Use proper cornice service registration, for API batch execute etc.

This commit is contained in:
Lance Edgar 2020-03-20 14:40:27 -05:00
parent a721ec4a43
commit 1570871884

View file

@ -31,7 +31,7 @@ import six
from rattail.time import localtime
from rattail.util import load_object
from cornice import resource
from cornice import resource, Service
from tailbone.api import APIMasterView2 as APIMasterView
@ -213,25 +213,27 @@ class APIBatchView(APIBatchMixin, APIMasterView):
if cls.supports_toggle_complete:
# mark complete
config.add_route('{}.mark_complete'.format(route_prefix), '{}/{{uuid}}/mark-complete'.format(object_url_prefix))
config.add_view(cls, attr='mark_complete', route_name='{}.mark_complete'.format(route_prefix),
permission='{}.edit'.format(permission_prefix),
renderer='json')
mark_complete = Service(name='{}.mark_complete'.format(route_prefix),
path='{}/{{uuid}}/mark-complete'.format(object_url_prefix))
mark_complete.add_view('POST', 'mark_complete', klass=cls,
permission='{}.edit'.format(permission_prefix))
config.add_cornice_service(mark_complete)
# mark incomplete
config.add_route('{}.mark_incomplete'.format(route_prefix), '{}/{{uuid}}/mark-incomplete'.format(object_url_prefix))
config.add_view(cls, attr='mark_incomplete', route_name='{}.mark_incomplete'.format(route_prefix),
permission='{}.edit'.format(permission_prefix),
renderer='json')
mark_incomplete = Service(name='{}.mark_incomplete'.format(route_prefix),
path='{}/{{uuid}}/mark-incomplete'.format(object_url_prefix))
mark_incomplete.add_view('POST', 'mark_incomplete', klass=cls,
permission='{}.edit'.format(permission_prefix))
config.add_cornice_service(mark_incomplete)
if cls.supports_execute:
# execute
config.add_route('{}.execute'.format(route_prefix), '{}/{{uuid}}/execute'.format(object_url_prefix),
request_method=('OPTIONS', 'POST'))
config.add_view(cls, attr='execute', route_name='{}.execute'.format(route_prefix),
permission='{}.execute'.format(permission_prefix),
renderer='json')
# execute batch
execute = Service(name='{}.execute'.format(route_prefix),
path='{}/{{uuid}}/execute'.format(object_url_prefix))
execute.add_view('POST', 'execute', klass=cls,
permission='{}.execute'.format(permission_prefix))
config.add_cornice_service(execute)
# TODO: deprecate / remove this