Table Of Contents

Previous topic

Flat Pages Views

Next topic

Urls

This Page

Application Views

Base Class

class djpcms.views.appview.AppViewBase(parent=None, regex=None, splitregex=False, insitemap=True, isapp=False, isplugin=False, in_navigation=0, template_name=None, description=None, form=None, form_withrequest=None, form_ajax=None)

A djpcms.views.baseview.djpcmsview specialised class for application views in djpcms applications.

name

name of view.

parent

instance of AppViewBase or None.

_form

Form class associated with view. Default None.

isapp

if True the view will be added to the application list and can have its own page object. Default False.

isplugin

if True the view can be rendered as djpcms.plugins.DJPplugin. Default False.

in_navigation

If 0 the view won’t appear in Navigation.

plugin_form

The djpcms.plugins.DJPplugin.form for this view. Default None.

isroot()

True if this application view represents the root view of the application.

render(djp, **kwargs)

Render the application child. This method is reimplemented by subclasses. By default it renders the search application

parentresponse(djp)

Retrive the parent response

processurlbits(appmodel)

Process url bits and store information for navigation and urls

App View

class djpcms.views.appview.AppView(isapp=True, splitregex=True, **kwargs)

An AppViewBase class for views in djpcms.views.appsite.ModelApplication.

modelparent()

Return a parent with same model if it exists

basequery(request, **kwargs)

Base query for application. If this is the root view (no parents) it returns djpcms.views.appsite.ModelApplication.basequery(), otherwise it returns the appquery() of the modelparent() view.

appquery(request, *args, **kwargs)

This function implements the application query. By default return the basequery() (usually all items of a model).

Search View

class djpcms.views.appview.SearchView(in_navigation=True, **kwargs)

An AppView class for searching objects in model. By default AppViewBase.in_navigation is set to True.

search_text

identifier for queries. Default search_text.

appquery(request, *args, **kwargs)

This function implements the search query. The query is build using the search fields specifies in djpcms.views.appsite.ModelApplication.search_fields. It returns a queryset.

render(djp, **kwargs)

Perform the custom query over the model objects and return a paginated result

Add View

class djpcms.views.appview.AddView(regex='add', isplugin=True, in_navigation=True, **kwargs)

An AppView class which renders a form for adding instances and handles the saving as default POST response.

Object View

class djpcms.views.appview.ObjectView(isapp=True, splitregex=True, **kwargs)

An AppView class view for model instances. A view of this type has an embedded object available which is used to generate the full url.

View View

class djpcms.views.appview.ViewView(regex='(?P<id>\d+)', **kwargs)

An ObjectView class specialised for displaying an object.

render(djp)

Render the view object

Edit View

class djpcms.views.appview.EditView(regex='edit', parent='view', **kwargs)

An ObjectView class specialised for editing an object.

ajax__save(djp)

Save and redirect to default redirect

ajax__save_and_continue(djp)

Save and redirect to default redirect

Delete View

class djpcms.views.appview.DeleteView(regex='delete', parent='view', isapp=False, **kwargs)

An ObjectView class specialised for deleting an object.

Autocomplete View

class djpcms.views.appview.AutocompleteView(regex='autocomplete', display='name', **kwargs)

This is an interesting view. It is an AJAX Get only view for auto-complete functionalities. To use it, add it to a djpcms.views.appsite.ModelApplication declaration.

Let’s say you have a model:

from django.db import models

class MyModel(models.Model):
    name = models.CharField(max_length = 60)
    description = models.TextField()

And we would like to have an auto-complete view which displays the name field and search for both name and description fields:

from djpcms.views.appsite import ModelApplication

class MyModelApp(ModelApplication):
    search_fields = ['name','description']
    complete = AutocompleteView(display = 'name')
    
appsite.site.register('/mymodelurl/', MyModelApp, model = MyModel)

The last bit of information is to use a different ModelChoiceField and ModelMultipleChoiceField in your forms. Rather than doing:

from django.forms import ModelChoiceField, ModelMultipleChoiceField

do:

from djpcms.forms import ModelChoiceField, ModelMultipleChoiceField

and if your model has an AutocompleteView installed, it will work out of the box.

get_response(djp)

This response works only if it is an AJAX response. Otherwise it raises a Http404 exception.

Rember the four points to have autocomplete out of the box:

  • When using the model in Forms, import from djpcms.forms and not django.forms.