68 |
68 |
69 The behaviour of reledited attributes/relations can be finely |
69 The behaviour of reledited attributes/relations can be finely |
70 controlled using the reledit_ctrl rtag, defined in |
70 controlled using the reledit_ctrl rtag, defined in |
71 :mod:`cubicweb.web.uicfg`. |
71 :mod:`cubicweb.web.uicfg`. |
72 |
72 |
73 This rtag provides three control variables: |
73 This rtag provides four control variables: |
74 |
74 |
75 * ``default_value`` |
75 * ``default_value``: alternative default value |
76 * ``reload``, to specificy if edition of the relation entails a full page |
76 The default value is what is shown when there is no value. |
77 reload, which defaults to False |
77 * ``reload``: boolean, eid (to reload to) or function taking subject |
78 * ``noedit``, to explicitly inhibit edition |
78 and returning bool/eid This is useful when editing a relation (or |
|
79 attribute) that impacts the url or another parts of the current |
|
80 displayed page. Defaults to false. |
|
81 * ``rvid``: alternative view id (as str) for relation or composite |
|
82 edition Default is 'incontext' or 'csv' depending on the |
|
83 cardinality. They can also be statically changed by subclassing |
|
84 ClickAndEditFormView and redefining _one_rvid (resp. _many_rvid). |
|
85 * ``edit_target``: 'rtype' (to edit the relation) or 'related' (to |
|
86 edit the related entity) This controls whether to edit the relation |
|
87 or the target entity of the relation. Currently only one-to-one |
|
88 relations support target entity edition. By default, the 'related' |
|
89 option is taken whenever the relation is composite and one-to-one. |
79 |
90 |
80 Let's see how to use these controls. |
91 Let's see how to use these controls. |
81 |
92 |
82 .. sourcecode:: python |
93 .. sourcecode:: python |
83 |
94 |
84 from logilab.mtconverter import xml_escape |
95 from logilab.mtconverter import xml_escape |
85 from cubicweb.web.uicfg import reledit_ctrl |
96 from cubicweb.web.uicfg import reledit_ctrl |
86 reledit_ctrl.tag_attribute(('Company', 'name'), |
97 reledit_ctrl.tag_attribute(('Company', 'name'), |
87 {'reload': lambda x:x.eid, |
98 {'reload': lambda x:x.eid, |
88 'default_value': xml_escape(u'<logilab tastes better>')}) |
99 'default_value': xml_escape(u'<logilab tastes better>')}) |
89 reledit_ctrl.tag_object_of(('*', 'boss', 'Person'), {'noedit': True}) |
100 reledit_ctrl.tag_object_of(('*', 'boss', 'Person'), {'edit_target': 'related'}) |
90 |
101 |
91 The `default_value` needs to be an xml escaped unicode string. |
102 The `default_value` needs to be an xml escaped unicode string. |
92 |
103 |
93 The `noedit` attribute is convenient to programmatically disable some |
104 The `edit_target` tag on the `boss` relation being set to `related` will |
94 relation edition on views that apply it systematically (the prime |
105 ensure edition of the `Person` entity instead (using a standard |
95 example being the primary view). Here we use it to forbid changing the |
106 automatic form) of the association of Company and Person. |
96 `boss` relation from a `Person` side (as it could have unwanted |
|
97 effects). |
|
98 |
107 |
99 Finally, the `reload` key accepts either a boolean, an eid or an |
108 Finally, the `reload` key accepts either a boolean, an eid or an |
100 unicode string representing an url. If an eid is provided, it will be |
109 unicode string representing an url. If an eid is provided, it will be |
101 internally transformed into an url. The eid/url case helps when one |
110 internally transformed into an url. The eid/url case helps when one |
102 needs to reload and the current url is inappropriate. A common case is |
111 needs to reload and the current url is inappropriate. A common case is |