diff --git a/tailbone/api/customers.py b/tailbone/api/customers.py index ddca770c..2e0a9d4c 100644 --- a/tailbone/api/customers.py +++ b/tailbone/api/customers.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2019 Lance Edgar +# Copyright © 2010-2020 Lance Edgar # # This file is part of Rattail. # @@ -30,15 +30,16 @@ import six from rattail.db import model -from cornice.resource import resource, view - -from tailbone.api import APIMasterView +from tailbone.api import APIMasterView2 as APIMasterView -@resource(collection_path='/customers', path='/customer/{uuid}') class CustomerView(APIMasterView): - + """ + API views for Customer data + """ model_class = model.Customer + collection_url_prefix = '/customers' + object_url_prefix = '/customer' def normalize(self, customer): return { @@ -48,22 +49,6 @@ class CustomerView(APIMasterView): 'name': customer.name, } - @view(permission='customers.list') - def collection_get(self): - return self._collection_get() - - @view(permission='customers.create') - def collection_post(self): - return self._collection_post() - - @view(permission='customers.view') - def get(self): - return self._get() - - @view(permission='customers.edit') - def post(self): - return self._post() - def includeme(config): - config.scan(__name__) + CustomerView.defaults(config) diff --git a/tailbone/api/upgrades.py b/tailbone/api/upgrades.py index 620ed4f8..85e4a91e 100644 --- a/tailbone/api/upgrades.py +++ b/tailbone/api/upgrades.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2020 Lance Edgar # # This file is part of Rattail. # @@ -30,17 +30,16 @@ import six from rattail.db import model -from cornice.resource import resource, view - -from tailbone.api import APIMasterView +from tailbone.api import APIMasterView2 as APIMasterView -@resource(collection_path='/upgrades', path='/upgrades/{uuid}') -class UpgradeAPIView(APIMasterView): +class UpgradeView(APIMasterView): """ REST API views for Upgrade model. """ model_class = model.Upgrade + collection_url_prefix = '/upgrades' + object_url_prefix = '/upgrades' def normalize(self, upgrade): data = { @@ -57,14 +56,6 @@ class UpgradeAPIView(APIMasterView): six.text_type(upgrade.status_code)) return data - @view(permission='upgrades.list') - def collection_get(self): - return self._collection_get() - - @view(permission='upgrades.view') - def get(self): - return self._get() - def includeme(config): - config.scan(__name__) + UpgradeView.defaults(config) diff --git a/tailbone/api/users.py b/tailbone/api/users.py index a21d3a2c..8474fd97 100644 --- a/tailbone/api/users.py +++ b/tailbone/api/users.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2020 Lance Edgar # # This file is part of Rattail. # @@ -30,15 +30,16 @@ import six from rattail.db import model -from cornice.resource import resource, view - -from tailbone.api import APIMasterView +from tailbone.api import APIMasterView2 as APIMasterView -@resource(collection_path='/users', path='/users/{uuid}') class UserView(APIMasterView): - + """ + API views for User data + """ model_class = model.User + collection_url_prefix = '/users' + object_url_prefix = '/user' def normalize(self, user): return { @@ -58,14 +59,6 @@ class UserView(APIMasterView): query = query.outerjoin(model.Person) return query - @view(permission='users.list') - def collection_get(self): - return self._collection_get() - - @view(permission='users.view') - def get(self): - return self._get() - def includeme(config): - config.scan(__name__) + UserView.defaults(config) diff --git a/tailbone/api/vendors.py b/tailbone/api/vendors.py index 533d7094..ce885e07 100644 --- a/tailbone/api/vendors.py +++ b/tailbone/api/vendors.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2019 Lance Edgar +# Copyright © 2010-2020 Lance Edgar # # This file is part of Rattail. # @@ -30,16 +30,15 @@ import six from rattail.db import model -from cornice import Service -from cornice.resource import resource, view - -from tailbone.api import APIMasterView +from tailbone.api import APIMasterView2 as APIMasterView -@resource(collection_path='/vendors', path='/vendor/{uuid}') class VendorView(APIMasterView): model_class = model.Vendor + collection_url_prefix = '/vendors' + object_url_prefix = '/vendor' + supports_autocomplete = True autocomplete_fieldname = 'name' def normalize(self, vendor): @@ -50,26 +49,6 @@ class VendorView(APIMasterView): 'name': vendor.name, } - @view(permission='vendors.list') - def collection_get(self): - return self._collection_get() - - @view(permission='vendors.create') - def collection_post(self): - return self._collection_post() - - @view(permission='vendors.view') - def get(self): - return self._get() - - @view(permission='vendors.edit') - def post(self): - return self._post() - def includeme(config): - config.scan(__name__) - - autocomplete = Service(name='vendors.autocomplete', path='/vendors/autocomplete') - autocomplete.add_view('GET', 'autocomplete', klass=VendorView) - config.add_cornice_service(autocomplete) + VendorView.defaults(config)