Common Structure
View objects expose a number of fields, they are optional unless specified otherwise.
name(mandatory)- only useful as a mnemonic/description of the view when looking for one in a list of some sort
model- the model linked to the view, if applicable (it doesn't for QWeb views)
priority- client programs can request views by
id, or by(model, type). For the latter, all the views for the right type and model will be searched, and the one with the lowestprioritynumber will be returned (it is the "default view").priorityalso defines the order of application during view inheritance. arch- the description of the view's layout
groups_idMany2manyfield to the groups allowed to view/use the current viewinherit_id- the current view's parent view, see Inheritance, unset by default
mode- inheritance mode, see Inheritance. If
inherit_idis unset themodecan only beprimary. Ifinherit_idis set,extensionby default but can be explicitly set toprimary application- website feature defining togglable views. By default, views are always applied
Inheritance
View matching
- if a view is requested by
(model, type), the view with the right model and type,mode=primaryand the lowest priority is matched - when a view is requested by
id, if its mode is notprimaryits closest parent with modeprimaryis matched
View resolution
Resolution generates the final
arch for a requested/matched primary view:- if the view has a parent, the parent is fully resolved then the current view's inheritance specs are applied
- if the view has no parent, its
archis used as-is - the current view's children with mode
extensionare looked up and their inheritance specs are applied depth-first (a child view is applied, then its children, then its siblings)
The result of applying children views yields the final
archInheritance specs
There are three types of inheritance specs:
- An
xpathelement with anexprattribute.expris an XPath expression2 applied to the currentarch, the first node it finds is the match - a
fieldelement with anameattribute, matches the firstfieldwith the samename - any other element, the first element with the same name and identical attributes (ignoring
position) is matched
The inheritance spec may have an optional
position attribute specifying how the matched node should be altered:inside(default)- the content of the inheritance spec is appended to the matched node
replace- the content of the inheritance spec replaces the matched node
after- the content of the inheritance spec is added to the matched node's parent, after the matched node
before- the content of the inheritance spec is added to the matched node's parent, before the matched node
attributes- the content of the inheritance spec should be
attributeelements with anameattribute and an optional body:- if the
attributeelement has a body, a new attributed named after itsnameis created on the matched node with theattributeelement's text as value - if the
attributeelement has no body, the attribute named after itsnameis removed from the matched node. If no such attribute exists, an error is raised
- if the
A view's specs are applied sequentially.
Lists
The root element of list views is
<tree>3. The list view's root can have the following attributes:editable- by default, selecting a list view's row opens the corresponding form view The
editableattributes makes the list view itself editable in-place.Valid values aretopandbottom, making new records appear respectively at the top or bottom of the list.The architecture for the inline form view is derived from the list view. Most attributes valid on a form view's fields and buttons are thus accepted by list views although they may not have any meaning if the list view is non-editable default_order- overrides the ordering of the view, replacing the model's default order. The value is a comma-separated list of fields, postfixed by
descto sort in reverse order:<tree default_order="sequence,name desc">
colors- allows changing the color of a row's text based on the corresponding record's attributes.Defined as a mapping of colors to Python expressions. Values are of the form:
color:expr[;...]. For each record, pairs are tested in order, the expression is evaluated for the record and iftruethe corresponding color is applied to the row. If no color matches, uses the default text color (black).colorcan be any valid CSS color unit.exprshould be a Python expression evaluated with the current record's attributes as context values. Other context values areuid(the id of the current user) andcurrent_date(the current date as a string of the formyyyy-MM-dd)
fonts- allows changing a row's font style based on the corresponding record's attributes.The format is the same as for
color, but thecolorof each pair is replaced bybold,italicorunderline, the expression evaluating totruewill apply the corresponding style to the row's text. Contrary tocolors, multiple pairs can match each record create,edit,delete- allows disabling the corresponding action in the view by setting the corresponding attribute to
false on_write- only makes sense on an
editablelist. Should be the name of a method on the list's model. The method will be called with theidof a record after having created or edited that record (in database).The method should return a list of ids of other records to load or update.
Possible children elements of the list view are:
No comments:
Post a Comment