djangocms-apphook-setup


Namedjangocms-apphook-setup JSON
Version 0.5.1 PyPI version JSON
download
home_pagehttps://github.com/nephila/djangocms-apphook-setup
SummaryLibrary to auto setup apphooks
upload_time2024-01-16 11:47:41
maintainer
docs_urlNone
authorIacopo Spalletti
requires_python>=3.7
licenseBSD
keywords djangocms-apphook-setup django cms apphook
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            =======================
djangocms-apphook-setup
=======================

|Gitter| |PyPiVersion| |PyVersion| |GAStatus| |TestCoverage| |CodeClimate| |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.

.. note:: To avoid issues with ``AldrynSearch`` during the creation of pages, the url of the
          pages is faked; this is normally not an issues as the pages will be reindexed
          whenever the content is updated.

*****
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()




.. |Gitter| image:: https://img.shields.io/badge/GITTER-join%20chat-brightgreen.svg?style=flat-square
    :target: https://gitter.im/nephila/applications
    :alt: Join the Gitter chat

.. |PyPiVersion| image:: https://img.shields.io/pypi/v/djangocms-apphook-setup.svg?style=flat-square
    :target: https://pypi.python.org/pypi/djangocms-apphook-setup
    :alt: Latest PyPI version

.. |PyVersion| image:: https://img.shields.io/pypi/pyversions/djangocms-apphook-setup.svg?style=flat-square
    :target: https://pypi.python.org/pypi/djangocms-apphook-setup
    :alt: Python versions

.. |GAStatus| image:: https://github.com/nephila/djangocms-apphook-setup/workflows/Tox%20tests/badge.svg
    :target: https://github.com/nephila/djangocms-apphook-setup
    :alt: Latest CI build status

.. |TestCoverage| image:: https://img.shields.io/coveralls/nephila/djangocms-apphook-setup/master.svg?style=flat-square
    :target: https://coveralls.io/r/nephila/djangocms-apphook-setup?branch=master
    :alt: Test coverage

.. |License| image:: https://img.shields.io/github/license/nephila/djangocms-apphook-setup.svg?style=flat-square
   :target: https://pypi.python.org/pypi/djangocms-apphook-setup/
    :alt: License

.. |CodeClimate| image:: https://codeclimate.com/github/nephila/djangocms-apphook-setup/badges/gpa.svg?style=flat-square
   :target: https://codeclimate.com/github/nephila/djangocms-apphook-setup
   :alt: Code Climate

.. :changelog:

*******
History
*******

