doc/book/en/development/webstdlib/autoform.rst
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 08 Feb 2010 21:21:31 +0100
changeset 4507 57927ad07e63
parent 4256 bf6e0e75acfa
permissions -rw-r--r--
no need for a specific vid argument here
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     1
The automatic entity form (:mod:`cubicweb.web.views.autoform`)
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     2
---------------------------------------------------------------
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     3
4256
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
     4
Tags declaration
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
     5
~~~~~~~~~~~~~~~~~~~~
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
     6
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     7
It is possible to manage attributes/relations in the simple or multiple
4256
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
     8
editing form thanks of the methods bellow ::
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
     9
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    10
  uicfg.autoform_section.tag_subject_of(<relation>, tag)
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    11
  uicfg.autoform_section.tag_object_of(<relation>, tag)
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    12
  uicfg.autoform_field.tag_attribute(<attribut_def>, tag)
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    13
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    14
Where ``<relation>`` is a three elements tuple ``(Subject Entity Type,
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    15
relation_type, Object Entity Type)``. ``<attribut_def>`` is a two elements tuple
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    16
``(Entity Type, Attribut Name)``. Wildcard ``*`` could be used in place of
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    17
``Entity Type``
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    18
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    19
Possible tags are detailled below
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    20
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    21
Simple Tags
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    22
~~~~~~~~~~~~~~~~~~~~
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    23
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    24
* `primary`, indicates that an attribute or a relation has to be
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    25
  inserted **in the simple or multiple editing forms**. In the case of
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    26
  a relation, the related entity editing form will be included in the
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    27
  editing form and represented as a combobox. Each item of the
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    28
  combobox is a link to an existing entity.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    29
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    30
* `secondary`, indicates that an attribute or a relation has to be
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    31
  inserted **in the simple editing form only**. In the case of a
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    32
  relation, the related entity editing form will be included in the
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    33
  editing form and represented as a combobox. Each item of the combobox
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    34
  is a link to an existing entity.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    35
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    36
* `inlineview`, includes the target entity's form in the editing form
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    37
  of the current entity. It allows to create the target entity in the
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    38
  same time as the current entity.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    39
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    40
* `generic`, indicates that a relation has to be inserted in the simple
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    41
  editing form, in the generic box of relation creation.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    42
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    43
* `generated`, indicates that an attribute is dynamically computed
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    44
  or other,  and that it should not be displayed in the editing form.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    45
2172
cf8f9180e63e delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1714
diff changeset
    46
If necessary, it is possible to overwrite the method
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    47
`relation_category(rtype, x='subject')` to dynamically compute
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    48
a relation editing category.
4256
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    49
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    50
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    51
Advanced Tags
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    52
~~~~~~~~~~~~~~~~~~~~
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    53
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    54
Tag can also reference a custom Field crafted with the help of
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    55
``cubicweb.web.formfields`` and ``cubicweb.web.formwidget``. In the example
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    56
bellow, the field ``path`` of ``ExecData`` entities will be done with a standard
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    57
file input dialogue ::
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    58
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    59
  from cubicweb.web import uicfg, formfields, formwidgets
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    60
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    61
  uicfg.autoform_field.tag_attribute(('Execdata', 'path'),
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    62
      formfields.FileField(name='path', widget=formwidgets.FileInput()))
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    63
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    64
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    65
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    66
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    67
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    68
bf6e0e75acfa import uicfg.auto_form doc
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 2172
diff changeset
    69