Package: aldryn-apphooks-config
aldryn-apphooks-configNamespaces based configuration for ApphooksBasic conceptsThe 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 thePageadminAdvanced settingsby following the steps above.
When creating an application configuration, you are in fact defining a
namespace, which is saved in the same field in thePagemodel as the
plain namespaces.ContributingWe’re grateful to all contributors who have helped create and maintain this package.Contributors are listed atcontributions page.Supported versionsPython: 3.9 - 3.11
Django: 3.2 - 4.2
django CMS: 3.9 - 3.11Implementation step-guideDefine a AppHookConfig model incms_appconfig.py:from aldryn_apphooks_config.models import AppHookConfig

class NewsBlogConfig(AppHookConfig):
    passImplementation can be completely empty as the schema is defined in the
parent (abstract) modelUse apphooks managers in your model:from aldryn_apphooks_config.managers import AppHookConfigManager

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

    objects = AppHookConfigManager()AppHookConfigManageraddsnamespacemethod to manager and queryset:Article.objects.namespace('foobar')There is also a proper queryset, theApphooksConfigQueryset. Parler
integrated variants can be found inaldryn_apphooks_config.managers.parler.
Names areAppHookConfigTranslatableManagerandAppHookConfigTranslatableQueryset.Define a ConfigForm incms_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 = NewsBlogConfigDefine an admin class for the AppHookConfig model (usually inadmin.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
(incms_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 theAppConfigMixin: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)AppConfigMixinprovides 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 inself.namespacenamespace configuration (the instance of NewsBlogConfig) inself.configcurrent application in thecurrent_appparameter passed to the
Response classTest setupTo 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)Changelog0.7.0 (2023-05-07)Add Django 3.2+ support0.6.0 (2020-05-12)Add Django 3.0 support0.5.3 (2019-10-19)Fix media asset declaration on django 2.2+0.5.2 (2019-01-02)Changed deprecatedrel.totoremote_field.modelFixed migration for example appFixed issues for Django 2.0 and up0.5.1 (2018-12-18)Added support for Django 2.0 and 2.1Removed support for Django < 1.11Adapted testing infrastructure (tox/travis) to incorporate django CMS 3.6Fixed setup.py0.4.2 (2018-12-17)Fixed issue with Django 1.10 and below in AppHookConfigWidget0.4.1 (2018-04-10)django-appdata>=0.2.0 is now required0.4.0 (2018-03-19)Added Django 1.11 compatibilityAdded django CMS 3.5 compatibilityImplemented django-appdata 0.2 interfaceRemoved south migrationsDropped support for django CMS 3.3 and belowAllowed use setup_config as decorators0.3.3 (2017-03-06)Fixed MANIFEST.in typo0.3.2 (2017-03-06)Fixed setup.py issueAdded locale files to MANIFEST.in0.3.1 (2017-03-02)Added translation systemAdded german translation0.3.0 (2017-01-06)Allowed override AppHookConfigField attributesDropped Django 1.7 and belowDropped django CMS 3.1 and belowAdded Django 1.10 support0.2.7 (2016-03-03)Set namespace as readonlyAdded official Django 1.9 supportUpdated readmeUsed path_info instead of path in resolve0.2.6 (2015-10-05)Added support for Python 3.5Added support for Django 1.9a1Code style cleanup and tests0.2.5 (2015-09-25)Added support for Django 1.8, django CMS 3.2AppHookConfigTranslatableManager.get_queryset should use queryset_classSkipped overriding admin form if app_config field not present0.2.4 (2015-04-20)Fixed issue where an apphook could not be changed, once set.Added optional ‘default’ kwarg to namespace_url templatetag0.1.0 (2014-01-01)Released first version on PyPI.