fluent_pages.models

The data layer of the CMS, exposing all database models.

The objects can be imported from the main package. There are several sub packages:

db: The database models managers: Additional manager classes modeldata: Classes that expose model data in a sane way (for template designers) navigation: The menu navigation nodes (for template designers)

The UrlNode class

class fluent_pages.models.UrlNode(*args, **kwargs)

The base class for all nodes; a mapping of an URL to content (e.g. a HTML page, text file, blog, etc..)

Parameters:
  • id (AutoField) – Id
  • polymorphic_ctype (ForeignKey to ContentType) – Polymorphic ctype
  • parent (PageTreeForeignKey to UrlNode) – Parent. You can also change the parent by dragging the page in the list.
  • parent_site (ForeignKey to Site) – Parent site
  • status (CharField) – Status
  • publication_date (DateTimeField) – Publication date. When the page should go live, status must be “Published”.
  • publication_end_date (DateTimeField) – Publication end date
  • in_navigation (BooleanField) – Show in navigation
  • in_sitemaps (BooleanField) – Include in search engine sitemaps
  • key (SlugField) – Page identifier. A unique identifier that is used for linking to this page.
  • author (ForeignKey to User) – Author
  • creation_date (DateTimeField) – Creation date
  • modification_date (DateTimeField) – Last modification
  • lft (PositiveIntegerField) – Lft
  • rght (PositiveIntegerField) – Rght
  • tree_id (PositiveIntegerField) – Tree id
  • level (PositiveIntegerField) – Level
exception DoesNotExist
exception MultipleObjectsReturned
__init__(*args, **kwargs)

Replace Django’s inheritance accessor member functions for our model (self.__class__) with our own versions. We monkey patch them until a patch can be added to Django (which would probably be very small and make all of this obsolete).

If we have inheritance of the form ModelA -> ModelB ->ModelC then Django creates accessors like this: - ModelA: modelb - ModelB: modela_ptr, modelb, modelc - ModelC: modela_ptr, modelb, modelb_ptr, modelc

These accessors allow Django (and everyone else) to travel up and down the inheritance tree for the db object at hand.

The original Django accessors use our polymorphic manager. But they should not. So we replace them with our own accessors that use our appropriate base_objects manager.

delete(*args, **kwargs)

Calling delete on a node will delete it as well as its full subtree, as opposed to reattaching all the subnodes to its parent node.

There are no argument specific to a MPTT model, all the arguments will be passed directly to the django’s Model.delete.

delete will not return anything.

get_absolute_url()

Return the URL to this page.

get_absolute_urls()

Return all available URLs to this page.

is_publication_date_active(date=None)

Return whether a configured publication date is within range.

New in version 2.0.4.

save(*args, **kwargs)

Save the model, and update caches.

save_translation(translation, *args, **kwargs)

Update the fields associated with the translation. This also rebuilds the decedent URLs when the slug changed.

breadcrumb

Return the breadcrumb; all parent pages leading to the current page, including current page itself.

can_be_root

Return True when the page type can be used as root page.

can_have_children

Return True when the node can have child nodes.

child_types

Return a list of content type ids of nodes that can be children of this node.

default_url

The internal implementation of get_absolute_url(). This function can be used when overriding get_absolute_url() in the settings. For example:

ABSOLUTE_URL_OVERRIDES = {
    'fluent_pages.Page': lambda o: "http://example.com" + o.default_url
}
is_draft

Return whether the node is still a draft.

is_file

Return True when the node represents a file (can’t have children, doesn’t have a layout).

is_first_child

Return True when the node is the first sibling.

is_last_child

Return True when the node is the last sibling.

is_published

Return whether the node is published.

last_modified

Return the last modification date of the page. Currently this is the last time the page was saved. This is implemented as separate property, to be extended to page content in the future.

page_key

Ensure get_child_types is run once per plugin model.

plugin

Access the parent plugin which renders this model.

url

The URL of the page, provided for template code.

The Page class

class fluent_pages.models.Page(*args, **kwargs)

The base class for all all UrlNode subclasses that display pages.

This is a proxy model that changes the appearance of the node in the admin. The UrlNode displays the URL path, while this model displays the title.

