Add support for "toggle complete" for batch API
This commit is contained in:
parent
bd09acd0fd
commit
afdd294c60
3 changed files with 92 additions and 16 deletions
|
@ -39,6 +39,7 @@ class BatchAPIMasterView(APIMasterView):
|
|||
"batch row" data.
|
||||
"""
|
||||
supports_quick_entry = False
|
||||
supports_toggle_complete = False
|
||||
|
||||
def __init__(self, request, **kwargs):
|
||||
super(BatchAPIMasterView, self).__init__(request, **kwargs)
|
||||
|
@ -95,14 +96,67 @@ class BatchAPIMasterView(APIMasterView):
|
|||
result['ok'] = True
|
||||
return result
|
||||
|
||||
def mark_complete(self):
|
||||
"""
|
||||
Mark the given batch as "complete".
|
||||
"""
|
||||
batch = self.get_object()
|
||||
|
||||
if batch.executed:
|
||||
return {'error': "Batch {} has already been executed: {}".format(
|
||||
batch.id_str, batch.description)}
|
||||
|
||||
if batch.complete:
|
||||
return {'error': "Batch {} is already marked complete: {}".format(
|
||||
batch.id_str, batch.description)}
|
||||
|
||||
batch.complete = True
|
||||
return self._get(obj=batch)
|
||||
|
||||
def mark_incomplete(self):
|
||||
"""
|
||||
Mark the given batch as "incomplete".
|
||||
"""
|
||||
batch = self.get_object()
|
||||
|
||||
if batch.executed:
|
||||
return {'error': "Batch {} has already been executed: {}".format(
|
||||
batch.id_str, batch.description)}
|
||||
|
||||
if not batch.complete:
|
||||
return {'error': "Batch {} is already marked incomplete: {}".format(
|
||||
batch.id_str, batch.description)}
|
||||
|
||||
batch.complete = False
|
||||
return self._get(obj=batch)
|
||||
|
||||
@classmethod
|
||||
def _batch_defaults(cls, config):
|
||||
route_prefix = cls.get_route_prefix()
|
||||
url_prefix = cls.get_url_prefix()
|
||||
collection_url_prefix = cls.get_collection_url_prefix()
|
||||
object_url_prefix = cls.get_object_url_prefix()
|
||||
permission_prefix = cls.get_permission_prefix()
|
||||
|
||||
# quick entry
|
||||
if cls.supports_quick_entry:
|
||||
config.add_route('{}.quick_entry'.format(route_prefix), '{}/quick-entry'.format(url_prefix),
|
||||
|
||||
# quick entry
|
||||
config.add_route('{}.quick_entry'.format(route_prefix), '{}/quick-entry'.format(collection_url_prefix),
|
||||
request_method=('OPTIONS', 'POST'))
|
||||
config.add_view(cls, attr='quick_entry', route_name='{}.quick_entry'.format(route_prefix),
|
||||
permission='{}.edit'.format(permission_prefix),
|
||||
renderer='json')
|
||||
|
||||
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 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')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue