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.register to 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 model and render_template fields. The model should be a subclass of the Page model 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 the ModelAdmin classes in Django.

To customize the admin, define the model_admin attribute. The provided class should inherit from the PageAdmin class.

The output of a page is fully customizable in the page type plugin. By default, render_template will be used but you can also override get_render_template(), get_context() or even get_response(). The latter gives full control over the HttpResponse to 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 urls attribute to use this feature, and resolve those URLs using the fluent_pages.urlresolvers module.

model_admin

alias of fluent_pages.adminui.pageadmin.DefaultPageChildAdmin

response_class

alias of django.template.response.TemplateResponse

__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 (or get_render_template()). By default, it returns the model instance as instance field in the template.

Note that this function can also be called by custom views when those views implement the CurrentPageMixin or CurrentPageTemplateMixin

get_model_instances()

Return all Page instances that are has created using this page types.

get_render_template(request, page, **kwargs)

Return the template to render for the specific page or request, By default it uses the render_template attribute.

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() and response_class to 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_file is True, 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.

model = None

Defines the model to use to store the custom fields. It must derive from Page.

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 ContentType id 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 urlpatterns in it, or a direct inline patterns() list.

verbose_name

Returns the title for the plugin, by default it reads the verbose_name of 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 ContentType id’s of page types that act like files (no slash or children).

get_folder_types()

Return the ContentType id’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 PageTypePlugin for a given model.

get_plugins()

Return the PageTypePlugin instances which are loaded.

get_url_pattern_plugins()

Return the PageTypePlugin instances that provide URL patterns.

get_url_pattern_types()

Return the ContentType id’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 ModelAdmin classes. If a plugin is already registered, this will raise a PluginAlreadyRegistered exception.

The page_type_pool attribute

fluent_pages.extensions.page_type_pool

The global plugin pool, a instance of the PluginPool class.

Other classes

exception fluent_pages.extensions.PageTypeAlreadyRegistered

Raised when attempting to register a plugin twice.

exception fluent_pages.extensions.PageTypeNotFound

Raised when the plugin could not be found in the rendering process.