Pages

class cms.models.pagemodel.Page(*args, **kwargs)

Bases: MP_Node

A Page is the basic unit of site structure in django CMS. The CMS uses a hierarchical page model: each page stands in relation to other pages as parent, child or sibling. This hierarchy is managed by the django-treebeard library.

A Page is an abstract entity. It does not have any content associated with it, nor does is provide any slugs to build a URL. This is part of the model PageContent and PageUrl respectively.

add_child(**kwargs)

Adds a child to the node.

This method saves the node in database. The object is populated as if via:

` obj = self.__class__(**kwargs) `

Raises:

PathOverflow – when no more child nodes can be added

add_sibling(pos=None, *args, **kwargs)

Adds a new node as a sibling to the current node object.

This method saves the node in database. The object is populated as if via:

` obj = self.__class__(**kwargs) `

Raises:

PathOverflow – when the library can’t make room for the node’s new position

apply_view_restrictions(restrictions, user=None)

Recreate restrictions (from get_view_restrictions) on this page.

Used when a page leaves the subtree its view restrictions came from: the ancestors that protected it no longer do, so their grants have to be materialized here. Only can_view is carried over – the editing privileges attached to the original rows are not privileges of the new location. Grants the page already inherits at its new position with at least the same scope are skipped, so repeated moves do not pile up redundant rows.

copy_with_descendants(target_page=None, target_node=None, position=None, copy_permissions=True, target_site=None, user=None)

Copy a page [ and all its descendants to a new location ]

delete(*args, **kwargs)

Removes a node and all it’s descendants.

get_application_urls(language=None, fallback=True, force_reload=False)

get application urls conf for application hook

get_changed_by(language=None, fallback=True, force_reload=False)

get user who last changed this page

get_changed_date(language=None, fallback=True, force_reload=False)

get when this page was last updated

get_content_obj(language=None, fallback=True, force_reload=False)

Helper function for accessing wanted / current title. If wanted title doesn’t exist, EmptyPageContent instance will be returned.

get_languages(admin_manager=True)

Returns available languages for the page. This is potentially costly.

get_media_path(filename)

Returns path (relative to MEDIA_ROOT/MEDIA_URL) to directory for storing page-scope files. This allows multiple pages to contain files with identical names without namespace issues. Plugins such as Picture can use this method to initialise the ‘upload_to’ parameter for File-based fields. For example:

image = models.ImageField(

_(“image”), upload_to=CMSPlugin.get_media_path)

where CMSPlugin.get_media_path calls self.page.get_media_path

This location can be customised using the CMS_PAGE_MEDIA_PATH setting

get_menu_title(language=None, fallback=True, force_reload=False)

get the menu title of the page depending on the given language

get_meta_description(language=None, fallback=True, force_reload=False)

get content for the description meta tag for the page depending on the given language

get_page_content_obj_attribute(attrname, language=None, fallback=True, force_reload=False)

Helper function for getting attribute or None from wanted/current page content.

get_page_title(language=None, fallback=True, force_reload=False)

get the page title of the page depending on the given language

get_redirect(language=None, fallback=True, force_reload=False)

get redirect

get_root()
Returns:

the root node for the current node object.

get_template_name()

get the textual name (2nd parameter in get_cms_setting(‘TEMPLATES’)) of the template of this page or of the nearest ancestor. failing to find that, return the name of the default template.

get_title(language=None, fallback=True, force_reload=False)

get the title of the page depending on the given language

get_url_obj(language, fallback=True)

Get the path of the page depending on the given language

get_view_restrictions(inherited_only=False)

Snapshot the can_view grants that currently protect this page.

Each entry is a (user_id, group_id, grant_on) tuple whose scope is expressed relative to this page: a grant inherited from an ancestor becomes ACCESS_PAGE_AND_DESCENDANTS when it also covers what is below this page, and ACCESS_PAGE when it stops here. The page’s own rows keep their own scope.

has_add_permission(user)

Has user ability to add page under current page?

has_change_permissions_permission(user)

Has user ability to change permissions for current page?

has_move_page_permission(user)

Has user ability to move current page?

is_potential_home()

Encapsulates logic for determining if this page is eligible to be set as is_home. This is a public method so that it can be accessed in the admin for determining whether to enable the “Set as home” menu item. :return: Boolean

move_page(target_page, position='first-child', user=None)

Called from admin interface when page is moved. Should be used on all the places which are changing page position. Used like an interface to django-treebeard.

reload()

Reload a page from the database

save(**kwargs)

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

set_as_homepage(user=None)

Sets the given page as the homepage. Updates the url paths for all affected pages. Returns the old home page (if any).

admin_content_cache

Internal cache for page content objects visible publicly

page_content_cache

Internal cache for page urls

class cms.models.pagemodel.PageUrl(id, slug, path, language, page, managed)

Bases: Model

class cms.models.pagemodel.PageType(id, path, depth, numchild, parent, site, created_by, changed_by, creation_date, changed_date, reverse_id, navigation_extenders, login_required, is_home, application_urls, application_namespace, is_page_type)

Bases: Page

is_potential_home()

Encapsulates logic for determining if this page is eligible to be set as is_home. This is a public method so that it can be accessed in the admin for determining whether to enable the “Set as home” menu item. :return: Boolean

.