Pages (feincms3.pages
)¶
- class feincms3.pages.AbstractPage(*args, **kwargs)[source]¶
Short version: If you want to build a CMS with a hierarchical page structure, use this base class.
It comes with the following fields:
parent
: (a nullable tree foreign key) and aposition
field for relatively ordering pages. While it is technically possible forposition
to be 0, e.g., data bulk imported from another CMS, it is not recommended, as thesave()
method will override values of 0 if you manipulate pages using the ORM.is_active
: Boolean field. Thesave()
method ensures that inactive pages never have any active descendants.title
andslug
path
: The complete path to the page, starting and ending with a slash. The maximum length of path (1000) should be enough for everyone (tm, famous last words). This field also has a unique index, which means that MySQL with its low limit on unique indexes will not work with this base class. Sorry.static_path
: A boolean which, whenTrue
, allows you to fill in thepath
field all by yourself. By default,save()
ensures that thepath
fields are always composed of a concatenation of the parent’spath
with the page’s ownslug
(with slashes of course). This is especially useful for root pages (setpath
to/
) or, when building a multilingual site, for language root pages (i.e./en/
,/de/
,/pt-br/
etc.)
- get_absolute_url()[source]¶
Return the page’s absolute URL
If path is
/
, reversespages:root
without any arguments, alternatively reversespages:page
with an argument ofpath
. Note that thispath
is not the same asself.path
– slashes are stripped from the beginning and the end of the string to make building an URLconf more straightforward.If any
reverse()
call fails it falls back to returningself.path
prefixed with the script prefix which is/
in the standard case.
- save(self, ..., save_descendants=None)[source]¶
Saves the page instance, and traverses all descendants to update their
path
fields and ensure that inactive pages (is_active=False
) never have any descendants withis_active=True
.By default, descendants are only updated when any of
is_active
andpath
change. This can be overridden by either forcing updates usingsave_descendants=True
or skipping them usingsave_descendants=False
.
- class feincms3.pages.AbstractPageQuerySet(model=None, query=None, using=None, hints=None)[source]¶
Defines a single method,
active
, which only returns pages withis_active=True
.- active()[source]¶
Return only active pages
This function is used in
apps_urlconf()
and is the recommended way to fetch active pages in your code as well.
- applications()[source]¶
Helper for transforming a queryset into the apps format
apps_urlconf()
expects. The queryset isn’t filtered (on purpose) so you have to apply the.active()
filtering yourself.