Add custom FieldList
class for forms2 field list
This commit is contained in:
parent
4c189f2fcc
commit
40d2251844
|
@ -259,7 +259,7 @@ class Form(object):
|
||||||
model_instance=None, model_class=None, nodes={}, enums={}, labels={}, renderers={},
|
model_instance=None, model_class=None, nodes={}, enums={}, labels={}, renderers={},
|
||||||
widgets={}, defaults={}, validators={}, required={}, action_url=None, cancel_url=None):
|
widgets={}, defaults={}, validators={}, required={}, action_url=None, cancel_url=None):
|
||||||
|
|
||||||
self.fields = list(fields) if fields is not None else None
|
self.fields = FieldList(fields) if fields is not None else None
|
||||||
self.schema = schema
|
self.schema = schema
|
||||||
self.request = request
|
self.request = request
|
||||||
self.readonly = readonly
|
self.readonly = readonly
|
||||||
|
@ -291,9 +291,9 @@ class Form(object):
|
||||||
mapper = orm.class_mapper(self.model_class)
|
mapper = orm.class_mapper(self.model_class)
|
||||||
|
|
||||||
# first add primary column fields
|
# first add primary column fields
|
||||||
fields = [prop.key for prop in mapper.iterate_properties
|
fields = FieldList([prop.key for prop in mapper.iterate_properties
|
||||||
if not prop.key.startswith('_')
|
if not prop.key.startswith('_')
|
||||||
and prop.key != 'versions']
|
and prop.key != 'versions'])
|
||||||
|
|
||||||
# then add association proxy fields
|
# then add association proxy fields
|
||||||
for key, desc in sa.inspect(self.model_class).all_orm_descriptors.items():
|
for key, desc in sa.inspect(self.model_class).all_orm_descriptors.items():
|
||||||
|
@ -574,3 +574,17 @@ class Form(object):
|
||||||
def validate(self, *args, **kwargs):
|
def validate(self, *args, **kwargs):
|
||||||
form = self.make_deform_form()
|
form = self.make_deform_form()
|
||||||
return form.validate(*args, **kwargs)
|
return form.validate(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
class FieldList(list):
|
||||||
|
"""
|
||||||
|
Convenience wrapper for a form's field list.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def insert_before(self, field, newfield):
|
||||||
|
i = self.index(field)
|
||||||
|
self.insert(i, newfield)
|
||||||
|
|
||||||
|
def insert_after(self, field, newfield):
|
||||||
|
i = self.index(field)
|
||||||
|
self.insert(i + 1, newfield)
|
||||||
|
|
Loading…
Reference in a new issue