{"id":21001446,"url":"https://github.com/divio/aldryn-apphooks-config","last_synced_at":"2025-08-25T06:04:21.537Z","repository":{"id":24918397,"uuid":"28335340","full_name":"divio/aldryn-apphooks-config","owner":"divio","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-08T18:37:04.000Z","size":228,"stargazers_count":5,"open_issues_count":4,"forks_count":27,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-08T11:07:23.387Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/divio.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-12-22T11:05:05.000Z","updated_at":"2023-10-12T11:44:11.000Z","dependencies_parsed_at":"2024-06-19T05:17:34.039Z","dependency_job_id":"90fb6df0-aa53-4159-9cec-e4fdbcdbf3b6","html_url":"https://github.com/divio/aldryn-apphooks-config","commit_stats":null,"previous_names":["aldryn/aldryn-apphooks-config"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/divio%2Faldryn-apphooks-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/divio%2Faldryn-apphooks-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/divio%2Faldryn-apphooks-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/divio%2Faldryn-apphooks-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/divio","download_url":"https://codeload.github.com/divio/aldryn-apphooks-config/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254248439,"owners_count":22039008,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T08:15:20.206Z","updated_at":"2025-05-14T23:32:33.160Z","avatar_url":"https://github.com/divio.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"|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\u003chttps://github.com/divio/aldryn-apphooks-config/graphs/contributors\u003e`_.\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdivio%2Faldryn-apphooks-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdivio%2Faldryn-apphooks-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdivio%2Faldryn-apphooks-config/lists"}