From 8dcec94aecdc5314d1de7b804af3d39f79956acc Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 6 Nov 2019 22:31:00 -0600 Subject: [PATCH] Add notes to label batch API (get), basic create support --- tailbone/api/batch/labels.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tailbone/api/batch/labels.py b/tailbone/api/batch/labels.py index 507657fe..d6ba226d 100644 --- a/tailbone/api/batch/labels.py +++ b/tailbone/api/batch/labels.py @@ -62,6 +62,8 @@ class LabelBatchViews(APIMasterView): 'id': batch.id, 'id_str': batch.id_str, 'description': batch.description, + 'notes': batch.notes, + 'rowcount': batch.rowcount, 'created': created, 'created_by_uuid': batch.created_by.uuid, 'created_by_display': six.text_type(batch.created_by), @@ -74,14 +76,23 @@ class LabelBatchViews(APIMasterView): def collection_get(self): return self._collection_get() - # @view(permission='ordering.create') - # def collection_post(self): - # return self._collection_post() + def collection_post(self): + return self._collection_post() + + def update_object(self, batch, data): + + # assign some default values for new batch + if not batch.uuid: + batch.created_by_uuid = self.request.user.uuid + if batch.rowcount is None: + batch.rowcount = 0 + + return super(LabelBatchViews, self).update_object(batch, data) def get(self): return self._get() - # @view(permission='ordering.edit') + # @view(permission='labels.batch.edit') # def post(self): # return self._post() @@ -90,6 +101,7 @@ class LabelBatchViews(APIMasterView): # label batches resource.add_view(cls.collection_get, permission='labels.batch.list') + resource.add_view(cls.collection_post, permission='labels.batch.create') resource.add_view(cls.get, permission='labels.batch.view') batch_resource = resource.add_resource(cls, collection_path='/label-batches', path='/label-batch/{uuid}') config.add_cornice_resource(batch_resource)