.. _topics-views: ===== Views ===== The views are used to display records of an :class:`ModelView ` to the user. In Tryton, :class:`ModelView ` can have several views. An ``action`` opens a window and defines which view to show. The views are built from XML that is stored in the :file:`view` directory of the module or in the databases thanks to the model ir.ui.view. So generally, they are defined in XML files with this kind of XML where name is the name of the XML file in the :file:`view` directory: .. highlight:: xml :: model name type name view_name There are different types of views: .. contents:: :local: :backlinks: entry :depth: 2 Some attributes are shared by many form elements: .. _common-attributes-id: ``id`` A unique identifier for the tag if there is no name attribute. .. _common-attributes-yexpand: ``yexpand`` A boolean to specify if the label should expand to take up any extra vertical space. .. _common-attributes-yfill: ``yfill`` A boolean to specify if the label should fill the vertical space allocated to it in the table cell. .. _common-attributes-yalign: ``yalign`` The vertical alignment, from 0.0 to 1.0. .. _common-attributes-xexpand: ``xexpand`` The same as ``yexpand`` but for horizontal space. .. _common-attributes-xfill: ``xfill`` The same as ``yfill`` but for horizontal space. .. _common-attributes-xalign: ``xalign`` The horizontal alignment, from ``0.0`` to ``1.0``. .. _common-attributes-colspan: ``colspan`` The number of columns the widget must take in the table. .. _common-attributes-col: ``col`` The number of columns the container must have. A negative value (or zero) remove the constraint on the number of columns. The default value is ``4``. .. _common-attributes-states: ``states`` A string of :ref:`PYSON statement ` that is evaluated with the values of the current record. It must return a dictionary where keys can be: ``invisible`` If true, the widget is hidden. ``required`` If true, the field is required. ``readonly`` If true, the field is readonly. ``icon`` Only for button, it must return the icon name to use or False. ``pre_validate`` Only for button, it contains a domain to apply on the record before calling the button. ``depends`` Only for button, it must return the list of field on which the button depends. .. _common-attributes-help: ``help`` The string that is displayed when the cursor hovers over the widget. .. _common-attributes-pre_validate: ``pre_validate`` A boolean only for fields :class:`trytond.model.fields.One2Many` to specify if the client must pre-validate the records using :meth:`trytond.model.Model.pre_validate`. .. _common-attributes-completion: ``completion`` A boolean only for fields :class:`trytond.model.fields.Many2One`, :class:`trytond.model.fields.Many2Many` and :class:`trytond.model.fields.One2Many` to specify if the client must auto-complete the field. The default value is ``True``. .. _common-attributes-create: ``create`` A boolean to specify if the user can create targets from the widget. The default value is ``True``. ``delete`` A boolean to specify if the user can delete targets from the widget. The default value is ``True``. .. _common-attributes-factor: ``factor`` A factor to apply on fields :class:`trytond.model.fields.Integer`, :class:`trytond.model.fields.Float` and :class:`trytond.model.fields.Numeric` to display on the widget. The default value is ``1``. .. _common-attributes-symbol: ``symbol`` Only on numerical fields, the name of field which provides the symbol to display. .. _common-attributes-grouping: ``grouping`` A boolean only on numerical fields to specify if the client must use grouping separators to display on the widget. The default value is ``True``. .. _common-attributes-help_field: ``help_field`` The name of Dict field mapping the Selection value with its help string. Form ==== A form view is used to display one record. Elements of the view are put on the screen following the rules: * Elements are placed on the screen from left to right, from top to bottom, according to the order of the XML. * The screen composed of a table with a fixed number of columns and enough rows to handle all elements. * Elements take one or more columns when they are put in the table. If there are not enough free columns on the current row, the elements are put at the beginning of the next row. .. _example_form_view: Example: .. highlight:: xml ::