doc/book/devweb/edition/editcontroller.rst
author Julien Cristau <julien.cristau@logilab.fr>
Fri, 05 Feb 2016 16:32:20 +0100
changeset 11095 02e88ca3bc23
parent 10491 c67bcee93248
permissions -rw-r--r--
[dataimport/test] fix test failures since 35b29f1eb37a The index name changed, so we need to follow suit.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     1
.. _edit_controller:
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     2
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     3
The `edit controller`
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
     4
---------------------
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     5
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
     6
It can be found in (:mod:`cubicweb.web.views.editcontroller`). This
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
     7
controller processes data received from an html form to create or
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
     8
update entities.
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
     9
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    10
Edition handling
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    11
~~~~~~~~~~~~~~~~
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    12
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    13
The parameters related to entities to edit are specified as follows
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    14
(first seen in :ref:`attributes_section`)::
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    15
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    16
  <rtype-role>:<entity eid>
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    17
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    18
where entity eid could be a letter in case of an entity to create. We
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    19
name those parameters as *qualified*.
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    20
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    21
* Retrieval of entities to edit is done by using the forms parameters
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    22
  `eid` and `__type`
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    23
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    24
* For all the attributes and the relations of an entity to edit
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    25
  (attributes and relations are handled a bit differently but these
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    26
  details are not much relevant here) :
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    27
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    28
   * using the ``rtype``, ``role`` and ``__type`` information, fetch
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    29
     an appropriate field instance
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    30
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    31
   * check if the field has been modified (if not, proceed to the next
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    32
     relation)
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    33
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    34
   * build an rql expression to update the entity
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    35
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    36
At the end, all rql expressions are executed.
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    37
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    38
* For each entity to edit:
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    39
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    40
   * if a qualified parameter `__linkto` is specified, its value has
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    41
     to be a string (or a list of strings) such as: ::
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    42
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    43
        <relation type>:<eids>:<target>
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    44
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    45
     where <target> is either `subject` or `object` and each eid could
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    46
     be separated from the others by a `_`. Target specifies if the
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    47
     *edited entity* is subject or object of the relation and each
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    48
     relation specified will be inserted.
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    49
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    50
    * if a qualified parameter `__clone_eid` is specified for an entity, the
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    51
      relations of the specified entity passed as value of this parameter are
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    52
      copied on the edited entity.
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    53
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    54
    * if a qualified parameter `__delete` is specified, its value must be
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    55
      a string or a list of string such as follows: ::
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    56
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    57
          <subjects eids>:<relation type>:<objects eids>
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    58
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    59
      where each eid subject or object can be seperated from the other
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    60
      by `_`. Each specified relation will be deleted.
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    61
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    62
5475
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    63
* If no entity is edited but the form contains the parameters `__linkto`
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    64
  and `eid`, this one is interpreted by using the value specified for `eid`
b44bad36e609 [doc/book] refresh a bit the edit controller section
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5459
diff changeset
    65
  to designate the entity on which to add the relations.
5459
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    66
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    67
.. note::
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    68
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    69
   * if the parameter `__action_delete` is found, all the entities specified
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    70
     as to be edited will be deleted.
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    71
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    72
   * if the parameter `__action_cancel` is found, no action is completed.
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    73
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    74
   * if the parameter `__action_apply` is found, the editing is
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    75
     applied normally but the redirection is done on the form (see
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    76
     :ref:`RedirectionControl`).
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    77
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    78
   * if no entity is found to be edited and if there is no parameter
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    79
     `__action_delete`, `__action_cancel`, `__linkto`, `__delete` or
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    80
     `__insert`, an error is raised.
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    81
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    82
   * using the parameter `__message` in the form will allow to use its value
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    83
     as a message to provide the user once the editing is completed.
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    84
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    85
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    86
.. _RedirectionControl:
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    87
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    88
Redirection control
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    89
~~~~~~~~~~~~~~~~~~~
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    90
Once editing is completed, there is still an issue left: where should we go
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    91
now? If nothing is specified, the controller will do his job but it does not
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    92
mean we will be happy with the result. We can control that by using the
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    93
following parameters:
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    94
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    95
* `__redirectpath`: path of the URL (relative to the root URL of the site,
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    96
  no form parameters
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    97
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    98
* `__redirectparams`: forms parameters to add to the path
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
    99
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   100
* `__redirectrql`: redirection RQL request
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   101
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   102
* `__redirectvid`: redirection view identifier
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   103
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   104
* `__errorurl`: initial form URL, used for redirecting in case a validation
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   105
  error is raised during editing. If this one is not specified, an error page
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   106
  is displayed instead of going back to the form (which is, if necessary,
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   107
  responsible for displaying the errors)
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   108
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   109
* `__form_id`: initial view form identifier, used if `__action_apply` is
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   110
  found
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   111
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   112
In general we use either `__redirectpath` and `__redirectparams` or
6e561796804c [doc/book] regroup form/editcontroller stuff under an "edition control" chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
diff changeset
   113
`__redirectrql` and `__redirectvid`.