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 lowestpriority
number will be returned (it is the "default view").priority
also defines the order of application during view inheritance. arch
- the description of the view's layout
groups_id
Many2many
field 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_id
is unset themode
can only beprimary
. Ifinherit_id
is set,extension
by 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=primary
and the lowest priority is matched - when a view is requested by
id
, if its mode is notprimary
its closest parent with modeprimary
is 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
arch
is used as-is - the current view's children with mode
extension
are 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
arch
Inheritance specs
There are three types of inheritance specs:
- An
xpath
element with anexpr
attribute.expr
is an XPath expression2 applied to the currentarch
, the first node it finds is the match - a
field
element with aname
attribute, matches the firstfield
with 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
attribute
elements with aname
attribute and an optional body:- if the
attribute
element has a body, a new attributed named after itsname
is created on the matched node with theattribute
element's text as value - if the
attribute
element has no body, the attribute named after itsname
is 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
editable
attributes makes the list view itself editable in-place.Valid values aretop
andbottom
, 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
desc
to 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 iftrue
the corresponding color is applied to the row. If no color matches, uses the default text color (black).color
can be any valid CSS color unit.expr
should 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 thecolor
of each pair is replaced bybold
,italic
orunderline
, the expression evaluating totrue
will 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
editable
list. Should be the name of a method on the list's model. The method will be called with theid
of 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