Pages¶
- class cms.models.pagemodel.Page(*args, **kwargs)¶
Bases:
MP_NodeA
Pageis 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
Pageis 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 modelPageContentandPageUrlrespectively.- 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
- 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_absolute_url(language=None, fallback=True)¶
Return the absolute URL of the page for the given language, or
Noneif the page has no reachable path (e.g. it or an ancestor is unpublished).
- 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 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_data(slug, overwrite_url, language)¶
Derive the
PageUrlfields (slug,path,managed) from an authored slug and overwrite URL.
- get_url_obj(language, fallback=True)¶
Get the path of the page depending on the given language
- 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')¶
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).
- update_urls_from_content(language)¶
Derive this page’s
PageUrlforlanguagefrom the publicly visiblePageContentobject, then update the paths of all descendant pages.The slug and overwrite URL are authored on the page content object.
PageUrlis a routing table that must only ever reflect published content: without a versioning package every saved content is public and this runs on every save; with a versioning package installed it must be called when a version is published or unpublished.When no public content exists, the URL’s path is set to
Noneso the page stops resolving while the slug stays reserved for the page.Raises
IntegrityErrorif the derived path collides with the URL of another page on the same site.
- 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, site, managed)¶
Bases:
Model- save(*args, **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.
- site¶
Denormalized from
page.siteso path uniqueness per site can be enforced by the database.
- 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
.