Base views

CubicWeb provides a lot of standard views, that can be found in cubicweb.web.views sub-modules.

A certain number of views are used to build the web interface, which apply to one or more entities. As other appobjects, their identifier is what distinguish them from each others. The most generic ones, found in cubicweb.web.views.baseviews, are described below.

You’ll probably want to customize one or more of the described views which are default, generic, implementations.

HTML views

Special views

class cubicweb.web.views.baseviews.NullView(req=None, rset=None, **kwargs)[source]
__regid__:null

This view is the default view used when nothing needs to be rendered. It is always applicable and is usually used as fallback view when calling _cw.view() to display nothing if the result set is empty.

class cubicweb.web.views.baseviews.NoResultView(req=None, rset=None, **kwargs)[source]
__regid__:noresult

This view is the default view to be used when no result has been found (i.e. empty result set).

It’s usually used as fallback view when calling _cw.view() to display “no results” if the result set is empty.

class cubicweb.web.views.baseviews.FinalView(req=None, rset=None, **kwargs)[source]
__regid__:final

Display the value of a result set cell with minimal transformations (i.e. you’ll get a number for entities). It is applicable on any result set, though usually dedicated for cells containing an attribute’s value.

Base entity views

class cubicweb.web.views.baseviews.InContextView(req=None, rset=None, **kwargs)[source]
__regid__:incontext

This view is used when the entity should be considered as displayed in its context. By default it produces the result of entity.dc_title() wrapped in a link leading to the primary view of the entity.

class cubicweb.web.views.baseviews.OutOfContextView(req=None, rset=None, **kwargs)[source]
__regid__:outofcontext

This view is used when the entity should be considered as displayed out of its context. By default it produces the result of entity.dc_long_title() wrapped in a link leading to the primary view of the entity.

class cubicweb.web.views.baseviews.OneLineView(req=None, rset=None, **kwargs)[source]
__regid__:oneline

This view is used when we can’t tell if the entity should be considered as displayed in or out of context. By default it produces the result of the text view in a link leading to the primary view of the entity.

Those are used to display a link to an entity, whose label depends on the entity having to be displayed in or out of context (of another entity): some entities make sense in the context of another entity. For instance, the Version of a Project in forge. So one may expect that ‘incontext’ will be called when display a version from within the context of a project, while ‘outofcontext”’ will be called in other cases. In our example, the ‘incontext’ view of the version would be something like ‘0.1.2’, while the ‘outofcontext’ view would include the project name, e.g. ‘baz 0.1.2’ (since only a version number without the associated project doesn’t make sense if you don’t know yet that you’re talking about the famous ‘baz’ project. CubicWeb tries to make guess and call ‘incontext’/’outofcontext’ nicely. When it can’t know, the ‘oneline’ view should be used.

List entity views

class cubicweb.web.views.baseviews.ListView(req=None, rset=None, **kwargs)[source]
__regid__:list

This view displays a list of entities by creating a HTML list (<ul>) and call the view listitem for each entity of the result set. The ‘list’ view will generate HTML like:

<ul class="section">
  <li>"result of 'subvid' view for a row</li>
  ...
</ul>

If you wish to use a different view for each entity, either subclass and change the item_vid class attribute or specify a subvid argument when calling this view.

class cubicweb.web.views.baseviews.SimpleListView(req=None, rset=None, **kwargs)[source]
__regid__:simplelist

Similar to :class:~cubicweb.web.views.baseviews.ListView but using ‘<div>’ instead of ‘<ul>’. It rely on ‘<div>’ behaviour to separate items. HTML will look like

<div class="section">"result of 'subvid' view for a row</div>
...

It relies on base View class implementation of the call() method to insert those <div>.

class cubicweb.web.views.baseviews.SameETypeListView(req=None, rset=None, **kwargs)[source]
__regid__:sameetypelist

This view displays a list of entities of the same type, in HTML section (‘<div>’) and call the view sameetypelistitem for each entity of the result set. It’s designed to get a more adapted global list when displayed entities are all of the same type (for instance, display gallery if there are only images entities).

class cubicweb.web.views.baseviews.CSVView(req=None, rset=None, **kwargs)[source]
__regid__:csv

This view displays each entity in a coma separated list. It is NOT related to the well-known text file format.

Those list views can be given a ‘subvid’ arguments, telling the view to use of each item in the list. When not specified, the value of the ‘redirect_vid’ attribute of ListItemView (for ‘listview’) or of SimpleListView will be used. This default to ‘outofcontext’ for ‘list’ / ‘incontext’ for ‘simplelist’

Text entity views

Basic HTML view have some variants to be used when generating raw text, not HTML (for notifications for instance). Also, as explained above, some of the HTML views use those text views as a basis.

class cubicweb.web.views.baseviews.TextView(req=None, rset=None, **kwargs)[source]
__regid__:text

This is the simplest text view for an entity. By default it returns the result of the entity’s dc_title() method, which is cut to fit the navigation.short-line-size property if necessary.

class cubicweb.web.views.baseviews.InContextTextView(req=None, rset=None, **kwargs)[source]
__regid__:textincontext

Similar to the text view, but called when an entity is considered in context (see description of incontext HTML view for more information on this). By default it displays what’s returned by the dc_title() method of the entity.

class cubicweb.web.views.baseviews.OutOfContextView(req=None, rset=None, **kwargs)[source]
__regid__:outofcontext

This view is used when the entity should be considered as displayed out of its context. By default it produces the result of entity.dc_long_title() wrapped in a link leading to the primary view of the entity.

You will also find modules providing some specific services:

This module provides some generic components to navigate in the web application.

Previous / next navigation

An adapter and its related component for the somewhat usal “previous / next” navigation are provided.

class cubicweb.web.views.navigation.IPrevNextAdapter(_cw, **kwargs)[source]

Interface for entities which can be linked to a previous and/or next entity

next_entity()[source]

return the ‘next’ entity

previous_entity()[source]

return the ‘previous’ entity

class cubicweb.web.views.navigation.NextPrevNavigationComponent(*args, **kwargs)[source]

Entities adaptable to the ‘IPrevNext’ should have this component automatically displayed. You may want to override this component to have a different look and feel.

Table Of Contents

Previous topic

The “Click and Edit” (also reledit) View

Next topic

Startup views