aldryn-apphooks-config


Namealdryn-apphooks-config JSON
Version 0.7.0 PyPI version JSON
download
home_pagehttps://github.com/aldryn/aldryn-apphooks-config
SummaryNamespaces based configuration for Apphooks
upload_time2023-05-07 16:06:35
maintainer
docs_urlNone
authorIacopo Spalletti
requires_python>=3.7
licenseBSD
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            |PyPI Version| |Coverage Status|

======================
aldryn-apphooks-config
======================

Namespaces based configuration for Apphooks

Basic concepts
==============

The concept of apphooks-config is to store all the configuration
in an applications-specific model, and let the developer
specify the desired option in a form.
In the views the model instance specific for the current
application namespace is loaded (through a mixin) and it's
thus available in the view to provide the configuration for
the current namespace.

Namespaces can be created on the fly in the ``Page`` admin
**Advanced settings** by following the steps above.
When creating an application configuration, you are in fact defining a
namespace, which is saved in the same field in the ``Page`` model as the
plain namespaces.


Contributing
------------

We're grateful to all contributors who have helped create and maintain this package.

Contributors are listed at `contributions page
<https://github.com/divio/aldryn-apphooks-config/graphs/contributors>`_.


Supported versions
-----------------------------

Python: 3.9 - 3.11
Django: 3.2 - 4.2
django CMS: 3.9 - 3.11


Implementation step-guide
=========================

* Define a AppHookConfig model in ``cms_appconfig.py``::

    from aldryn_apphooks_config.models import AppHookConfig

    class NewsBlogConfig(AppHookConfig):
        pass

  Implementation can be completely empty as the schema is defined in the
  parent (abstract) model

* Use apphooks managers in your model::

    from aldryn_apphooks_config.managers import AppHookConfigManager

    class Article(models.Model):
        title = models.CharField()

        objects = AppHookConfigManager()

``AppHookConfigManager`` adds ``namespace`` method to manager and queryset::

    Article.objects.namespace('foobar')

There is also a proper queryset, the ``ApphooksConfigQueryset``. Parler
integrated variants can be found in ``aldryn_apphooks_config.managers.parler``.
Names are ``AppHookConfigTranslatableManager`` and
``AppHookConfigTranslatableQueryset``.

* Define a ConfigForm in ``cms_appconfig.py``::

    from app_data import AppDataForm
    from django import forms
    from aldryn_newsblog.models import NewsBlogConfig
    from aldryn_apphooks_config.utils import setup_config

    class BlogOptionForm(AppDataForm):
        # fields are totally arbitrary: any form field supported by
        # django-appdata is supported
        show_authors = forms.BooleanField(required=False)
        ...

    # this function will register the provided form with the model created
    # at the above step
    setup_config(BlogOptionForm, NewsBlogConfig)

    # setup_config can be used as a decorator too, but the `model`
    # attribute must be added to the form class
    @setup_config
    class BlogOptionForm(AppDataForm):
        model = NewsBlogConfig




