doc/book/en/development/devweb/views/autoform.rst
branchstable
changeset 5368 d321e4b62a10
parent 5367 4176a50c81c9
child 5369 68c33344581c
equal deleted inserted replaced
5367:4176a50c81c9 5368:d321e4b62a10
     1 The automatic entity form
       
     2 -------------------------
       
     3 
       
     4 (:mod:`cubicweb.web.views.autoform`)
       
     5 
       
     6 Tags declaration
       
     7 ````````````````
       
     8 
       
     9 It is possible to manage attributes/relations in the simple or multiple
       
    10 editing form using proper uicfg tags.
       
    11 
       
    12 .. sourcecode:: python
       
    13 
       
    14   uicfg.autoform_section.tag_subject_of(<relation>, tag)
       
    15   uicfg.autoform_section.tag_object_of(<relation>, tag)
       
    16   uicfg.autoform_field.tag_attribute(<attribut_def>, tag)
       
    17 
       
    18 The details of the uicfg syntax can be found in the :ref:`uicfg`
       
    19 chapter.
       
    20 
       
    21 Possible tags are detailled below
       
    22 
       
    23 Automatic form configuration
       
    24 ````````````````````````````
       
    25 
       
    26 Attributes/relations display location
       
    27 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       
    28 
       
    29 ``uicfg.autoform_section`` specifies where to display a relation in
       
    30 creation/edition entity form for a given form type.  ``tag_attribute``,
       
    31 ``tag_subject_of`` and ``tag_object_of`` methods for this relation tag expect
       
    32 two arguments additionally to the relation key: a ``formtype`` and a
       
    33 ``section``.
       
    34 
       
    35 ``formtype`` may be one of:
       
    36 
       
    37 * ``main``, the main entity form (via the modify action)
       
    38 * ``inlined``, the form for an entity inlined into another form
       
    39 * ``muledit``, the table form to edit multiple entities
       
    40 
       
    41 section may be one of:
       
    42 
       
    43 * ``hidden``, don't display
       
    44 
       
    45 * ``attributes``, display in the attributes section
       
    46 
       
    47 * ``relations``, display in the relations section, using the generic relation
       
    48   selector combobox (available in main form only, and not for attribute
       
    49   relation)
       
    50 
       
    51 * ``inlined``, display target entity of the relation in an inlined form
       
    52   (available in main form only, and not for attribute relation)
       
    53 
       
    54 * ``metadata``, display in a special metadata form (NOT YET IMPLEMENTED, subject
       
    55   to changes)
       
    56 
       
    57 By default, mandatory relations are displayed in the ``attributes`` section,
       
    58 others in ``relations`` section.
       
    59 
       
    60 Change default fields
       
    61 ^^^^^^^^^^^^^^^^^^^^^
       
    62 
       
    63 Use ``autoform_field`` to replace the default field type of an attribute.
       
    64 
       
    65 .. warning::
       
    66 
       
    67    ``autoform_field_kwargs`` should usually be used instead of
       
    68    ``autoform_field``. Do not use both methods for the same relation!
       
    69 
       
    70 
       
    71 Customize field options
       
    72 ^^^^^^^^^^^^^^^^^^^^^^^
       
    73 
       
    74 In order to customize field options (see :class:`cubicweb.web.formfields.Field`
       
    75 for a detailed list of options), use ``autoform_field_kwargs``. This rtag takes
       
    76 a relation triplet and a dictionary as arguments.
       
    77 
       
    78 .. sourcecode:: python
       
    79 
       
    80    # Change the content of the combobox
       
    81    # here ``ticket_done_in_choices`` is a function which returns a list of
       
    82    # elements to populate the combobox
       
    83    uicfg.autoform_field_kwargs.tag_subject_of(('Ticket', 'done_in', '*'), {'sort': False,
       
    84                                                   'choices': ticket_done_in_choices})
       
    85 
       
    86 
       
    87 
       
    88 Overriding permissions
       
    89 ^^^^^^^^^^^^^^^^^^^^^^
       
    90 
       
    91 ``autoform_permissions_overrides`` provides a way to by-pass security checking
       
    92 for dark-corner case where it can't be verified properly. XXX documents.