Refactor all API views thus far, to use new v2 master

This commit is contained in:
Lance Edgar 2020-03-01 17:17:54 -06:00
parent 113c0af49d
commit c55830e533
4 changed files with 28 additions and 80 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)