# HG changeset patch # User Adrien Di Mascio # Date 1258545023 -3600 # Node ID 7d0d4a6be046453729c481faf306d45d80af8b55 # Parent 4d95109582c7a4ea4a3c692febfcdc4b1f18f48c [formfields] allow fields ordering with autoform_field_kwargs diff -r 4d95109582c7 -r 7d0d4a6be046 web/formfields.py --- a/web/formfields.py Wed Nov 18 12:32:57 2009 +0100 +++ b/web/formfields.py Wed Nov 18 12:50:23 2009 +0100 @@ -81,6 +81,8 @@ role of the entity in the relation (eg 'subject' or 'object') :fieldset: optional fieldset to which this field belongs to + :order: + key used by automatic forms to sort fields """ # default widget associated to this class of fields. May be overriden per @@ -94,7 +96,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', fieldset=None): + eidparam=False, role='subject', fieldset=None, order=None): self.name = name self.id = id or name self.label = label or name @@ -108,6 +110,7 @@ self.role = role self.fieldset = fieldset self.init_widget(widget) + self.order = order # ordering number for this field instance self.creation_rank = Field.__creation_rank Field.__creation_rank += 1 diff -r 4d95109582c7 -r 7d0d4a6be046 web/views/autoform.py --- a/web/views/autoform.py Wed Nov 18 12:32:57 2009 +0100 +++ b/web/views/autoform.py Wed Nov 18 12:50:23 2009 +0100 @@ -180,6 +180,8 @@ except form.FieldNotFound: # meta attribute such as _format continue + fnum = len(self.fields) + self.fields.sort(key=lambda f: f.order is None and fnum or f.order) self.maxrelitems = self.req.property_value('navigation.related-limit') self.force_display = bool(self.req.form.get('__force_display'))