new fieldset attribute on field, use to group fields by the default form renderer
--- a/web/formfields.py Mon Jul 27 18:40:29 2009 +0200
+++ b/web/formfields.py Mon Jul 27 18:41:29 2009 +0200
@@ -63,6 +63,8 @@
:role:
when the field is linked to an entity attribute or relation, tells the
role of the entity in the relation (eg 'subject' or 'object')
+ :fieldset:
+ optional fieldset to which this field belongs to
"""
# default widget associated to this class of fields. May be overriden per
@@ -76,7 +78,7 @@
def __init__(self, name=None, id=None, label=None, help=None,
widget=None, required=False, initial=None,
choices=None, sort=True, internationalizable=False,
- eidparam=False, role='subject'):
+ eidparam=False, role='subject', fieldset=None):
self.name = name
self.id = id or name
self.label = label or name
@@ -88,6 +90,7 @@
self.internationalizable = internationalizable
self.eidparam = eidparam
self.role = role
+ self.fieldset = fieldset
self.init_widget(widget)
# ordering number for this field instance
self.creation_rank = Field.__creation_rank
--- a/web/views/formrenderers.py Mon Jul 27 18:40:29 2009 +0200
+++ b/web/views/formrenderers.py Mon Jul 27 18:41:29 2009 +0200
@@ -188,22 +188,29 @@
return fields
def _render_fields(self, fields, w, form):
- w(u'<table class="%s">' % self.table_class)
+ byfieldset = {}
for field in fields:
- w(u'<tr>')
- if self.display_label:
- w(u'<th class="labelCol">%s</th>' % self.render_label(form, field))
- error = form.form_field_error(field)
- if error:
- w(u'<td class="error">')
- w(error)
- else:
- w(u'<td>')
- w(field.render(form, self))
- if self.display_help:
- w(self.render_help(form, field))
- w(u'</td></tr>')
- w(u'</table>')
+ byfieldset.setdefault(field.fieldset, []).append(field)
+ for fieldset, fields in byfieldset.iteritems():
+ w(u'<fieldset class="%s">' % (fieldset or u'default'))
+ if fieldset:
+ w(u'<legend>%s</legend>' % self.req._(fieldset))
+ w(u'<table class="%s">' % self.table_class)
+ for field in fields:
+ w(u'<tr id="%s_%s">' % (field.name, field.role))
+ if self.display_label:
+ w(u'<th class="labelCol">%s</th>' % self.render_label(form, field))
+ error = form.form_field_error(field)
+ if error:
+ w(u'<td class="error">')
+ w(error)
+ else:
+ w(u'<td>')
+ w(field.render(form, self))
+ if self.display_help:
+ w(self.render_help(form, field))
+ w(u'</td></tr>')
+ w(u'</table></fieldset>')
def render_buttons(self, w, form):
if not form.form_buttons: