Page module

class feincms.module.page.models.ActiveAwareContentManagerMixin

Implement what’s necessary to add some kind of “active” state for content objects. The notion of active is defined by a number of filter rules that must all match (AND) for the object to be active.

A Manager for a content class using the “datepublisher” extension should either adopt this mixin or implement a similar interface.

ActiveAwareContentManagerMixin.active()

Return only currently active objects.

classmethod ActiveAwareContentManagerMixin.add_to_active_filters(filter)

Add a new clause to the active filters. A filter may be either a Q object to be applied to the content class or a callable taking a queryset and spitting out a new one.

classmethod ActiveAwareContentManagerMixin.apply_active_filters(queryset)

Apply all filters defined to the queryset passed and return the result.

class feincms.module.page.models.Page(*args, **kwargs)

Page(id, lft, rght, tree_id, level, active, title, slug, parent_id, in_navigation, override_url, redirect_to, _cached_url)

Page.active_children()

Returns a queryset describing all active children of the current page. This is different than page.get_descendants (from mptt) as it will additionally select only child pages that are active.

Page.active_children_in_navigation()

Returns a queryset describing all active children that also have the in_navigation flag set. This might be used eg. in building navigation menues (only show a disclosure indicator if there actually is something to disclose).

Page.are_ancestors_active()

Check whether all ancestors of this page are active

Page.cache_key()

Return a string that may be used as cache key for the current page. The cache_key is unique for each content type and content instance.

Page.etag(request)

Generate an etag for this page. An etag should be unique and unchanging for as long as the page content does not change. Since we have no means to determine whether rendering the page now (as opposed to a minute ago) will actually give the same result, this default implementation returns None, which means “No etag please, thanks for asking”.

Page.etag_response_processor(request, response)

Response processor to set an etag header on outgoing responses. The Page.etag() method must return something valid as etag content whenever you want an etag header generated.

Page.finalize_response(request, response)

After rendering a page to a response, the registered response processors are called to modify the response, eg. for setting cache or expiration headers, keeping statistics, etc.

Page.get_absolute_url(*moreargs, **morekwargs)

Return the absolute URL of this page.

Page.get_navigation_url()

Return either redirect_to if it is set, or the URL of this page.

Page.get_redirect_to_target(request)

This might be overriden/extended by extension modules.

Page.get_siblings_and_self(page)

As the name says.

Page.is_active()

Check whether this page and all its ancestors are active

Page.last_modified(request)

Generate a last modified date for this page. Since a standard page has no way of knowing this, we always return “no date” – this is overridden by the changedate extension.

classmethod Page.register_request_processors(*processors)

Registers all passed callables as request processors. A request processor always receives two arguments, the current page object and the request.

classmethod Page.register_response_processors(*processors)

Registers all passed callables as response processors. A response processor always receives three arguments, the current page object, the request and the response.

Page.require_path_active_request_processor(request)

Checks whether any ancestors are actually inaccessible (ie. not inactive or expired) and raise a 404 if so.

Page.save(*args, **kwargs)

Overridden save method which updates the _cached_url attribute of this page and all subpages. Quite expensive when called with a page high up in the tree.

Page.setup_request(request)

Before rendering a page, run all registered request processors. A request processor may peruse and modify the page or the request. It can also return a HttpResponse for shortcutting the page rendering and returning that response immediately to the client.

Page.short_title()

Title shortened for display.

class feincms.module.page.models.PageManager

The page manager. Only adds new methods, does not modify standard Django manager behavior in any way.

PageManager.best_match_for_path(path, raise404=False)

Return the best match for a path. If the path as given is unavailable, continues to search by chopping path components off the end.

Tries hard to avoid unnecessary database lookups by generating all possible matching URL prefixes and choosing the longest match.

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

PageManager.for_request(request, raise404=False, best_match=False, setup=True)

Return a page for the request

Does not hit the database more than once for the same request.

Examples:

Page.objects.for_request(request, raise404=True, best_match=False)

Defaults to raising a DoesNotExist exception if no exact match could be determined.

PageManager.in_navigation()

Returns active pages which have the in_navigation flag set.

PageManager.page_for_path(path, raise404=False)

Return a page for a path. Optionally raises a 404 error if requested.

