Navigation

We’ll start with a description of the interface providing a basic
understanding of the available classes and methods, then detail the
view selection principle.

A View is an object responsible for the rendering of data from the
model into an end-user consummable form. They typically churn out an
XHTML stream, but there are views concerned with email other non-html
outputs.

This class is an abstraction of a view class, used as a base class for
every renderable object such as views, templates and other user interface
components.

A View is instantiated to render a result set or part of a result
set. View subclasses may be parametrized using the following class
attributes:

templatable indicates if the view may be embedded in a main

template or if it has to be rendered standalone (i.e. pure XML views must
not be embedded in the main template of HTML pages)

content_type if the view is not templatable, it should set the

content_type class attribute to the correct MIME type (text/xhtml being
the default)

category this attribute may be used in the interface to regroup

related objects (view kinds) together

paginable

binary

A view writes to its output stream thanks to its attribute w (the
append method of an UStreamIO, except for binary views).

At instantiation time, the standard _cw, and cw_rset attributes are
added and the w attribute will be set at rendering time to a write
function to use.

The basic interface for views is as follows (remember that the result
set has a tabular structure with rows and columns, hence cells):

render(**context), render the view by calling call or
cell_call depending on the context

call(**kwargs), call the view for a complete result set or null
(the default implementation calls cell_call() on each cell of the
result set)

cell_call(row, col, **kwargs), call the view for a given cell of a
result set (row and col being integers used to access the cell)

url(), returns the URL enabling us to get the view with the current
result set

wview(__vid, rset, __fallback_vid=None, **kwargs), call the view of
identifier __vid on the given result set. It is possible to give a
fallback view identifier that will be used if the requested view is
not applicable to the result set.

html_headers(), returns a list of HTML headers to be set by the
main template

classRSSView(XMLView):__regid__='rss'title=_('rss')templatable=Falsecontent_type='text/xml'http_cache_manager=MaxAgeHTTPCacheManagercache_max_age=60*60*2# stay in http cache for 2 hours by default

Using a custom selector

classSearchForAssociationView(EntityView):"""view called by the edition view when the user asks to search for something to link to the edited eid """__regid__='search-associate'title=_('search for association')__select__=one_line_rset()&match_search_state('linksearch')&is_instance('Any')

For views generating other formats than HTML (an image generated dynamically
for example), and which can not simply be included in the HTML page generated
by the main template (see above), you have to:

set the attribute templatable of the class to False

set, through the attribute content_type of the class, the MIME
type generated by the view to application/octet-stream or any
relevant and more specialised mime type

For views dedicated to binary content creation (like dynamically generated
images), we have to set the attribute binary of the class to True (which
implies that templatable == False, so that the attribute w of the view could be
replaced by a binary flow instead of unicode).