move base form renderer label handling into a function to reuse it in CompositeFormRenderer and avoid seeing a tuple in column headers... stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 21 Jan 2010 11:07:32 +0100
branchstable
changeset 4313 5d8196a105a7
parent 4299 96d347c3247e
child 4314 e12ee4a009bc
child 4315 2f957ad8e082
move base form renderer label handling into a function to reuse it in CompositeFormRenderer and avoid seeing a tuple in column headers...
web/views/formrenderers.py
--- a/web/views/formrenderers.py	Wed Jan 20 17:07:48 2010 +0100
+++ b/web/views/formrenderers.py	Thu Jan 21 11:07:32 2010 +0100
@@ -20,6 +20,14 @@
 from cubicweb.web.widgets import checkbox
 from cubicweb.web.formfields import HiddenInitialValueField
 
+def field_label(form, field):
+    # XXX with 3.6 we can now properly rely on 'if field.role is not None' and
+    # stop having a tuple for label
+    if isinstance(field.label, tuple): # i.e. needs contextual translation
+        return form.req.pgettext(*field.label)
+    return form.req._(field.label)
+
+
 
 class FormRenderer(AppObject):
     """basic renderer displaying fields in a two columns table label | value
@@ -87,10 +95,7 @@
     def render_label(self, form, field):
         if field.label is None:
             return u''
-        if isinstance(field.label, tuple): # i.e. needs contextual translation
-            label = self.req.pgettext(*field.label)
-        else:
-            label = self.req._(field.label)
+        label = field_label(form, field)
         attrs = {'for': form.context[field]['id']}
         if field.required:
             attrs['class'] = 'required'
@@ -324,7 +329,7 @@
                              title=self.req._('toggle check boxes'),
                              onclick="setCheckboxesState('eid', this.checked)"))
                 for field in subfields:
-                    w(u'<th>%s</th>' % self.req._(field.label))
+                    w(u'<th>%s</th>' % field_label(form, field))
                 w(u'</tr>')
         super(EntityCompositeFormRenderer, self).render_fields(w, form, values)
         if form.parent_form is None: