Skip to main content

djangocms-apphook-setup

Join the Gitter chat Latest PyPI version Python versions Latest CI build status Test coverage Code Climate License

Utility function to auto setup apphooks on project startup.

Supported Django versions:

  • Django: 3.2, 4.1, 4.2

Supported django CMS versions:

  • django CMS: 3.9, 3.11

Features

The mixin included in this utility allows to automatically add an Apphook to a django CMS project on the first access to the website.

This is intended for use by the django CMS application developers by extending their own CMSApp classes.

This behavior simplify the initial setup of a project and lower the barrier for the end user.

The setup function included here does the following:

  • Check if the Apphook is already added to a CMS page

  • If it is, it skips any further step

  • If not:

    • Creates the home page (if not present)

    • Creates a sub page of the home

    • Adds the application Apphook to it

In case the application uses aldryn-apphooks-config, a Apphook Config instance is created and added to the application page together with the Apphook.

Usage

This utility can be used by extending the CMSApp class, adding the auto_setup attribute with relevant configuration options and triggering setup at the end of cms_app.py:

@apphook_pool.register
class App4(AutoCMSAppMixin, CMSConfigApp):
    name = _('App4')
    urls = ['sample_app_4.urls']
    app_name = 'app4'
    app_config = App4Config
    # djangocms-apphook-setup attribute
    auto_setup = {
        'enabled': True,
        'home title': 'home title',
        'page title': 'page 4 title',
        'namespace': 'namespace',
        'config_fields': {'random_option': True},
        'config_translated_fields': {'app_title': 'app title', 'object_name': 'name'},
        'sites': True,
    }


# trigger djangocms-apphook-setup function
App4.setup()

Customizing ApphookConfig instances creation

While config_fields and config_translated_fields should cover most use cases when it comes to ApphookConfig instances creation, you may need more control over the process.

For this, it’s possible to override AutoCMSAppMixin._create_config and AutoCMSAppMixin._create_config_translation.

Default implementation:

@classmethod
def _create_config(cls):
    return cls.app_config.objects.create(
        namespace=cls.auto_setup['namespace'], **cls.auto_setup['config_fields']
    )

@classmethod
def _create_config_translation(cls, config, lang):
    config.set_current_language(lang, initialize=True)
    for field, data in cls.auto_setup['config_translated_fields'].items():
        setattr(config, field, data)
    config.save_translations()

You can completely redefine the methods, provided you return an ApphookConfig instance in _create_config.

Configuration options

The behavior of the setup function can be customized by setting the following keys in the auto_setup attribute:

  • enabled: If True the setup is invoked; a good option is to use a setting to control this to allow application users to disable the behavior (default: True)

  • home title: Title of the home page if created by the setup function; this must be set in the application CMSApp, otherwise the setup function will exit with a warning.

  • page title: Title of the page created by the setup function; this must be set in the application CMSApp, otherwise the setup function will exit with a warning.

  • namespace: Application instance name used when attaching the Apphook; this must be set in the application CMSApp if an app_name is defined, otherwise the setup function will exit with a warning.

  • config_fields: Fields used when creating the ApphookConfigModel instance; use this attribute for non-translated fields.

  • config_translated_fields: Fields used when creating the ApphookConfigModel instance; use this attribute for translated fields (currently only django-parler is supported).

  • sites: List of site ids for which to create the pages; if set to True (the default value) pages will be created for all sites. A single apphook config is created for all the sites; instance is created only on first page creation.

Notes on testing

As this utility works by triggering setup function at import time, extra steps must be taken in the tests to unload the modules between the tests (this is only needed when testing the setup).

Example cleanup to be included in setUp method:

def setUp(self):
    super(SetupAppBaseTest, self).setUp()
    from cms.apphook_pool import apphook_pool

    delete = [
        'my_app',
        'my_app.cms_app',
    ]
    for module in delete:
        if module in sys.modules:
            del sys.modules[module]
    MyApphoolConfigModel.cmsapp = None
    apphook_pool.clear()

History

0.5.1 (2024-01-16)

Features

  • Switch to Coveralls Github action (#37)

Bugfixes

  • Pin Django CMS version < 4, fix README (#45)

0.5.0 (2023-05-07)

Features

  • Add support for Django 4.2 / django CMS 3.11 (#16)

  • Update tooling and drop Python 2 / Django < 2.2 compatibility (#10214)

0.4.1 (2019-12-22)

  • Fix classifiers

0.4.0 (2019-12-22)

  • Add Django 2.2 support

  • Add django CMS 3.6, 3.7 support

  • Drop Django < 1.11 support

  • Drop django CMS < 3.6 support

  • Fix monkey-patch not applied consistently

0.3.0 (2018-01-15)

  • Add support for multisite setups

  • Add Django 1.11 support

  • Add django CMS 3.5 support

0.2.0 (2016-12-04)

  • Add support for multisite setups

  • Add Django 1.9, 1.10 support

  • Add django CMS 3.4 support

0.1.2 (2015-12-22)

  • Monekypatch aldryn_search index to avoid errors

0.1.1 (2015-11-02)

  • Easier extension of ApphookConfig creation

0.1.0 (2015-10-24)

  • First experimental release

Metadata

Release files for djangocms-apphook-setup 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for djangocms-apphook-setup 0.5.1
File Size Uploaded Provenance Actions
djangocms-apphook-setup-0.5.1.tar.gz 12.1 kB Without provenance Details for djangocms-apphook-setup-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for djangocms-apphook-setup 0.5.1
File Interpreter ABI Platform Actions
djangocms_apphook_setup-0.5.1-py2.py3-none-any.whl Python 3, Python 2 none any Details for djangocms_apphook_setup-0.5.1-py2.py3-none-any.whl

Total release size: 19.6 kB

Release files / djangocms-apphook-setup-0.5.1.tar.gz

Download URL djangocms-apphook-setup-0.5.1.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b4173e1335216e8e16b027efcdbf97f1a1139d141c139793285adb4f33f88021
BLAKE2b-256 checksum
How to use checksums
b307f9e7b18fa6f235f68f1b6b53517cf9e166dec5924c267bf1d0433e28473c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Release files / djangocms_apphook_setup-0.5.1-py2.py3-none-any.whl

Download URL djangocms_apphook_setup-0.5.1-py2.py3-none-any.whl
Size 7.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0cd01022e5e342751f630900a276d2eb1a680ec6cef371aa206049731ebdc43b
BLAKE2b-256 checksum
How to use checksums
556e1ebd924befe26f26fa17f311a88cfdcdea58b0555e04fb48ad6659ca6410
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.1

Security for djangocms-apphook-setup 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page