Refactor all API views thus far, to use new v2 master
This commit is contained in:
parent
113c0af49d
commit
c55830e533
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2019 Lance Edgar
|
# Copyright © 2010-2020 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -30,15 +30,16 @@ import six
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
|
|
||||||
from cornice.resource import resource, view
|
from tailbone.api import APIMasterView2 as APIMasterView
|
||||||
|
|
||||||
from tailbone.api import APIMasterView
|
|
||||||
|
|
||||||
|
|
||||||
@resource(collection_path='/customers', path='/customer/{uuid}')
|
|
||||||
class CustomerView(APIMasterView):
|
class CustomerView(APIMasterView):
|
||||||
|
"""
|
||||||
|
API views for Customer data
|
||||||
|
"""
|
||||||
model_class = model.Customer
|
model_class = model.Customer
|
||||||
|
collection_url_prefix = '/customers'
|
||||||
|
object_url_prefix = '/customer'
|
||||||
|
|
||||||
def normalize(self, customer):
|
def normalize(self, customer):
|
||||||
return {
|
return {
|
||||||
|
@ -48,22 +49,6 @@ class CustomerView(APIMasterView):
|
||||||
'name': customer.name,
|
'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):
|
def includeme(config):
|
||||||
config.scan(__name__)
|
CustomerView.defaults(config)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2018 Lance Edgar
|
# Copyright © 2010-2020 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -30,17 +30,16 @@ import six
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
|
|
||||||
from cornice.resource import resource, view
|
from tailbone.api import APIMasterView2 as APIMasterView
|
||||||
|
|
||||||
from tailbone.api import APIMasterView
|
|
||||||
|
|
||||||
|
|
||||||
@resource(collection_path='/upgrades', path='/upgrades/{uuid}')
|
class UpgradeView(APIMasterView):
|
||||||
class UpgradeAPIView(APIMasterView):
|
|
||||||
"""
|
"""
|
||||||
REST API views for Upgrade model.
|
REST API views for Upgrade model.
|
||||||
"""
|
"""
|
||||||
model_class = model.Upgrade
|
model_class = model.Upgrade
|
||||||
|
collection_url_prefix = '/upgrades'
|
||||||
|
object_url_prefix = '/upgrades'
|
||||||
|
|
||||||
def normalize(self, upgrade):
|
def normalize(self, upgrade):
|
||||||
data = {
|
data = {
|
||||||
|
@ -57,14 +56,6 @@ class UpgradeAPIView(APIMasterView):
|
||||||
six.text_type(upgrade.status_code))
|
six.text_type(upgrade.status_code))
|
||||||
return data
|
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):
|
def includeme(config):
|
||||||
config.scan(__name__)
|
UpgradeView.defaults(config)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2018 Lance Edgar
|
# Copyright © 2010-2020 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -30,15 +30,16 @@ import six
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
|
|
||||||
from cornice.resource import resource, view
|
from tailbone.api import APIMasterView2 as APIMasterView
|
||||||
|
|
||||||
from tailbone.api import APIMasterView
|
|
||||||
|
|
||||||
|
|
||||||
@resource(collection_path='/users', path='/users/{uuid}')
|
|
||||||
class UserView(APIMasterView):
|
class UserView(APIMasterView):
|
||||||
|
"""
|
||||||
|
API views for User data
|
||||||
|
"""
|
||||||
model_class = model.User
|
model_class = model.User
|
||||||
|
collection_url_prefix = '/users'
|
||||||
|
object_url_prefix = '/user'
|
||||||
|
|
||||||
def normalize(self, user):
|
def normalize(self, user):
|
||||||
return {
|
return {
|
||||||
|
@ -58,14 +59,6 @@ class UserView(APIMasterView):
|
||||||
query = query.outerjoin(model.Person)
|
query = query.outerjoin(model.Person)
|
||||||
return query
|
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):
|
def includeme(config):
|
||||||
config.scan(__name__)
|
UserView.defaults(config)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2019 Lance Edgar
|
# Copyright © 2010-2020 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -30,16 +30,15 @@ import six
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
|
|
||||||
from cornice import Service
|
from tailbone.api import APIMasterView2 as APIMasterView
|
||||||
from cornice.resource import resource, view
|
|
||||||
|
|
||||||
from tailbone.api import APIMasterView
|
|
||||||
|
|
||||||
|
|
||||||
@resource(collection_path='/vendors', path='/vendor/{uuid}')
|
|
||||||
class VendorView(APIMasterView):
|
class VendorView(APIMasterView):
|
||||||
|
|
||||||
model_class = model.Vendor
|
model_class = model.Vendor
|
||||||
|
collection_url_prefix = '/vendors'
|
||||||
|
object_url_prefix = '/vendor'
|
||||||
|
supports_autocomplete = True
|
||||||
autocomplete_fieldname = 'name'
|
autocomplete_fieldname = 'name'
|
||||||
|
|
||||||
def normalize(self, vendor):
|
def normalize(self, vendor):
|
||||||
|
@ -50,26 +49,6 @@ class VendorView(APIMasterView):
|
||||||
'name': vendor.name,
|
'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):
|
def includeme(config):
|
||||||
config.scan(__name__)
|
VendorView.defaults(config)
|
||||||
|
|
||||||
autocomplete = Service(name='vendors.autocomplete', path='/vendors/autocomplete')
|
|
||||||
autocomplete.add_view('GET', 'autocomplete', klass=VendorView)
|
|
||||||
config.add_cornice_service(autocomplete)
|
|
||||||
|
|
Loading…
Reference in a new issue