Add default normalize logic for API views
and use common logic for getting field list in traditional Form class
This commit is contained in:
parent
960d6279a9
commit
35728e20be
3 changed files with 25 additions and 22 deletions
|
@ -37,6 +37,7 @@ from sqlalchemy.ext.associationproxy import AssociationProxy, ASSOCIATION_PROXY
|
|||
from rattail.time import localtime
|
||||
from rattail.util import prettify, pretty_boolean, pretty_quantity
|
||||
from rattail.core import UNSPECIFIED
|
||||
from rattail.db.util import get_fieldnames
|
||||
|
||||
import colander
|
||||
import deform
|
||||
|
@ -396,19 +397,8 @@ class Form(object):
|
|||
if not self.model_class:
|
||||
raise ValueError("Must define model_class to use make_fields()")
|
||||
|
||||
mapper = orm.class_mapper(self.model_class)
|
||||
|
||||
# first add primary column fields
|
||||
fields = FieldList([prop.key for prop in mapper.iterate_properties
|
||||
if not prop.key.startswith('_')
|
||||
and prop.key != 'versions'])
|
||||
|
||||
# then add association proxy fields
|
||||
for key, desc in sa.inspect(self.model_class).all_orm_descriptors.items():
|
||||
if desc.extension_type == ASSOCIATION_PROXY:
|
||||
fields.append(key)
|
||||
|
||||
return fields
|
||||
return get_fieldnames(self.request.rattail_config, self.model_class,
|
||||
columns=True, proxies=True, relations=True)
|
||||
|
||||
def make_renderers(self):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue