Page CMS reference API
Django page CMS declare rather simple models: Page
Content and PageAlias .
Those Django models have the following relations:
Placeholder module, that’s where the smart things appened.
class pages.placeholders. ImagePlaceholderNode ( name , page=None , widget=None , parsed=False , as_varname=None , inherited=False , untranslated=False )
A PlaceholderNode that saves one image on disk.
PAGE_UPLOAD_ROOT setting define where to save the image.
get_field ( page , language , initial=None )
save ( page , language , data , change , extra_data=None )
class pages.placeholders. PlaceholderNode ( name , page=None , widget=None , parsed=False , as_varname=None , inherited=False , untranslated=False )
This template node is used to output page content and
dynamically generate input fields in the admin.
Parameters:
name – the name of the placeholder you want to show/create
page – the optional page object
widget – the widget you want to use in the admin interface. Take
a look into pages.widgets to see which widgets
are available.
parsed – if the parsed word is given, the content of the
placeholder is evaluated as template code, within the current
context.
as_varname – if as_varname is defined, no value will be
returned. A variable will be created in the context
with the defined name.
inherited – inherit content from parent’s pages.
untranslated – the placeholder’s content is the same for
every language.
field
alias of CharField
get_content ( page_obj , lang , lang_fallback=True )
get_content_from_context ( context )
Get eventual extra data for this placeholder from the
POST dictionary.
get_field ( page , language , initial=None )
The field that will be shown within the admin.
get_widget ( page , language , fallback=<class 'django.forms.widgets.Textarea'> )
Given the name of a placeholder return a Widget subclass
like Textarea or TextInput.
render ( context )
Output the content of the PlaceholdeNode in the template.
save ( page , language , data , change , extra_data=None )
Actually save the placeholder data into the Content object.
widget
alias of TextInput
class pages.placeholders. VideoPlaceholderNode ( name , page=None , widget=None , parsed=False , as_varname=None , inherited=False , untranslated=False )
A youtube PlaceholderNode , just here as an example.
render ( context )
widget
alias of VideoWidget
pages.placeholders. parse_placeholder ( parser , token )
Parse the PlaceholderNode parameters.
Return a tuple with the name and parameters.
Page CMS page_tags template tags
class pages.templatetags.pages_tags. FakeCSRFNode
Fake CSRF node for django 1.1.1
class pages.templatetags.pages_tags. GetContentNode ( page , content_type , varname , lang )
Get content node
class pages.templatetags.pages_tags. GetPageNode ( page , varname )
get_page Node
class pages.templatetags.pages_tags. LoadPagesNode
Load page node.
pages.templatetags.pages_tags. do_get_content ( parser , token )
Retrieve a Content object and insert it into the template’s context.
Example:
{% get_content page_object "title" as content %}
You can also use the slug of a page:
{% get_content "my-page-slug" "title" as content %}
Syntax:
{% get_content page type [lang] as name %}
Parameters:
page – the page object, slug or id
type – content_type used by a placeholder
name – name of the context variable to store the content in
lang – the wanted language
pages.templatetags.pages_tags. do_get_page ( parser , token )
Retrieve a page and insert into the template’s context.
Example:
{% get_page "news" as news_page %}
Parameters:
page – the page object, slug or id
name – name of the context variable to store the page in
pages.templatetags.pages_tags. do_imageplaceholder ( parser , token )
Method that parse the imageplaceholder template tag.
pages.templatetags.pages_tags. do_load_pages ( parser , token )
Load the navigation pages, lang, and current_page variables into the
current context.
Example:
<ul>
{% load_pages %}
{% for page in pages_navigation %}
{% pages_menu page %}
{% endfor %}
</ul>
pages.templatetags.pages_tags. do_placeholder ( parser , token )
Method that parse the placeholder template tag.
Syntax:
{% placeholder <name> [on <page>] [with <widget>] [parsed] [as <varname>] %}
Example usage:
{% placeholder about %}
{% placeholder body with TextArea as body_text %}
{% placeholder welcome with TextArea parsed as welcome_text %}
{% placeholder teaser on next_page with TextArea parsed %}
pages.templatetags.pages_tags. do_videoplaceholder ( parser , token )
Method that parse the imageplaceholder template tag.
pages.templatetags.pages_tags. get_page_from_string_or_id ( page_string , lang=None )
Return a Page object from a slug or an id.
pages.templatetags.pages_tags. has_content_in ( page , language )
Fitler that return True if the page has any content in a
particular language.
Parameters:
page – the current page
language – the language you want to look at
pages.templatetags.pages_tags. language_content_up_to_date ( page , language )
Tell if all the page content has been updated since the last
change of the official version (settings.LANGUAGE_CODE)
This is approximated by comparing the last modified date of any
content in the page, not comparing each content block to its
corresponding official language version. That allows users to
easily make “do nothing” changes to any content block when no
change is required for a language.
Render the admin table of pages.
pages.templatetags.pages_tags. pages_breadcrumb
Tags
Render a “dynamic” tree menu, with all nodes expanded which are either
ancestors or the current page itself.
Override pages/dynamic_tree_menu.html if you want to change the
design.
Parameters:
page – the current page
url – not used anymore
Render a nested list of all the descendents of the given page,
including this page.
Parameters:
page – the page where to start the menu from.
url – not used anymore.
Get the parent page of the given page and render a nested list of its
child pages. Good for rendering a secondary menu.
Parameters:
page – the page where to start the menu from.
url – not used anymore.
Get the root page of the given page and
render a nested list of all root’s children pages.
Good for rendering a secondary menu.
Parameters:
page – the page where to start the menu from.
url – not used anymore.
pages.templatetags.pages_tags. show_absolute_url ( context , page , lang=None )
Show the url of a page in the right language
Example
{% show_absolute_url page_object %}
You can also use the slug of a page:
{% show_absolute_url "my-page-slug" %}
Keyword arguments:
:param page: the page object, slug or id
:param lang: the wanted language (defaults to settings.PAGE_DEFAULT_LANGUAGE )
pages.templatetags.pages_tags. show_content ( context , page , content_type , lang=None , fallback=True )
Display a content type from a page.
Example:
{% show_content page_object "title" %}
You can also use the slug of a page:
{% show_content "my-page-slug" "title" %}
Or even the id of a page:
{% show_content 10 "title" %}
Parameters:
page – the page object, slug or id
content_type – content_type used by a placeholder
lang – the wanted language (default None, use the request object to know)
fallback – use fallback content from other language
pages.templatetags.pages_tags. show_revisions ( context , page , content_type , lang=None )
Render the last 10 revisions of a page content with a list using
the pages/revisions.html template
pages.templatetags.pages_tags. show_slug_with_level ( context , page , lang=None , fallback=True )
Display slug with level by language.
Django CMS come with a set of ready to use widgets that you can enable
in the admin via a placeholder tag in your template.
class pages.widgets. CKEditor ( language=None , attrs=None , **kwargs )
CKEditor widget.
class Media
CKEditor. media
CKEditor. render ( name , value , attrs=None , **kwargs )
class pages.widgets. EditArea ( language=None , attrs=None , **kwargs )
EditArea is a html syntax coloured widget.
class Media
EditArea. media
EditArea. render ( name , value , attrs=None , **kwargs )
class pages.widgets. ImageInput ( page=None , language=None , attrs=None , **kwargs )
media
render ( name , value , attrs=None , **kwargs )
class pages.widgets. LanguageChoiceWidget ( language=None , attrs=None , **kwargs )
media
render ( name , value , attrs=None , **kwargs )
class pages.widgets. RichTextarea ( language=None , attrs=None , **kwargs )
A RichTextarea widget.
class Media
RichTextarea. media
RichTextarea. render ( name , value , attrs=None , **kwargs )
class pages.widgets. VideoWidget ( attrs=None , page=None , language=None , video_url=None , weight=None , height=None )
A youtube Widget for the admin.
decompress ( value )
format_output ( rendered_widgets )
Given a list of rendered widgets (as strings), it inserts an HTML
linebreak between them.
Returns a Unicode string representing the HTML for the whole lot.
media
value_from_datadict ( data , files , name )
class pages.widgets. WYMEditor ( language=None , attrs=None , **kwargs )
WYMEditor widget.
class Media
WYMEditor. media
WYMEditor. render ( name , value , attrs=None , **kwargs )
class pages.widgets. markItUpHTML ( attrs=None )
markItUpHTML widget.
class Media
markItUpHTML. media
markItUpHTML. render ( name , value , attrs=None , **kwargs )
class pages.widgets. markItUpMarkdown ( attrs=None )
markItUpMarkdown widget.
class Media
markItUpMarkdown. media
markItUpMarkdown. render ( name , value , attrs=None , **kwargs )
class pages.models. Page ( *args , **kwargs )
This model contain the status, dates, author, template.
The real content of the page can be found in the
Content model.
creation_date
When the page has been created.
publication_date
When the page should be visible.
publication_end_date
When the publication of this page end.
last_modification_date
Last time this page has been modified.
status
The current status of the page. Could be DRAFT, PUBLISHED,
EXPIRED or HIDDEN. You should the property :attr:`calculated_status` if
you want that the dates are taken in account.
template
A string containing the name of the template file for this page.
calculated_status
Get the calculated status of the page based on
Page.publication_date ,
Page.publication_end_date ,
and Page.status .
expose_content ( )
Return all the current content of this page into a string .
This is used by the haystack framework to build the search index.
get_absolute_url ( *moreargs , **morekwargs )
Alias for get_url_path .
This method is only there for backward compatibility and will be
removed in a near futur.
Parameter: language – the wanted url language.
get_ancestors ( ascending=False )
Creates a QuerySet containing the ancestors of this model
instance.
This defaults to being in descending order (root ancestor first,
immediate parent last); passing True for the ascending
argument will reverse the ordering (immediate parent first, root
ancestor last).
get_children ( )
Creates a QuerySet containing the immediate children of this
model instance, in tree order.
The benefit of using this method over the reverse relation
provided by the ORM to the instance’s children is that a
database query can be avoided in the case where the instance is
a leaf node (it has no children).
get_children_for_frontend ( )
Return a QuerySet of published children page
get_complete_slug ( language=None )
Return the complete slug of this page by concatenating
all parent’s slugs.
Parameter: language – the wanted slug language.
get_content ( language , ctype , language_fallback=False )
Shortcut method for retrieving a piece of page content
Parameters:
language – wanted language, if not defined default is used.
ctype – the type of content.
fallback – if True , the content will also be searched in other languages.
get_date_ordered_children_for_frontend ( )
Return a QuerySet of published children page ordered
by publication date.
get_descendant_count ( )
Returns the number of descendants this model instance has.
get_descendants ( include_self=False )
Creates a QuerySet containing descendants of this model
instance, in tree order.
If include_self is True , the QuerySet will also
include this model instance.
get_languages ( )
Return a list of all used languages for this page.
get_next_sibling ( )
Returns this model instance’s next sibling in the tree, or
None if it doesn’t have a next sibling.
get_previous_sibling ( )
Returns this model instance’s previous sibling in the tree, or
None if it doesn’t have a previous sibling.
get_root ( )
Returns the root node of this model instance’s tree.
get_siblings ( include_self=False )
Creates a QuerySet containing siblings of this model
instance. Root nodes are considered to be siblings of other root
nodes.
If include_self is True , the QuerySet will also
include this model instance.
get_template ( )
Get the template of this page if
defined or the closer parent’s one if defined
or pages.settings.PAGE_DEFAULT_TEMPLATE otherwise.
get_template_name ( )
Get the template name of this page if defined or if a closer
parent has a defined template or
pages.settings.PAGE_DEFAULT_TEMPLATE otherwise.
get_url ( language=None )
Alias for get_complete_slug .
This method is only there for backward compatibility and will be
removed in a near futur.
Parameter: language – the wanted url language.
get_url_path ( language=None )
Return the URL’s path component. Add the language prefix if
PAGE_USE_LANGUAGE_PREFIX setting is set to True .
Parameter: language – the wanted url language.
has_broken_link ( )
Return True if the page have broken links to other pages
into the content.
insert_at ( target , position='first-child' , commit=False )
Convenience method for calling TreeManager.insert_node with this
model instance.
invalidate ( )
Invalidate cached data for this page.
is_child_node ( )
Returns True if this model instance is a child node, False
otherwise.
is_first_root ( )
Return True if the page is the first root page.
is_leaf_node ( )
Returns True if this model instance is a leaf node (it has no
children), False otherwise.
is_root_node ( )
Returns True if this model instance is a root node,
False otherwise.
margin_level ( )
Used in the admin menu to create the left margin.
move_to ( target , position='first-child' )
Convenience method for calling TreeManager.move_node with this
model instance.
save ( *args , **kwargs )
Override the default save method.
slug ( language=None , fallback=True )
Return the slug of the page depending on the given language.
Parameters:
language – wanted language, if not defined default is used.
fallback – if True , the slug will also be searched in other languages.
slug_with_level ( language=None )
Display the slug of the page prepended with insecable
spaces equal to the level of page in the hierarchy.
title ( language=None , fallback=True )
Return the title of the page depending on the given language.
Parameters:
language – wanted language, if not defined default is used.
fallback – if True , the slug will also be searched in other languages.
valid_targets ( )
Return a QuerySet of valid targets for moving a page
into the tree.
Parameter: perms – the level of permission of the concerned user.
class pages.managers. PageManager
Page manager provide several filters to obtain pages QuerySet
that respect the page attributes and project settings.
drafts ( )
Creates a QuerySet of drafts using the page’s
Page.publication_date .
expired ( )
Creates a QuerySet of expired using the page’s
Page.publication_end_date .
filter_published ( queryset )
Filter the given pages QuerySet to obtain only published
page.
from_path ( complete_path , lang , exclude_drafts=True )
Return a Page according to
the page’s path.
hidden ( )
Creates a QuerySet of the hidden pages.
navigation ( )
Creates a QuerySet of the published root pages.
on_site ( site_id=None )
Return a QuerySet of pages that are published on the site
defined by the SITE_ID setting.
Parameter: site_id – specify the id of the site object to filter with.
populate_pages ( parent=None , child=5 , depth=5 )
Create a population of Page
for testing purpose.
published ( )
Creates a QuerySet of published
Page .
root ( )
Return a QuerySet of pages without parent.
class pages.models. Content ( *args , **kwargs )
A block of content, tied to a Page ,
for a particular language
exception DoesNotExist
exception Content. MultipleObjectsReturned
Content. get_next_by_creation_date ( *moreargs , **morekwargs )
Content. get_previous_by_creation_date ( *moreargs , **morekwargs )
Content. page
class pages.managers. ContentManager
Content manager methods
create_content_if_changed ( page , language , ctype , body )
Create a Content for a particular
page and language only if the content has changed from the last
time.
Parameters:
page – the concerned page object.
language – the wanted language.
ctype – the content type.
body – the content of the Content object.
get_content ( page , language , ctype , language_fallback=False )
Gets the latest Content
for a particular page and language. Falls back to another
language if wanted.
Parameters:
page – the concerned page object.
language – the wanted language.
ctype – the content type.
language_fallback – fallback to another language if True .
get_content_slug_by_slug ( slug )
Returns the latest Content
slug object that match the given slug for the current site domain.
Parameter: slug – the wanted slug.
get_page_ids_by_slug ( slug )
Return all page’s id matching the given slug.
Parameter: slug – the wanted slug.
sanitize ( content )
Sanitize a string in order to avoid possible XSS using
html5lib .
set_or_create_content ( page , language , ctype , body )
Set or create a Content for a
particular page and language.
Parameters:
page – the concerned page object.
language – the wanted language.
ctype – the content type.
body – the content of the Content object.
class pages.models. PageAlias ( *args , **kwargs )
URL alias for a Page
exception DoesNotExist
exception PageAlias. MultipleObjectsReturned
PageAlias. page
PageAlias. save ( *args , **kwargs )
class pages.managers. PageAliasManager
PageAlias manager.
from_path ( request , path , lang )
Resolve a request to an alias. returns a
PageAlias if the url matches
no page at all. The aliasing system supports plain
aliases (/foo/bar ) as well as aliases containing GET parameters
(like index.php?page=foo ).
Parameters:
request – the request object
path – the complete path to the page
lang – not used
A collection of functions for Page CMS
pages.utils. filter_link ( content , page , language , content_type )
Transform the HTML link href to point to the targeted page
absolute URL.
>>> filter_link ( '<a class="page_1">hello</a>' , page , 'en-us' , body )
'<a href="/pages/page-1" class="page_1">hello</a>'
pages.utils. get_context_mock ( )
return a mockup dictionnary to use in get_placeholders.
pages.utils. get_placeholders ( template_name )
Return a list of PlaceholderNode found in the given template.
Parameter: template_name – the name of the template file
pages.utils. normalize_url ( url )
Return a normalized url with trailing and without leading slash.
>>> normalize_url ( None )
'/'
>>> normalize_url ( '/' )
'/'
>>> normalize_url ( '/foo/bar' )
'/foo/bar'
>>> normalize_url ( 'foo/bar' )
'/foo/bar'
>>> normalize_url ( '/foo/bar/' )
'/foo/bar'
Page CMS functions related to the request object.
exception pages.http. AutoRenderHttpError
Cannot return context dictionary because a view returned an
HttpResponse when a (template_name, context) tuple was expected.
pages.http. auto_render ( func )
This view decorator automatically calls the render_to_response
shortcut. A view that use this decorator should return a tuple of this
form : (template name, context) instead of a HttpRequest object.
pages.http. get_language_from_request ( request )
Return the most obvious language according the request.
pages.http. get_request_mock ( )
Build a request mock up that can be used for testing.
pages.http. get_slug_and_relative_path ( path , lang=None )
Return the page’s slug, relative path and language.
>>> get_slug_and_relative_path ( '/test/function/' )
('function', 'test/function', None)
pages.http. get_template_from_request ( request , page=None )
Gets a valid template from different sources or falls back to the
default template.
pages.http. pages_view ( view )
Provide the essential pages variables to the decorated view
by using the default pages.views.details view.
Pages admin views
pages.admin.views. change_status ( request , *args , **kwargs )
Switch the status of a page.
pages.admin.views. delete_content ( request , *args , **kwargs )
pages.admin.views. modify_content ( request , *args , **kwargs )
Modify the content of a page.
pages.admin.views. move_page ( request , page_id , extra_context=None )
Move the page to the requested target, at the given
position