fluent_pages.extensions¶
Special classes to extend the module; e.g. page type plugins.
The extension mechanism is provided for projects that benefit from a tighter integration then the Django URLconf can provide.
The API uses a registration system.
While plugins can be easily detected via __subclasses__(), the register approach is less magic and more explicit.
Having to do an explicit register ensures future compatibility with other API’s like reversion.
The PageTypePlugin class¶
-
class
fluent_pages.extensions.PageTypePlugin¶ The base class for a page type plugin.
To create a new plugin, derive from this class and call
page_type_pool.registerto enable it. For example:from fluent_pages.extensions import PageTypePlugin, page_type_pool from mycms.models import MyCustomPage @page_type_pool.register class MyCustomPagePlugin(PageTypePlugin): model = MyCustomPage render_template = "mycustompage/example.html"
As minimal configuration, specify the
modelandrender_templatefields. Themodelshould be a subclass of thePagemodel class.Note
When the plugin is registered in the
page_type_pool, it will be instantiated only once. It is therefore not possible to store per-request state at the page type object. This is similar to the behavior of theModelAdminclasses in Django.To customize the admin, define the
model_adminattribute. The provided class should inherit from thePageAdminclass.The output of a page is fully customizable in the page type plugin. By default,
render_templatewill be used but you can also overrideget_render_template(),get_context()or evenget_response(). The latter gives full control over theHttpResponseto send to the client.Page types can provide additional views, relative to the location where the page is placed in the tree. A shopping module for example, can display products as sub pages. Provide an URLconf to the
urlsattribute to use this feature, and resolve those URLs using thefluent_pages.urlresolversmodule.-
model_admin¶ alias of
fluent_pages.adminui.pageadmin.DefaultPageChildAdmin
-
response_class¶
-
__init__()¶ Initialize self. See help(type(self)) for accurate signature.
-
get_context(request, page, **kwargs)¶ Return the context to use in the template defined by
render_template(orget_render_template()). By default, it returns the model instance asinstancefield in the template.Note that this function can also be called by custom views when those views implement the
CurrentPageMixinorCurrentPageTemplateMixin
-
get_render_template(request, page, **kwargs)¶ Return the template to render for the specific page or request, By default it uses the
render_templateattribute.
-
get_response(request, page, **kwargs)¶ Render the page, and return the Django
HttpResponse.This is the main function to generate output of the page. By default, it uses
get_render_template(),get_context()andresponse_classto generate the output of the page. The behavior can be replaced completely by overriding this function.
-
get_url_resolver()¶ Access the URL resolver of the page type.
-
get_view_response(request, page, view_func, view_args, view_kwargs)¶ Render the custom view that was exposed by the extra plugin URL patterns. This gives the ability to add extra middleware logic.
-
can_be_root= True¶ New in version 1.1.
Define whether this page type can be a root node.
-
can_have_children= True¶ Defines whether users are allowed to place sub pages below this node. When
is_fileisTrue, this is never possible.
-
child_types= []¶ New in version 1.1.
Defines which pages can be children of this node. List of values similar to those values accepted in a model ForeignKey.
-
default_in_sitemaps= True¶ New in version 0.9.
Tell whether the page type should be displayed in the sitemaps by default. This value can be changed for most pages in the admin interface.
-
is_file= False¶ Defines the page type represents a file; it neither has appended slash or does it allow children.
-
render_template= None¶ Defines the template to use for rendering the page.
-
sort_priority= 100¶ The sorting priority for the page type in the “Add Page” dialog of the admin.
-
type_id¶ Returns the
ContentTypeid of the model.
-
type_name¶ Return the class name of the model, this is mainly provided for templates.
-
urls= None¶ Defines the URLs that the page provides relative to the current node. This can either be the name of a Python module with
urlpatternsin it, or a direct inlinepatterns()list.
-
verbose_name¶ Returns the title for the plugin, by default it reads the
verbose_nameof the model.
-
The PageTypePool class¶
-
class
fluent_pages.extensions.PageTypePool¶ The central administration of plugins.
-
__init__()¶ Initialize self. See help(type(self)) for accurate signature.
-
get_file_types()¶ Return the
ContentTypeid’s of page types that act like files (no slash or children).
-
get_folder_types()¶ Return the
ContentTypeid’s of page types that operate as a container for sub pages.
-
get_model_classes()¶ Return all model classes which are exposed by page types. Each model derives from
Page.
-
get_plugin_by_model(model_class)¶ Return the corresponding
PageTypePluginfor a given model.
-
get_plugins()¶ Return the
PageTypePlugininstances which are loaded.
-
get_url_pattern_plugins()¶ Return the
PageTypePlugininstances that provide URL patterns.
-
get_url_pattern_types()¶ Return the
ContentTypeid’s of page types that provide URL patterns.
-
register(plugin)¶ Make a page type plugin known by the CMS.
Parameters: plugin – The plugin class, deriving from PageTypePlugin.The plugin will be instantiated, just like Django does this with
ModelAdminclasses. If a plugin is already registered, this will raise aPluginAlreadyRegisteredexception.
-