Table Of Contents

Previous topic

Included Applications

Next topic

Flat Pages Views

This Page

View handlers

djpcms handles views using objects rather than functions. Each view is an instance of a class derived from djpcms.views.baseview.djpcmsview.

View Base Class

class djpcms.views.baseview.djpcmsview

Base class for handling urls requests.

_methods

Tuple of request methods handled by self. By default GET and POST only:

_methods = ('get','post')
template_name

Used to override the template name in the djpcms.models.Page model instance (if it exists). Not used very often but here just in case.

parent

The parent view of self. An instance of djpcmsview or None

get_page(djp)

The djpcms.models.Page instances associated with this view.

methods(request)

Allowed request methods for this view. By default it returns _methods.

get_template(page=None)

Given a djpcms.models.Page instance page, which may be None, returns the template file for the GET response. If template_name is specified, it uses it, otherwise if page is available, it gets the template from djpcms.models.Page.get_template(). If page is None it returns DEFAULT_TEMPLATE_NAME.

title(page, **urlargs)

View title.

render(djp, **kwargs)

Render the Current View plugin. Return safe unicode This function is implemented by application views

handle_response(djp)

Handle the RESPONSE.This function SHOULD NOT be overwritten. Several functions can be overwritten for tweaking the results. If that is not enough, maybe more hooks should be put in place. Hooks: * 'preget': for pre-processing and redirect * 'render': for creating content when there is no inner_template * extra_response: for more.

post_response(djp)

Handle the post view. This function checks the request.POST dictionary for a post_view_key specified in HTML_CLASSES (by default 'xhr')

If it finds this key, the post view is an AJAX-JSON request and the key VALUE represents
a function responsible for handling the response.

These ajax enabled post view functions must start with the prefix ajax__ followed by the VALUE of the post_view_key.

Example:

so lets say we find in the POST dictionary

'xhr': 'change_parameter', ... }

Than there should be a function called 'ajax__change_parameter' which handle the response

has_permission(request=None, page=None, obj=None)

Check if view can be displayed.

in_navigation(request, page)

Hook for modifying the in_navigation property. This default implementation should suffice

children(djp, instance=None, **kwargs)

Return children permitted views for self. It includes views not in navigation. In scanning for children we porposefully leave a possible object instance out of the key-values arguments. If we didn't do that, test_navigation.testMultiPageApplication would fail.

redirect(url)

Shortcut function for redirecting to url.