1 .. -*- coding: utf-8 -*- |
|
2 |
|
3 The 'edit' controller (:mod:`cubicweb.web.views.editcontroller`) |
|
4 ---------------------------------------------------------------- |
|
5 |
|
6 Editing control |
|
7 ~~~~~~~~~~~~~~~~ |
|
8 |
|
9 Re-requisites: the parameters related to entities to edit are |
|
10 specified as follows :: |
|
11 |
|
12 <field name>:<entity eid> |
|
13 |
|
14 where entity eid could be a letter in case of an entity to create. We |
|
15 name those parameters as *qualified*. |
|
16 |
|
17 1. Retrieval of entities to edit by looking for the forms parameters |
|
18 starting by `eid:` and also having a parameter `__type` associated |
|
19 (also *qualified* by eid) |
|
20 |
|
21 2. For all the attributes and the relations of an entity to edit: |
|
22 |
|
23 1. search for a parameter `edits-<relation name>` or `edito-<relation name>` |
|
24 qualified in the case of a relation where the entity is object |
|
25 2. if found, the value returned is considered as the initial value |
|
26 for this relaiton and we then look for the new value(s) in the parameter |
|
27 <relation name> (qualified) |
|
28 3. if the value returned is different from the initial value, an database update |
|
29 request is done |
|
30 |
|
31 3. For each entity to edit: |
|
32 |
|
33 1. if a qualified parameter `__linkto` is specified, its value has to be |
|
34 a string (or a list of string) such as: :: |
|
35 |
|
36 <relation type>:<eids>:<target> |
|
37 |
|
38 where <target> is either `subject` or `object` and each eid could be |
|
39 separated from the others by a `_`. Target specifies if the *edited entity* |
|
40 is subject or object of the relation and each relation specified will |
|
41 be inserted. |
|
42 |
|
43 2. if a qualified parameter `__clone_eid` is specified for an entity, the |
|
44 relations of the specified entity passed as value of this parameter are |
|
45 copied on the edited entity. |
|
46 |
|
47 3. if a qualified parameter `__delete` is specified, its value must be |
|
48 a string or a list of string such as follows: :: |
|
49 |
|
50 <ssubjects eids>:<relation type>:<objects eids> |
|
51 |
|
52 where each eid subject or object can be seperated from the other |
|
53 by `_`. Each relation specified will be deleted. |
|
54 |
|
55 4. if a qualified parameter `__insert` is specified, its value should |
|
56 follow the same pattern as `__delete`, but each relation specified is |
|
57 inserted. |
|
58 |
|
59 4. If the parameters `__insert` and/or `__delete` are found not qualified, |
|
60 they are interpreted as explained above (independantly from the number |
|
61 of entities edited). |
|
62 |
|
63 5. If no entity is edited but the form contains the parameters `__linkto` |
|
64 and `eid`, this one is interpreted by using the value specified for `eid` |
|
65 to designate the entity on which to add the relations. |
|
66 |
|
67 |
|
68 .. note:: |
|
69 |
|
70 * If the parameter `__action_delete` is found, all the entities specified |
|
71 as to be edited will be deleted. |
|
72 |
|
73 * If the parameter`__action_cancel` is found, no action is completed. |
|
74 |
|
75 * If the parameter `__action_apply` is found, the editing is applied |
|
76 normally but the redirection is done on the form |
|
77 (see :ref:`RedirectionControl`). |
|
78 |
|
79 * The parameter `__method` is also supported as for the main template |
|
80 (XXX not very consistent, maybe __method should be dealed in the view |
|
81 controller). |
|
82 |
|
83 * If no entity is found to be edited and if there is no parameter |
|
84 `__action_delete`, `__action_cancel`, `__linkto`, `__delete` or |
|
85 `__insert`, an error is raised. |
|
86 |
|
87 * Using the parameter `__message` in the form will allow to use its value |
|
88 as a message to provide the user once the editing is completed. |
|
89 |
|
90 |
|
91 .. _RedirectionControl: |
|
92 |
|
93 Redirection control |
|
94 ~~~~~~~~~~~~~~~~~~~ |
|
95 Once editing is completed, there is still an issue left: where should we go |
|
96 now? If nothing is specified, the controller will do his job but it does not |
|
97 mean we will be happy with the result. We can control that by using the |
|
98 following parameters: |
|
99 |
|
100 * `__redirectpath`: path of the URL (relative to the root URL of the site, |
|
101 no form parameters |
|
102 |
|
103 * `__redirectparams`: forms parameters to add to the path |
|
104 |
|
105 * `__redirectrql`: redirection RQL request |
|
106 |
|
107 * `__redirectvid`: redirection view identifier |
|
108 |
|
109 * `__errorurl`: initial form URL, used for redirecting in case a validation |
|
110 error is raised during editing. If this one is not specified, an error page |
|
111 is displayed instead of going back to the form (which is, if necessary, |
|
112 responsible for displaying the errors) |
|
113 |
|
114 * `__form_id`: initial view form identifier, used if `__action_apply` is |
|
115 found |
|
116 |
|
117 In general we use either `__redirectpath` and `__redirectparams` or |
|
118 `__redirectrql` and `__redirectvid`. |
|
119 |
|