Add /people API endpoint; allow for "native sort"
This commit is contained in:
parent
d671b18215
commit
fa700d53ad
|
@ -46,6 +46,7 @@ class CustomerView(APIMasterView):
|
||||||
'uuid': customer.uuid,
|
'uuid': customer.uuid,
|
||||||
'_str': six.text_type(customer),
|
'_str': six.text_type(customer),
|
||||||
'id': customer.id,
|
'id': customer.id,
|
||||||
|
'number': customer.number,
|
||||||
'name': customer.name,
|
'name': customer.name,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,6 +129,10 @@ class APIMasterView(APIView):
|
||||||
|
|
||||||
def make_sort_spec(self):
|
def make_sort_spec(self):
|
||||||
|
|
||||||
|
# we prefer a "native sort"
|
||||||
|
if self.request.GET.has_key('nativeSort'):
|
||||||
|
return json.loads(self.request.GET.getone('nativeSort'))
|
||||||
|
|
||||||
# these params are based on 'vuetable-2'
|
# these params are based on 'vuetable-2'
|
||||||
# https://www.vuetable.com/guide/sorting.html#initial-sorting-order
|
# https://www.vuetable.com/guide/sorting.html#initial-sorting-order
|
||||||
if 'sort' in self.request.params:
|
if 'sort' in self.request.params:
|
||||||
|
|
56
tailbone/api/people.py
Normal file
56
tailbone/api/people.py
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
# -*- coding: utf-8; -*-
|
||||||
|
################################################################################
|
||||||
|
#
|
||||||
|
# Rattail -- Retail Software Framework
|
||||||
|
# Copyright © 2010-2021 Lance Edgar
|
||||||
|
#
|
||||||
|
# This file is part of Rattail.
|
||||||
|
#
|
||||||
|
# Rattail is free software: you can redistribute it and/or modify it under the
|
||||||
|
# terms of the GNU General Public License as published by the Free Software
|
||||||
|
# Foundation, either version 3 of the License, or (at your option) any later
|
||||||
|
# version.
|
||||||
|
#
|
||||||
|
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
# details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with
|
||||||
|
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
"""
|
||||||
|
Tailbone Web API - Person Views
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
|
import six
|
||||||
|
|
||||||
|
from rattail.db import model
|
||||||
|
|
||||||
|
from tailbone.api import APIMasterView2 as APIMasterView
|
||||||
|
|
||||||
|
|
||||||
|
class PersonView(APIMasterView):
|
||||||
|
"""
|
||||||
|
API views for Person data
|
||||||
|
"""
|
||||||
|
model_class = model.Person
|
||||||
|
permission_prefix = 'people'
|
||||||
|
collection_url_prefix = '/people'
|
||||||
|
object_url_prefix = '/person'
|
||||||
|
|
||||||
|
def normalize(self, person):
|
||||||
|
return {
|
||||||
|
'uuid': person.uuid,
|
||||||
|
'_str': six.text_type(person),
|
||||||
|
'first_name': person.first_name,
|
||||||
|
'last_name': person.last_name,
|
||||||
|
'display_name': person.display_name,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def includeme(config):
|
||||||
|
PersonView.defaults(config)
|
Loading…
Reference in a new issue