[form renderer] fix composite form renderer in case the main form has some visible fields
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 30 Jul 2009 18:51:44 +0200
changeset 2575 e033939d5664
parent 2574 37154aa90947
child 2576 4ed80b85a22a
[form renderer] fix composite form renderer in case the main form has some visible fields
web/views/formrenderers.py
--- a/web/views/formrenderers.py	Thu Jul 30 18:50:41 2009 +0200
+++ b/web/views/formrenderers.py	Thu Jul 30 18:51:44 2009 +0200
@@ -306,12 +306,17 @@
     """specific renderer for multiple entities edition form (muledit)"""
     id = 'composite'
 
+    _main_display_fields = None
+
     def render_fields(self, w, form, values):
         if not form.is_subform:
             w(u'<table class="listing">')
         super(EntityCompositeFormRenderer, self).render_fields(w, form, values)
         if not form.is_subform:
             w(u'</table>')
+            if self._main_display_fields:
+                super(EntityCompositeFormRenderer, self)._render_fields(
+                    self._main_display_fields, w, form)
 
     def _render_fields(self, fields, w, form):
         if form.is_subform:
@@ -334,17 +339,22 @@
                 elif isinstance(field.widget, fwdgs.Input):
                     field.widget.attrs['onkeypress'] = cbsetstate
                 w(u'<div>%s</div>' % field.render(form, self))
-                w(u'</td>')
+                w(u'</td></tr>')
         else:
-            # main form, display table headers
-            w(u'<tr class="header">')
-            w(u'<th align="left">%s</th>'
-              % tags.input(type='checkbox', title=self.req._('toggle check boxes'),
-                           onclick="setCheckboxesState('eid', this.checked)"))
-            for field in self.forms[0].fields:
-                if self.display_field(form, field) and field.is_visible():
+            self._main_display_fields = fields
+            subfields = [field for field in form.forms[0].fields
+                         if self.display_field(form, field)
+                         and field.is_visible()]
+            if subfields:
+                # main form, display table headers
+                w(u'<tr class="header">')
+                w(u'<th align="left">%s</th>' %
+                  tags.input(type='checkbox',
+                             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'</tr>')
+                w(u'</tr>')
 
 
 class EntityFormRenderer(EntityBaseFormRenderer):