App Hooks, what's the thing?
is a means of integrating existing apps into a CMS.
There are two ways to achieve this:
1) define the cms_app.py as follows:
From cms.app_base import cmsappfrom cms.apphook_pool import apphook_poolfrom django.utils.translation import Ugettext_ Lazy as _class Myapphook (cmsapp): name = _ ("My apphook") urls = ["Myapp.urls"]apphook_pool.register (Myapphook)
Official documents See here: Http://docs.django-cms.org/en/latest/extending_cms/app_integration.html#app-hooks
Load logic, loaded via Discover_apps's Load (' Cms_app ') (if cms_apphooks is not defined in settings.py): In all Installed_app, find the Cms_app module, and automatically Import_module
2) define Cms_apphooks in setting.py
apphooks= (' Yourmodule.you_object1 ', ' Yourmodule.you_object2 ',...)
This is from the source code analysis, the following:
C:\Python27\Lib\site-packages\django_cms-3.0.3-py2.7.egg\cms\apphook_pool.py (45~57)
def discover_apps (self): self.apphooks = get_cms_setting (' apphooks ') if self.apphooks: for CLS in Iterload_objects (self.apphooks): try: self.register (CLS, discovering_apps=true) except appalreadyregistered: Pass else: load (' Cms_app ') self.discovered = True
Iterload_objects, is a generator, as follows:
def iterload_objects (import_paths): "" " Load a list of objects. " " For Import_path in import_paths: yield load_object (import_path)
Load_object
def load_object (Import_path): if '. ' Not in Import_path: raise TypeError ( "' import_path ' argument to ' Django_load.core.load_object ' must " " contain at least one dot. " ) Module_name, object_name = Import_path.rsplit ('. ', 1) module = import_module (module_name) return GetAttr ( module, object_name)
DJANGO-CMS Code Research (eight) app hooks