* Define an admin class for the AppHookConfig model (usually in ``admin.py``::

    from django.contrib import admin
    from aldryn_apphooks_config.admin import BaseAppHookConfig

    class BlogConfigAdmin(BaseAppHookConfig):

        def get_config_fields(self):
            # this method **must** be implemented and **must** return the
            # fields defined in the above form, with the ``config`` prefix
            # This is dependent on the django-appdata API
            return ('config.show_authors', ...)

* Define a CMSApp derived from CMSConfigApp provided by this application
  (in ``cms_app.py``/``cms_apps.py``)::

    from aldryn_apphooks_config.app_base import CMSConfigApp
    from cms.apphook_pool import apphook_pool
    from django.utils.translation import ugettext_lazy as _
    from .models import NewsBlogConfig


    class NewsBlogApp(CMSConfigApp):
        name = _('NewsBlogApp')
        urls = ['aldryn_newsblog.urls']
        app_name = 'aldryn_newsblog'
        # this option is specific of CMSConfigApp, and links the
        # CMSApp to a specific AppHookConfig model
        app_config = NewsBlogConfig

    apphook_pool.register(NewsBlogApp)

* Implements your views inheriting the ``AppConfigMixin``::

    from django.views.generic.detail import DetailView
    from aldryn_apphooks_config.mixins import AppConfigMixin

    class ArticleDetail(AppConfigMixin, DetailView):
        def get_queryset(self):
            return Article.objects.namespace(self.namespace)

  ``AppConfigMixin`` provides a complete support to namespaces, so the view
  is not required to set anything specific to support them; the following
  attributes are set for the view class instance:

  * current namespace in ``self.namespace``
  * namespace configuration (the instance of NewsBlogConfig) in ``self.config``
  * current application in the ``current_app`` parameter passed to the
    Response class

Test setup
==========

To properly setup the data for tests to run for a apphook-config enabled application,
make sure you add the following code to your TestCase::

    MyTestCase():

        def setUp(self):
            # This is the namespace represented by the AppHookConfig model instance
            self.ns_newsblog = NewsBlogConfig.objects.create(namespace='NBNS')
            self.page = api.create_page(
                'page', self.template, self.language, published=True,
                # this is the name of the apphook defined in the CMSApp class
                apphook='NewsBlogApp',
                # The namespace is the namespace field of the AppHookConfig instance created above
                apphook_namespace=self.ns_newsblog.namespace)
            # publish the page to make the apphook available
            self.page.publish(self.language)


.. |PyPI Version| image:: http://img.shields.io/pypi/v/aldryn-apphooks-config.svg
   :target: https://pypi.python.org/pypi/aldryn-apphooks-config
.. |Build Status| image:: https://img.shields.io/github/actions/workflow/status/divio/aldryn-apphooks-config/test.yml?style=flat-square
   :target: https://github.com/divio/aldryn-apphooks-config/actions/workflows/test.yml
.. |Coverage Status| image:: http://img.shields.io/coveralls/aldryn/aldryn-apphooks-config/master.svg
   :target: https://coveralls.io/r/aldryn/aldryn-apphooks-config?branch=master

Changelog
=========


0.7.0 (2023-05-07)
==================

* Add Django 3.2+ support

0.6.0 (2020-05-12)
==================

* Add Django 3.0 support

0.5.3 (2019-10-19)
==================

* Fix media asset declaration on django 2.2+

0.5.2 (2019-01-02)
==================

* Changed deprecated ``rel.to`` to ``remote_field.model``
* Fixed migration for example app
* Fixed issues for Django 2.0 and up


0.5.1 (2018-12-18)
==================

* Added support for Django 2.0 and 2.1
* Removed support for Django < 1.11
* Adapted testing infrastructure (tox/travis) to incorporate django CMS 3.6
* Fixed setup.py


0.4.2 (2018-12-17)
==================

* Fixed issue with Django 1.10 and below in AppHookConfigWidget


0.4.1 (2018-04-10)
==================

* django-appdata>=0.2.0 is now required


0.4.0 (2018-03-19)
==================

* Added Django 1.11 compatibility
* Added django CMS 3.5 compatibility
* Implemented django-appdata 0.2 interface
* Removed south migrations
* Dropped support for django CMS 3.3 and below
* Allowed use setup_config as decorators


0.3.3 (2017-03-06)
==================

* Fixed MANIFEST.in typo


0.3.2 (2017-03-06)
==================

* Fixed setup.py issue
* Added locale files to MANIFEST.in


0.3.1 (2017-03-02)
==================

* Added translation system
* Added german translation


0.3.0 (2017-01-06)
==================

* Allowed override AppHookConfigField attributes
* Dropped Django 1.7 and below
* Dropped django CMS 3.1 and below
* Added Django 1.10 support


0.2.7 (2016-03-03)
==================

* Set namespace as readonly
* Added official Django 1.9 support
* Updated readme
* Used path_info instead of path in resolve


0.2.6 (2015-10-05)
==================

* Added support for Python 3.5
* Added support for Django 1.9a1
* Code style cleanup and tests


0.2.5 (2015-09-25)
==================

* Added support for Django 1.8, django CMS 3.2
* AppHookConfigTranslatableManager.get_queryset should use queryset_class
* Skipped overriding admin form if app_config field not present


0.2.4 (2015-04-20)
==================

* Fixed issue where an apphook could not be changed, once set.
* Added optional 'default' kwarg to namespace_url templatetag


0.1.0 (2014-01-01)
==================

* Released first version on PyPI.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aldryn/aldryn-apphooks-config",
    "name": "aldryn-apphooks-config",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Iacopo Spalletti",
    "author_email": "i.spalletti@nephila.it",
    "download_url": "https://files.pythonhosted.org/packages/fe/0d/ae9d0a05f9a87bd99ea34789bb405bc9d89d4c9deadeaf0bb9769977ddfa/aldryn-apphooks-config-0.7.0.tar.gz",
    "platform": null,
    "description": "|PyPI Version| |Coverage Status|\n\n======================\naldryn-apphooks-config\n======================\n\nNamespaces based configuration for Apphooks\n\nBasic concepts\n==============\n\nThe concept of apphooks-config is to store all the configuration\nin an applications-specific model, and let the developer\nspecify the desired option in a form.\nIn the views the model instance specific for the current\napplication namespace is loaded (through a mixin) and it's\nthus available in the view to provide the configuration for\nthe current namespace.\n\nNamespaces can be created on the fly in the ``Page`` admin\n**Advanced settings** by following the steps above.\nWhen creating an application configuration, you are in fact defining a\nnamespace, which is saved in the same field in the ``Page`` model as the\nplain namespaces.\n\n\nContributing\n------------\n\nWe're grateful to all contributors who have helped create and maintain this package.\n\nContributors are listed at `contributions page\n<https://github.com/divio/aldryn-apphooks-config/graphs/contributors>`_.\n\n\nSupported versions\n-----------------------------\n\nPython: 3.9 - 3.11\nDjango: 3.2 - 4.2\ndjango CMS: 3.9 - 3.11\n\n\nImplementation step-guide\n=========================\n\n* Define a AppHookConfig model in ``cms_appconfig.py``::\n\n    from aldryn_apphooks_config.models import AppHookConfig\n\n    class NewsBlogConfig(AppHookConfig):\n        pass\n\n  Implementation can be completely empty as the schema is defined in the\n  parent (abstract) model\n\n* Use apphooks managers in your model::\n\n    from aldryn_apphooks_config.managers import AppHookConfigManager\n\n    class Article(models.Model):\n        title = models.CharField()\n\n        objects = AppHookConfigManager()\n\n``AppHookConfigManager`` adds ``namespace`` method to manager and queryset::\n\n    Article.objects.namespace('foobar')\n\nThere is also a proper queryset, the ``ApphooksConfigQueryset``. Parler\nintegrated variants can be found in ``aldryn_apphooks_config.managers.parler``.\nNames are ``AppHookConfigTranslatableManager`` and\n``AppHookConfigTranslatableQueryset``.\n\n* Define a ConfigForm in ``cms_appconfig.py``::\n\n    from app_data import AppDataForm\n    from django import forms\n    from aldryn_newsblog.models import NewsBlogConfig\n    from aldryn_apphooks_config.utils import setup_config\n\n    class BlogOptionForm(AppDataForm):\n        # fields are totally arbitrary: any form field supported by\n        # django-appdata is supported\n        show_authors = forms.BooleanField(required=False)\n        ...\n\n    # this function will register the provided form with the model created\n    # at the above step\n    setup_config(BlogOptionForm, NewsBlogConfig)\n\n    # setup_config can be used as a decorator too, but the `model`\n    # attribute must be added to the form class\n    @setup_config\n    class BlogOptionForm(AppDataForm):\n        model = NewsBlogConfig\n\n\n\n\n* Define an admin class for the AppHookConfig model (usually in ``admin.py``::\n\n    from django.contrib import admin\n    from aldryn_apphooks_config.admin import BaseAppHookConfig\n\n    class BlogConfigAdmin(BaseAppHookConfig):\n\n        def get_config_fields(self):\n            # this method **must** be implemented and **must** return the\n            # fields defined in the above form, with the ``config`` prefix\n            # This is dependent on the django-appdata API\n            return ('config.show_authors', ...)\n\n* Define a CMSApp derived from CMSConfigApp provided by this application\n  (in ``cms_app.py``/``cms_apps.py``)::\n\n    from aldryn_apphooks_config.app_base import CMSConfigApp\n    from cms.apphook_pool import apphook_pool\n    from django.utils.translation import ugettext_lazy as _\n    from .models import NewsBlogConfig\n\n\n    class NewsBlogApp(CMSConfigApp):\n        name = _('NewsBlogApp')\n        urls = ['aldryn_newsblog.urls']\n        app_name = 'aldryn_newsblog'\n        # this option is specific of CMSConfigApp, and links the\n        # CMSApp to a specific AppHookConfig model\n        app_config = NewsBlogConfig\n\n    apphook_pool.register(NewsBlogApp)\n\n* Implements your views inheriting the ``AppConfigMixin``::\n\n    from django.views.generic.detail import DetailView\n    from aldryn_apphooks_config.mixins import AppConfigMixin\n\n    class ArticleDetail(AppConfigMixin, DetailView):\n        def get_queryset(self):\n            return Article.objects.namespace(self.namespace)\n\n  ``AppConfigMixin`` provides a complete support to namespaces, so the view\n  is not required to set anything specific to support them; the following\n  attributes are set for the view class instance:\n\n  * current namespace in ``self.namespace``\n  * namespace configuration (the instance of NewsBlogConfig) in ``self.config``\n  * current application in the ``current_app`` parameter passed to the\n    Response class\n\nTest setup\n==========\n\nTo properly setup the data for tests to run for a apphook-config enabled application,\nmake sure you add the following code to your TestCase::\n\n    MyTestCase():\n\n        def setUp(self):\n            # This is the namespace represented by the AppHookConfig model instance\n            self.ns_newsblog = NewsBlogConfig.objects.create(namespace='NBNS')\n            self.page = api.create_page(\n                'page', self.template, self.language, published=True,\n                # this is the name of the apphook defined in the CMSApp class\n                apphook='NewsBlogApp',\n                # The namespace is the namespace field of the AppHookConfig instance created above\n                apphook_namespace=self.ns_newsblog.namespace)\n            # publish the page to make the apphook available\n            self.page.publish(self.language)\n\n\n.. |PyPI Version| image:: http://img.shields.io/pypi/v/aldryn-apphooks-config.svg\n   :target: https://pypi.python.org/pypi/aldryn-apphooks-config\n.. |Build Status| image:: https://img.shields.io/github/actions/workflow/status/divio/aldryn-apphooks-config/test.yml?style=flat-square\n   :target: https://github.com/divio/aldryn-apphooks-config/actions/workflows/test.yml\n.. |Coverage Status| image:: http://img.shields.io/coveralls/aldryn/aldryn-apphooks-config/master.svg\n   :target: https://coveralls.io/r/aldryn/aldryn-apphooks-config?branch=master\n\nChangelog\n=========\n\n\n0.7.0 (2023-05-07)\n==================\n\n* Add Django 3.2+ support\n\n0.6.0 (2020-05-12)\n==================\n\n* Add Django 3.0 support\n\n0.5.3 (2019-10-19)\n==================\n\n* Fix media asset declaration on django 2.2+\n\n0.5.2 (2019-01-02)\n==================\n\n* Changed deprecated ``rel.to`` to ``remote_field.model``\n* Fixed migration for example app\n* Fixed issues for Django 2.0 and up\n\n\n0.5.1 (2018-12-18)\n==================\n\n* Added support for Django 2.0 and 2.1\n* Removed support for Django < 1.11\n* Adapted testing infrastructure (tox/travis) to incorporate django CMS 3.6\n* Fixed setup.py\n\n\n0.4.2 (2018-12-17)\n==================\n\n* Fixed issue with Django 1.10 and below in AppHookConfigWidget\n\n\n0.4.1 (2018-04-10)\n==================\n\n* django-appdata>=0.2.0 is now required\n\n\n0.4.0 (2018-03-19)\n==================\n\n* Added Django 1.11 compatibility\n* Added django CMS 3.5 compatibility\n* Implemented django-appdata 0.2 interface\n* Removed south migrations\n* Dropped support for django CMS 3.3 and below\n* Allowed use setup_config as decorators\n\n\n0.3.3 (2017-03-06)\n==================\n\n* Fixed MANIFEST.in typo\n\n\n0.3.2 (2017-03-06)\n==================\n\n* Fixed setup.py issue\n* Added locale files to MANIFEST.in\n\n\n0.3.1 (2017-03-02)\n==================\n\n* Added translation system\n* Added german translation\n\n\n0.3.0 (2017-01-06)\n==================\n\n* Allowed override AppHookConfigField attributes\n* Dropped Django 1.7 and below\n* Dropped django CMS 3.1 and below\n* Added Django 1.10 support\n\n\n0.2.7 (2016-03-03)\n==================\n\n* Set namespace as readonly\n* Added official Django 1.9 support\n* Updated readme\n* Used path_info instead of path in resolve\n\n\n0.2.6 (2015-10-05)\n==================\n\n* Added support for Python 3.5\n* Added support for Django 1.9a1\n* Code style cleanup and tests\n\n\n0.2.5 (2015-09-25)\n==================\n\n* Added support for Django 1.8, django CMS 3.2\n* AppHookConfigTranslatableManager.get_queryset should use queryset_class\n* Skipped overriding admin form if app_config field not present\n\n\n0.2.4 (2015-04-20)\n==================\n\n* Fixed issue where an apphook could not be changed, once set.\n* Added optional 'default' kwarg to namespace_url templatetag\n\n\n0.1.0 (2014-01-01)\n==================\n\n* Released first version on PyPI.\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Namespaces based configuration for Apphooks",
    "version": "0.7.0",
    "project_urls": {
        "Documentation": "https://aldryn-apphooks-config.readthedocs.io/",
        "Homepage": "https://github.com/aldryn/aldryn-apphooks-config"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "01a24dcb3121a6e011515e8b8a86e98495bcd59a78d5d691961d84eee4b8880f",
                "md5": "bdbb0b02ee922a8e7d45e7b455fb69ed",
                "sha256": "909339d91ebde6b9d0b1e5b791f08cce4f52d3f7967fa3de2d6e299fd869344c"
            },
            "downloads": -1,
            "filename": "aldryn_apphooks_config-0.7.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bdbb0b02ee922a8e7d45e7b455fb69ed",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.7",
            "size": 31822,
            "upload_time": "2023-05-07T16:06:33",
            "upload_time_iso_8601": "2023-05-07T16:06:33.696132Z",
            "url": "https://files.pythonhosted.org/packages/01/a2/4dcb3121a6e011515e8b8a86e98495bcd59a78d5d691961d84eee4b8880f/aldryn_apphooks_config-0.7.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fe0dae9d0a05f9a87bd99ea34789bb405bc9d89d4c9deadeaf0bb9769977ddfa",
                "md5": "411c429d7befc220021937032b00fa66",
                "sha256": "d6467ed1a61f88ef73ea02d5ec5a9c3ffd96855738192b1849ab0df86a5e1566"
            },
            "downloads": -1,
            "filename": "aldryn-apphooks-config-0.7.0.tar.gz",
            "has_sig": false,
            "md5_digest": "411c429d7befc220021937032b00fa66",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 26305,
            "upload_time": "2023-05-07T16:06:35",
            "upload_time_iso_8601": "2023-05-07T16:06:35.843121Z",
            "url": "https://files.pythonhosted.org/packages/fe/0d/ae9d0a05f9a87bd99ea34789bb405bc9d89d4c9deadeaf0bb9769977ddfa/aldryn-apphooks-config-0.7.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-07 16:06:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aldryn",
    "github_project": "aldryn-apphooks-config",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "aldryn-apphooks-config"
}
        
Elapsed time: 0.07374s