Parameters:
  • id (AutoField) – Id
  • polymorphic_ctype (ForeignKey to ContentType) – Polymorphic ctype
  • parent (PageTreeForeignKey to UrlNode) – Parent. You can also change the parent by dragging the page in the list.
  • parent_site (ForeignKey to Site) – Parent site
  • status (CharField) – Status
  • publication_date (DateTimeField) – Publication date. When the page should go live, status must be “Published”.
  • publication_end_date (DateTimeField) – Publication end date
  • in_navigation (BooleanField) – Show in navigation
  • in_sitemaps (BooleanField) – Include in search engine sitemaps
  • key (SlugField) – Page identifier. A unique identifier that is used for linking to this page.
  • author (ForeignKey to User) – Author
  • creation_date (DateTimeField) – Creation date
  • modification_date (DateTimeField) – Last modification
  • lft (PositiveIntegerField) – Lft
  • rght (PositiveIntegerField) – Rght
  • tree_id (PositiveIntegerField) – Tree id
  • level (PositiveIntegerField) – Level
exception DoesNotExist
exception MultipleObjectsReturned

The HtmlPage class

class fluent_pages.models.HtmlPage(*args, **kwargs)

The HtmlPage is the base for all page types that display HTML. This is a proxy model, which adds translatable SEO fields and a customizable title.

Parameters:
  • id (AutoField) – Id
  • polymorphic_ctype (ForeignKey to ContentType) – Polymorphic ctype
  • parent (PageTreeForeignKey to UrlNode) – Parent. You can also change the parent by dragging the page in the list.
  • parent_site (ForeignKey to Site) – Parent site
  • status (CharField) – Status
  • publication_date (DateTimeField) – Publication date. When the page should go live, status must be “Published”.
  • publication_end_date (DateTimeField) – Publication end date
  • in_navigation (BooleanField) – Show in navigation
  • in_sitemaps (BooleanField) – Include in search engine sitemaps
  • key (SlugField) – Page identifier. A unique identifier that is used for linking to this page.
  • author (ForeignKey to User) – Author
  • creation_date (DateTimeField) – Creation date
  • modification_date (DateTimeField) – Last modification
  • lft (PositiveIntegerField) – Lft
  • rght (PositiveIntegerField) – Rght
  • tree_id (PositiveIntegerField) – Tree id
  • level (PositiveIntegerField) – Level
exception DoesNotExist
exception MultipleObjectsReturned
delete(*args, **kwargs)

Calling delete on a node will delete it as well as its full subtree, as opposed to reattaching all the subnodes to its parent node.

There are no argument specific to a MPTT model, all the arguments will be passed directly to the django’s Model.delete.

delete will not return anything.

meta_robots

The value for the <meta name="robots" content=".."/> tag. It defaults to noindex when in_sitemaps is False.

The PageLayout class

class fluent_pages.models.PageLayout(*args, **kwargs)

A PageLayout object defines a template that can be used by a page.

Parameters:
  • id (AutoField) – Id
  • key (SlugField) – Key. A short name to identify the layout programmatically
  • title (CharField) – Title
  • template_path (TemplateFilePathField) – Template file
exception DoesNotExist
exception MultipleObjectsReturned
get_template()

Return the template to render this layout.

The UrlNodeManager class

class fluent_pages.models.UrlNodeManager

Extra methods attached to UrlNode.objects and Page.objects.

queryset_class

alias of UrlNodeQuerySet

best_match_for_path(path, language_code=None)

Return the UrlNode that is the closest parent to the given path.

UrlNode.objects.best_match_for_path(‘/photos/album/2008/09’) might return the page with url ‘/photos/album/’.

Changed in version 0.9: This filter only returns the pages of the current site.

get_for_key(key)

New in version 0.9: Return the UrlNode for the given key.

The key can be a slug-like value that was configured in FLUENT_PAGES_KEY_CHOICES.

get_for_path(path, language_code=None)

Return the UrlNode for the given path. The path is expected to start with an initial slash.

Raises UrlNode.DoesNotExist when the item is not found.

Changed in version 0.9: This filter only returns the pages of the current site.

in_navigation(for_user=None)

Return only pages in the navigation.

in_sitemaps()

New in version 0.9.

Return only pages in the navigation.

parent_site(site)

New in version 0.9: Filter to the given site.

published(for_user=None)

Return only published pages for the current site.

Changed in version 0.9: This filter only returns the pages of the current site.

toplevel()

Return all pages which have no parent.

toplevel_navigation(current_page=None, for_user=None, language_code=None)

Return all toplevel items, ordered by menu ordering.

When current_page is passed, the object values such as ‘is_current’ will be set.

url_pattern_types()

Return only page types which have a custom URLpattern attached.