[reledit] new rtag entry to control apparition of relation label in default value stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 17 Sep 2010 16:54:56 +0200
branchstable
changeset 6282 556b1b1a2c5a
parent 6281 a013a68fe8ec
child 6283 c827fa795a6b
[reledit] new rtag entry to control apparition of relation label in default value
web/uicfg.py
web/views/reledit.py
--- a/web/uicfg.py	Fri Sep 17 16:53:12 2010 +0200
+++ b/web/uicfg.py	Fri Sep 17 16:54:56 2010 +0200
@@ -42,8 +42,6 @@
    # Adds all subjects of the entry_of relation in the add menu of the ``Blog``
    # primary view
    uicfg.actionbox_appearsin_addmenu.tag_object_of(('*', 'entry_of', 'Blog'), True)
-
-
 """
 __docformat__ = "restructuredtext en"
 
@@ -375,22 +373,35 @@
 autoform_permissions_overrides = RelationTagsSet('autoform_permissions_overrides')
 
 class ReleditTags(NoTargetRelationTagsDict):
+    """Associate to relation a dictionnary to control `reledit` (e.g. edition of
+    attributes / relations from within views).
+
+    Possible keys and associated values are:
+
+    * `default_value`, alternative default value (shown when there is no value).
+
+    * `default_showlabel`, when `default_value` is not specified, this boolean
+      flag control wether the generated default value should contains the
+      relation label or not. Will be the opposite of the `showlabel` value found
+      in the `primaryview_display_ctrl` rtag by default.
+
+    * `reload`, boolean, eid (to reload to) or function taking subject and
+      returning bool/eid. This is useful when editing a relation (or attribute)
+      that impacts the url or another parts of the current displayed
+      page. Defaults to False.
+
+    * `rvid`, alternative view id (as str) for relation or composite edition.
+      Default is 'incontext' or 'csv' depending on the cardinality. They can
+      also be statically changed by subclassing :class:`ClickAndEditFormView`
+      and redefining `_one_rvid` (resp. `_many_rvid`).
+
+    * `edit_target`, may be either 'rtype' (to edit the relation) or 'related'
+      (to edit the related entity).  This controls whether to edit the relation
+      or the target entity of the relation.  Currently only one-to-one relations
+      support target entity edition. By default, the 'related' option is taken
+      whenever the relation is composite and one-to-one.
     """
-    default_value: alternative default value
-      The default value is what is shown when there is no value.
-    reload: boolean, eid (to reload to) or function taking subject and returning bool/eid
-      This is useful when editing a relation (or attribute) that impacts the url
-      or another parts of the current displayed page. Defaults to False.
-    rvid: alternative view id (as str) for relation or composite edition
-      Default is 'incontext' or 'csv' depending on the cardinality. They can also be
-      statically changed by subclassing ClickAndEditFormView and redefining _one_rvid
-      (resp. _many_rvid).
-    edit_target: 'rtype' (to edit the relation) or 'related' (to edit the related entity)
-      This controls whether to edit the relation or the target entity of the relation.
-      Currently only one-to-one relations support target entity edition. By default,
-      the 'related' option is taken whenever the relation is composite and one-to-one.
-    """
-    _keys = frozenset('default_value reload rvid edit_target'.split())
+    _keys = frozenset('default_value default_showlabel reload rvid edit_target'.split())
 
     def tag_relation(self, key, tag):
         for tagkey in tag.iterkeys():
@@ -415,6 +426,11 @@
         edittarget = 'related' if composite else 'rtype'
         rtag.tag_relation((sschema, rschema, oschema, role),
                           {'edit_target': edittarget})
+    if not 'default_showlabel' in values:
+        showlabel = primaryview_display_ctrl.get(
+            sschema, rschema, oschema, role).get('showlabel', True)
+        rtag.tag_relation((sschema, rschema, oschema, role),
+                          {'default_showlabel': not showlabel})
 
 reledit_ctrl = ReleditTags('reledit', init_reledit_ctrl)
 
--- a/web/views/reledit.py	Fri Sep 17 16:53:12 2010 +0200
+++ b/web/views/reledit.py	Fri Sep 17 16:54:56 2010 +0200
@@ -177,8 +177,10 @@
         if ctrl_default:
             return ctrl_default
         if default_value is None:
-            return xml_escape(self._cw._('<%s not specified>') %
-                              display_name(self._cw, rschema.type, role))
+            if self._rules.get('default_showlabel'):
+                return xml_escape(self._cw._('<%s not specified>') %
+                                  display_name(self._cw, rschema.type, role))
+            return xml_escape(self._cw._('<not specified>'))
         return default_value
 
     def _is_composite(self):
@@ -247,11 +249,10 @@
         return display_label, related_entity
 
     def _prepare_composite_form(self, entity, rtype, role, edit_related, add_related):
+        display_label = True
         if edit_related and not add_related:
-            display_label = True
             related_entity = entity.related(rtype, role).get_entity(0, 0)
         elif add_related:
-            display_label = True
             _new_entity = self._cw.vreg['etypes'].etype_class(add_related)(self._cw)
             _new_entity.eid = self._cw.varmaker.next()
             related_entity = _new_entity