.. towncrier release notes start

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nephila/djangocms-apphook-setup",
    "name": "djangocms-apphook-setup",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "djangocms-apphook-setup,django CMS,apphook",
    "author": "Iacopo Spalletti",
    "author_email": "i.spalletti@nephila.it",
    "download_url": "https://files.pythonhosted.org/packages/b3/07/f9e7b18fa6f235f68f1b6b53517cf9e166dec5924c267bf1d0433e28473c/djangocms-apphook-setup-0.5.1.tar.gz",
    "platform": null,
    "description": "=======================\ndjangocms-apphook-setup\n=======================\n\n|Gitter| |PyPiVersion| |PyVersion| |GAStatus| |TestCoverage| |CodeClimate| |License|\n\nUtility function to auto setup apphooks on project startup.\n\nSupported Django versions:\n\n* Django: 3.2, 4.1, 4.2\n\nSupported django CMS versions:\n\n* django CMS: 3.9, 3.11\n\n********\nFeatures\n********\n\nThe mixin included in this utility allows to automatically add an Apphook to a django CMS\nproject on the first access to the website.\n\nThis is intended for use by the django CMS application developers by extending their own\n``CMSApp`` classes.\n\nThis behavior simplify the initial setup of a project and lower the barrier for the end user.\n\nThe setup function included here does the following:\n\n* Check if the Apphook is already added to a CMS page\n* If it is, it skips any further step\n* If not:\n\n  * Creates the home page (if not present)\n  * Creates a sub page of the home\n  * Adds the application Apphook to it\n\nIn case the application uses ``aldryn-apphooks-config``, a Apphook Config instance is created\nand added to the application page together with the Apphook.\n\n.. note:: To avoid issues with ``AldrynSearch`` during the creation of pages, the url of the\n          pages is faked; this is normally not an issues as the pages will be reindexed\n          whenever the content is updated.\n\n*****\nUsage\n*****\n\nThis utility can be used by extending the ``CMSApp`` class, adding the ``auto_setup`` attribute\nwith relevant configuration options and triggering setup at the end of ``cms_app.py``::\n\n\n    @apphook_pool.register\n    class App4(AutoCMSAppMixin, CMSConfigApp):\n        name = _('App4')\n        urls = ['sample_app_4.urls']\n        app_name = 'app4'\n        app_config = App4Config\n        # djangocms-apphook-setup attribute\n        auto_setup = {\n            'enabled': True,\n            'home title': 'home title',\n            'page title': 'page 4 title',\n            'namespace': 'namespace',\n            'config_fields': {'random_option': True},\n            'config_translated_fields': {'app_title': 'app title', 'object_name': 'name'},\n            'sites': True,\n        }\n\n\n    # trigger djangocms-apphook-setup function\n    App4.setup()\n\n********************************************\nCustomizing ApphookConfig instances creation\n********************************************\n\nWhile ``config_fields`` and ``config_translated_fields`` should cover most use cases when it comes\nto ApphookConfig instances creation, you may need more control over the process.\n\nFor this, it's possible to override ``AutoCMSAppMixin._create_config`` and\n``AutoCMSAppMixin._create_config_translation``.\n\nDefault implementation::\n\n    @classmethod\n    def _create_config(cls):\n        return cls.app_config.objects.create(\n            namespace=cls.auto_setup['namespace'], **cls.auto_setup['config_fields']\n        )\n\n    @classmethod\n    def _create_config_translation(cls, config, lang):\n        config.set_current_language(lang, initialize=True)\n        for field, data in cls.auto_setup['config_translated_fields'].items():\n            setattr(config, field, data)\n        config.save_translations()\n\n\nYou can completely redefine the methods, provided you return an ApphookConfig instance\nin ``_create_config``.\n\n*********************\nConfiguration options\n*********************\n\nThe behavior of the setup function can be customized by setting the following keys in the\n``auto_setup`` attribute:\n\n* ``enabled``: If ``True`` the setup is invoked; a good option is to use a setting to control this\n  to allow application users to disable the behavior (default: ``True``)\n* ``home title``: Title of the home page if created by the setup function; this **must** be set in\n  the application ``CMSApp``, otherwise the setup function will exit with a warning.\n* ``page title``: Title of the page created by the setup function; this **must** be set in\n  the application ``CMSApp``, otherwise the setup function will exit with a warning.\n* ``namespace``: Application instance name used when attaching the Apphook; this **must** be set in\n  the application ``CMSApp`` if an ``app_name`` is defined, otherwise the setup function will exit\n  with a warning.\n* ``config_fields``: Fields used when creating the ApphookConfigModel instance; use this attribute\n  for non-translated fields.\n* ``config_translated_fields``: Fields used when creating the ApphookConfigModel instance;\n  use this attribute for translated fields (currently only ``django-parler`` is supported).\n* ``sites``: List of site ids for which to create the pages; if set to ``True`` (the default value)\n  pages will be created for all sites. A single apphook config is created for all the sites;\n  instance is created only on first page creation.\n\n****************\nNotes on testing\n****************\n\nAs this utility works by triggering setup function at import time, extra steps must be taken\nin the tests to unload the modules between the tests (this is only needed when testing the setup).\n\nExample cleanup to be included in ``setUp`` method::\n\n    def setUp(self):\n        super(SetupAppBaseTest, self).setUp()\n        from cms.apphook_pool import apphook_pool\n\n        delete = [\n            'my_app',\n            'my_app.cms_app',\n        ]\n        for module in delete:\n            if module in sys.modules:\n                del sys.modules[module]\n        MyApphoolConfigModel.cmsapp = None\n        apphook_pool.clear()\n\n\n\n\n.. |Gitter| image:: https://img.shields.io/badge/GITTER-join%20chat-brightgreen.svg?style=flat-square\n    :target: https://gitter.im/nephila/applications\n    :alt: Join the Gitter chat\n\n.. |PyPiVersion| image:: https://img.shields.io/pypi/v/djangocms-apphook-setup.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/djangocms-apphook-setup\n    :alt: Latest PyPI version\n\n.. |PyVersion| image:: https://img.shields.io/pypi/pyversions/djangocms-apphook-setup.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/djangocms-apphook-setup\n    :alt: Python versions\n\n.. |GAStatus| image:: https://github.com/nephila/djangocms-apphook-setup/workflows/Tox%20tests/badge.svg\n    :target: https://github.com/nephila/djangocms-apphook-setup\n    :alt: Latest CI build status\n\n.. |TestCoverage| image:: https://img.shields.io/coveralls/nephila/djangocms-apphook-setup/master.svg?style=flat-square\n    :target: https://coveralls.io/r/nephila/djangocms-apphook-setup?branch=master\n    :alt: Test coverage\n\n.. |License| image:: https://img.shields.io/github/license/nephila/djangocms-apphook-setup.svg?style=flat-square\n   :target: https://pypi.python.org/pypi/djangocms-apphook-setup/\n    :alt: License\n\n.. |CodeClimate| image:: https://codeclimate.com/github/nephila/djangocms-apphook-setup/badges/gpa.svg?style=flat-square\n   :target: https://codeclimate.com/github/nephila/djangocms-apphook-setup\n   :alt: Code Climate\n\n.. :changelog:\n\n*******\nHistory\n*******\n\n.. towncrier release notes start\n\n0.5.1 (2024-01-16)\n==================\n\nFeatures\n--------\n\n- Switch to Coveralls Github action (#37)\n\n\nBugfixes\n--------\n\n- Pin Django CMS version < 4, fix README (#45)\n\n\n0.5.0 (2023-05-07)\n==================\n\nFeatures\n--------\n\n- Add support for Django 4.2 / django CMS 3.11 (#16)\n- Update tooling and drop Python 2 / Django < 2.2 compatibility (#10214)\n\n0.4.1 (2019-12-22)\n==================\n\n* Fix classifiers\n\n0.4.0 (2019-12-22)\n==================\n\n* Add Django 2.2 support\n* Add django CMS 3.6, 3.7 support\n* Drop Django < 1.11 support\n* Drop django CMS < 3.6 support\n* Fix monkey-patch not applied consistently\n\n0.3.0 (2018-01-15)\n==================\n\n* Add support for multisite setups\n* Add Django 1.11 support\n* Add django CMS 3.5 support\n\n0.2.0 (2016-12-04)\n==================\n\n* Add support for multisite setups\n* Add Django 1.9, 1.10 support\n* Add django CMS 3.4 support\n\n0.1.2 (2015-12-22)\n==================\n\n* Monekypatch aldryn_search index to avoid errors\n\n0.1.1 (2015-11-02)\n==================\n\n* Easier extension of ApphookConfig creation\n\n0.1.0 (2015-10-24)\n==================\n\n* First experimental release\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Library to auto setup apphooks",
    "version": "0.5.1",
    "project_urls": {
        "Homepage": "https://github.com/nephila/djangocms-apphook-setup"
    },
    "split_keywords": [
        "djangocms-apphook-setup",
        "django cms",
        "apphook"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "556e1ebd924befe26f26fa17f311a88cfdcdea58b0555e04fb48ad6659ca6410",
                "md5": "7319d3727ee84f98e15b30831281ae14",
                "sha256": "0cd01022e5e342751f630900a276d2eb1a680ec6cef371aa206049731ebdc43b"
            },
            "downloads": -1,
            "filename": "djangocms_apphook_setup-0.5.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7319d3727ee84f98e15b30831281ae14",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.7",
            "size": 7439,
            "upload_time": "2024-01-16T11:47:40",
            "upload_time_iso_8601": "2024-01-16T11:47:40.253830Z",
            "url": "https://files.pythonhosted.org/packages/55/6e/1ebd924befe26f26fa17f311a88cfdcdea58b0555e04fb48ad6659ca6410/djangocms_apphook_setup-0.5.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b307f9e7b18fa6f235f68f1b6b53517cf9e166dec5924c267bf1d0433e28473c",
                "md5": "e513ad60745e06c8e62e36ff0d28ad20",
                "sha256": "b4173e1335216e8e16b027efcdbf97f1a1139d141c139793285adb4f33f88021"
            },
            "downloads": -1,
            "filename": "djangocms-apphook-setup-0.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e513ad60745e06c8e62e36ff0d28ad20",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 12140,
            "upload_time": "2024-01-16T11:47:41",
            "upload_time_iso_8601": "2024-01-16T11:47:41.248201Z",
            "url": "https://files.pythonhosted.org/packages/b3/07/f9e7b18fa6f235f68f1b6b53517cf9e166dec5924c267bf1d0433e28473c/djangocms-apphook-setup-0.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-16 11:47:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nephila",
    "github_project": "djangocms-apphook-setup",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "djangocms-apphook-setup"
}
        
Elapsed time: 0.55710s