API References

    Warning

    None of the functions in this module does any security or permission checks. They verify their input values to be sane wherever possible, however permission checks should be implemented manually before calling any of these functions.

    Warning

    Due to potential circular dependency issues, it’s recommended to import the api in the functions that uses its function.

    e.g. use:

    instead of:

    Used for the limit_visibility_in_menu keyword argument to create_page(). Does not limit menu visibility.

    cms.api.VISIBILITY_USERS

    Used for the limit_visibility_in_menu keyword argument to . Limits menu visibility to authenticated users.

    cms.api.VISIBILITY_ANONYMOUS

    Used for the limit_visibility_in_menu keyword argument to create_page(). Limits menu visibility to anonymous (not authenticated) users.

    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)

    Creates a instance and returns it. Also creates a cms.models.Title instance for the specified language.

    cms.api.create_title(language, title, page, menu_title=None, slug=None, redirect=None, meta_description=None, parent=None, overwrite_url=None)

    Creates a instance and returns it.

    Parameters:
    • language (str) – Language code for this page. Must be in
    • title (str) – Title of the page
    • page ( instance) – The page for which to create this title
    • menu_title (str) – Menu title for this page
    • slug () – Slug for the page, by default uses a slugified version of title
    • redirect (str) – URL redirect
    • meta_description () – Description of this page for SEO
    • parent (cms.models.Page instance) – Used for automated slug generation
    • overwrite_url () – Overwritten path for this page
    • page_title (str) – Overridden page title for HTML title tag

    cms.api.add_plugin(placeholder, plugin_type, language, position=’last-child’, target=None, \*data*)

    Adds a plugin to a placeholder and returns it.

    Parameters:
    • placeholder ( instance) – Placeholder to add the plugin to
    • plugin_type (str or cms.plugin_base.CMSPluginBase sub-class, must be a valid plugin) – What type of plugin to add
    • language () – Language code for this plugin, must be in LANGUAGES
    • position () – Position to add this plugin to the placeholder, must be a valid django-treebeard pos value for treebeard.models.Node.add_sibling()
    • target – Parent plugin. Must be plugin instance
    • data – Data for the plugin type instance

    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.

    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 object that gets created.

    Parameters:

    cms.api.publish_page(page, user, language)

    Publishes a page.

    Parameters:
    • page (cms.models.Page instance) – The page to publish
    • user ( instance) – The user that performs this action
    • language (str) – The target language to publish to

    (include_unpublished=False, language=None, site=None)

    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 ( 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:
    • page (cms.models.Page instance) – the page to copy
    • source_language () – The source language code, must be in LANGUAGES
    • target_language () – The source language code, must be in LANGUAGES
    • only_empty () – if False, plugin are copied even if plugins exists in the target language (on a placeholder basis).
    Return int:

    number of copied plugins

    Example workflows

    Create a page called 'My Page using the template 'my_template.html' and add a text plugin with the content 'hello world'. This is done in English:

    cms.constants.TEMPLATE_INHERITANCE_MAGIC

    The token used to identify when a user selects “inherit” as template for a page.

    cms.constants.LEFT

    Used as a position indicator in the toolbar.

    cms.constants.RIGHT

    Used as a position indicator in the toolbar.

    cms.constants.REFRESH

    Constant used by the toolbar.

    cms.constants.EXPIRE_NOW

    Constant of 0 (zero) used for cache control headers

    cms.constants.MAX_EXPIRATION_TTL

    Constant of 31536000 or 365 days in seconds used for cache control headers

    class cms.app_base.CMSApp

    • list of urlconfs: example: _urls = ["myapp.urls"]

    • _menus

    • name = None

      name of the apphook (required)

    • app_name = None

      name of the app, this enables Django namespaces support (optional)

    • app_config = None

      configuration model (optional)

    • permissions = True

      if set to true, apphook inherits permissions from the current page

    • exclude_permissions = []

      list of application names to exclude from inheriting CMS permissions

    • get_configs()

      Returns all the apphook configuration instances.

    • get_config(namespace)

      Returns the apphook configuration instance linked to the given namespace

    • get_config_add_url()

      Returns the url to add a new apphook configuration instance (usually the model admin add view)

    • get_menus(page, language, \*kwargs*)

      New in version 3.3: CMSApp.get_menus accepts page, language and generic keyword arguments: you can customize this function to return different list of menu classes according to the given arguments.

      Returns the menus for the apphook instance, selected according to the given arguments.

      By default it returns the menus assigned to

      If no page and language are provided, this method must return all the menus used by this apphook. Example:

    • get_urls(page, language, \*kwargs*)

      New in version 3.3.

      Returns the URL configurations for the apphook instance, selected according to the given arguments.

      By default it returns the urls assigned to _urls

      Parameters:
      • language – current site language
      Returns:

      list of strings representing URL configurations