APIs
Python APIs for creating and manipulating django CMS content.
These APIs are provided in order to provide a stable abstraction layer between internal django CMS functions and external code.
The APIs also make access to the functionality simpler, by providing more intuitive interface, with better input-checking.
Warning
None of the functions in this module make any security or permissions checks. They verify their input values for validity and make some basic sanity checks, but permissions checks should be implemented manually before calling any of these functions.
Warning
Due to potential circular dependency issues, we recommend that you import the APIs in the functions that use them. Use:
def my_function():
from cms.api import api_function
api_function(...)
rather than:
from cms.api import api_function
def my_function():
api_function(...)
cms.api.``create_page
(title, template, language, menu_title=None, slug=None, apphook=None, apphook_namespace=None, redirect=None, meta_description=None, created_by=’python-api’, parent=None, publication_date=None, publication_end_date=None, in_navigation=False, soft_root=False, reverse_id=None, navigation_extenders=None, published=False, site=None, login_required=False, limit_visibility_in_menu=VISIBILITY_ALL, position=”last-child”, overwrite_url=None, xframe_options=Page.X_FRAME_OPTIONS_INHERIT, with_revision=False)
Creates a cms.models.Page
instance and returns it. Also creates a cms.models.Title
instance for the specified language.
Parameters: |
|
---|
cms.api.``create_title
(language, title, page, menu_title=None, slug=None, redirect=None, meta_description=None, parent=None, overwrite_url=None, with_revision=False)
Creates a cms.models.Title
instance and returns it.
Parameters: |
|
---|
cms.api.``add_plugin
(placeholder, plugin_type, language, position=’last-child’, target=None, \*data*)
Adds a plugin to a placeholder and returns it.
Parameters: |
|
---|
cms.api.``create_page_user
(created_by, user, can_add_page=True, can_change_page=True, can_delete_page=True, can_recover_page=True, can_add_pageuser=True, can_change_pageuser=True, can_delete_pageuser=True, can_add_pagepermission=True, can_change_pagepermission=True, can_delete_pagepermission=True, grant_all=False)
Creates a page user for the user provided and returns that page user.
Parameters: |
|
---|
cms.api.``assign_user_to_page
(page, user, grant_on=ACCESS_PAGE_AND_DESCENDANTS, can_add=False, can_change=False, can_delete=False, can_change_advanced_settings=False, can_publish=False, can_change_permissions=False, can_move_page=False, grant_all=False)
Assigns a user to a page and gives them some permissions. Returns the cms.models.PagePermission
object that gets created.
Parameters: |
|
---|
cms.api.``publish_page
(page, user, language)
Publishes a page.
Parameters: |
|
---|
cms.api.``publish_pages
(include_unpublished=False, language=None, site=None)
Publishes multiple pages defined by parameters.
Parameters: |
|
---|
get_page_draft(page):
Returns the draft version of a page, regardless if the passed in page is a published version or a draft version.
Parameters: | page (cms.models.Page instance) – The page to get the draft version |
---|---|
Return page: | draft version of the page |
copy_plugins_to_language(page, source_language, target_language, only_empty=True):
Copy the plugins to another language in the same page for all the page placeholders.
By default plugins are copied only if placeholder has no plugin for the target language; use only_empty=False
to change this.
Warning
This function skips permissions checks
Parameters: |
|
---|---|
Return int: | number of copied plugins |
Examples of usage can be found in: