update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 02 Dec 2009 14:37:19 +0100
branchstable
changeset 3970 e4ad7663610b
parent 3969 970a748684b5
child 3971 7cfbc35dce7e
update _render_attribute / _render_relation prototype to gain more control on label through uicfg (for attributes and relations). Keep bw compat for crm/iliane
web/views/primary.py
--- a/web/views/primary.py	Wed Dec 02 14:35:23 2009 +0100
+++ b/web/views/primary.py	Wed Dec 02 14:37:19 2009 +0100
@@ -122,15 +122,26 @@
                     value = None
             if self.skip_none and (value is None or value == ''):
                 continue
-            self._render_attribute(rschema, value, role=role, table=True)
+            try:
+                self._render_attribute(dispctrl, rschema, value,
+                                       role=role, table=True)
+            except TypeError:
+                warn('[3.6] _render_attribute prototype has changed, '
+                     'please update %s' % self.__class___, DeprecationWarning)
+                self._render_attribute(rschema, value, role=role, table=True)
         self.w(u'</table>')
 
     def render_entity_relations(self, entity, siderelations=None):
         for rschema, tschemas, role, dispctrl in self._section_def(entity, 'relations'):
             rset = self._relation_rset(entity, rschema, role, dispctrl)
             if rset:
-                self._render_relation(rset, dispctrl, 'autolimited',
-                                      self.show_rel_label)
+                try:
+                    self._render_relation(dispctrl, rset, 'autolimited')
+                except TypeError:
+                    warn('[3.6] _render_relation prototype has changed, '
+                         'please update %s' % self.__class___, DeprecationWarning)
+                    self._render_relation(rset, dispctrl, 'autolimited',
+                                          self.show_rel_label)
 
     def render_side_boxes(self, boxes):
         """display side related relations:
@@ -192,21 +203,25 @@
             rset = dispctrl['filter'](rset)
         return rset
 
-    def _render_relation(self, rset, dispctrl, defaultvid, showlabel):
+    def _render_relation(self, dispctrl, rset, defaultvid, showlabel):
         self.w(u'<div class="section">')
-        if showlabel:
+        if dispctrl.get('showlabel', self.show_rel_label):
             self.w(u'<h4>%s</h4>' % self.req._(dispctrl['label']))
         self.wview(dispctrl.get('vid', defaultvid), rset,
                    initargs={'dispctrl': dispctrl})
         self.w(u'</div>')
 
-    def _render_attribute(self, rschema, value, role='subject', table=False):
+    def _render_attribute(self, dispctrl, rschema, value,
+                          role='subject', table=False):
         if rschema.final:
-            show_label = self.show_attr_label
+            showlabel = dispctrl.get('showlabel', self.show_attr_label)
         else:
-            show_label = self.show_rel_label
-        label = display_name(self.req, rschema.type, role)
-        self.field(label, value, show_label=show_label, tr=False, table=table)
+            showlabel = dispctrl.get('showlabel', self.show_rel_label)
+        if dispctrl.get('label'):
+            label = self.req._(dispctrl.get('label'))
+        else:
+            label = display_name(self.req, rschema.type, role)
+        self.field(label, value, show_label=showlabel, tr=False, table=table)
 
 
 class RelatedView(EntityView):