Example:

Page.objects.page_for_path(request.path)
PageManager.toplevel_navigation()

Returns top-level navigation entries.

Sitemap module

class feincms.module.page.sitemap.PageSitemap(navigation_only=False, max_depth=0, changefreq=None, queryset=None, filter=None, *args, **kwargs)

The PageSitemap can be used to automatically generate sitemap.xml files for submission to index engines. See http://www.sitemaps.org/ for details.

PageSitemap.items()

Consider all pages that are active and that are not a redirect

PageSitemap.priority(obj)

The priority is staggered according to the depth of the page in the site. Top level get highest priority, then each level is decreased by per_level.

Extensions

Date-based publishing

Allows setting a date range for when the page is active. Modifies the active() manager method so that only pages inside the given range are used in the default views and the template tags.

Depends on the page class having a “active_filters” list that will be used by the page’s manager to determine which entries are to be considered active.

feincms.module.page.extensions.datepublisher.format_date(d, if_none='')

Format a date in a nice human readable way: Omit the year if it’s the current year. Also return a default value if no date is passed in.

feincms.module.page.extensions.datepublisher.granular_now(n=None)

A datetime.now look-alike that returns times rounded to a five minute boundary. This helps the backend database to optimize/reuse/cache its queries by not creating a brand new query each time.

Also useful if you are using johnny-cache or a similar queryset cache.

Page excerpts

Add an excerpt field to the page.

Navigation extensions

Extend or modify the navigation with custom entries.

This extension allows the website administrator to select an extension which processes, modifies or adds subnavigation entries. The bundled feincms_navigation template tag knows how to collect navigation entries, be they real Page instances or extended navigation entries.

class feincms.module.page.extensions.navigation.NavigationExtension

Base class for all navigation extensions.

The name attribute is shown to the website administrator.

NavigationExtension.children(page, **kwargs)

This is the method which must be overridden in every navigation extension.

It receives the page the extension is attached to, the depth up to which the navigation should be resolved, and the current request object if it is available.

class feincms.module.page.extensions.navigation.PagePretender(**kwargs)

A PagePretender pretends to be a page, but in reality is just a shim layer that implements enough functionality to inject fake pages eg. into the navigation tree.

For use as fake navigation page, you should at least define the following parameters on creation: title, url, level. If using the translation extension, also add language.

class feincms.module.page.extensions.navigation.TypeRegistryMetaClass(name, bases, attrs)

You can access the list of subclasses as <BaseClass>.types

Related pages

Add a many-to-many relationship field to relate this page to other pages.

Flexible page titles

Sometimes, a single title is not enough, you’d like subtitles, and maybe differing titles in the navigation and in the <title>-tag. This extension lets you do that.

Page translations

This extension adds a language field to every page. When calling setup_request, the page’s language is activated. Pages in secondary languages can be said to be a translation of a page in the primary language (the first language in settings.LANGUAGES), thereby enabling deeplinks between translated pages.

This extension requires an activated LocaleMiddleware or something equivalent.

feincms.module.page.extensions.translations.translation_set_language(request, select_language)

Set and activate a language, if that language is available.

feincms.module.page.extensions.translations.user_has_language_set(request)

Determine whether the user has explicitely set a language earlier on. This is taken later on as an indication that we should not mess with the site’s language settings, after all, the user’s decision is what counts.

Extensions not specific to the page module

Creation and modification timestamps

Track the modification date for objects.

feincms.module.extensions.changedate.pre_save_handler(sender, instance, **kwargs)

Intercept attempts to save and insert the current date and time into creation and modification date fields.

Content type count denormalization

Track the content types for pages. Instead of gathering the content types present in each page at run time, save the current state at saving time, thus saving at least one DB query on page delivery.

feincms.module.extensions.ct_tracker.single_pre_save_handler(sender, instance, **kwargs)

Clobber the _ct_inventory attribute of this object

feincms.module.extensions.ct_tracker.tree_post_save_handler(sender, instance, **kwargs)

Clobber the _ct_inventory attribute of this object and all sub-objects on save.

Featured items

Add a “featured” field to objects so admins can better direct top content.

Search engine optimization fields

Add a keyword and a description field which are helpful for SEO optimization.