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
|
@ -28,7 +28,10 @@ from __future__ import unicode_literals, absolute_import
|
|||
|
||||
import json
|
||||
|
||||
import six
|
||||
|
||||
from rattail.config import parse_bool
|
||||
from rattail.db.util import get_fieldnames
|
||||
|
||||
from cornice import resource, Service
|
||||
|
||||
|
@ -268,6 +271,21 @@ class APIMasterView(APIView):
|
|||
query = self.Session.query(cls)
|
||||
return query
|
||||
|
||||
def get_fieldnames(self):
|
||||
if not hasattr(self, '_fieldnames'):
|
||||
self._fieldnames = get_fieldnames(
|
||||
self.rattail_config, self.model_class,
|
||||
columns=True, proxies=True, relations=False)
|
||||
return self._fieldnames
|
||||
|
||||
def normalize(self, obj):
|
||||
data = {'_str': six.text_type(obj)}
|
||||
|
||||
for field in self.get_fieldnames():
|
||||
data[field] = getattr(obj, field)
|
||||
|
||||
return data
|
||||
|
||||
def _collection_get(self):
|
||||
from sqlalchemy_filters import apply_filters, apply_sort, apply_pagination
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue