Add support for label batch "quick entry" API
plus other general improvements to API core/master views and config
This commit is contained in:
parent
c520dc23ba
commit
bd09acd0fd
4 changed files with 159 additions and 3 deletions
|
@ -34,6 +34,7 @@ from rattail.time import localtime
|
|||
from cornice import resource
|
||||
|
||||
from tailbone.api import APIMasterView
|
||||
from tailbone.api.batch import BatchAPIMasterView
|
||||
|
||||
|
||||
class LabelBatchViews(APIMasterView):
|
||||
|
@ -107,9 +108,14 @@ class LabelBatchViews(APIMasterView):
|
|||
config.add_cornice_resource(batch_resource)
|
||||
|
||||
|
||||
class LabelBatchRowViews(APIMasterView):
|
||||
class LabelBatchRowViews(BatchAPIMasterView):
|
||||
|
||||
model_class = model.LabelBatchRow
|
||||
default_handler_spec = 'rattail.batch.labels:LabelBatchHandler'
|
||||
supports_quick_entry = True
|
||||
route_prefix = 'api.label_batch_rows'
|
||||
permission_prefix = 'labels.batch'
|
||||
url_prefix = '/label-batch-rows'
|
||||
|
||||
def normalize(self, row):
|
||||
batch = row.batch
|
||||
|
@ -124,7 +130,10 @@ class LabelBatchRowViews(APIMasterView):
|
|||
'batch_description': batch.description,
|
||||
'sequence': row.sequence,
|
||||
'item_id': row.item_id,
|
||||
'upc': six.text_type(row.upc),
|
||||
'upc_pretty': row.upc.pretty() if row.upc else None,
|
||||
'description': row.description,
|
||||
'full_description': row.product.full_description if row.product else row.description,
|
||||
'status_code': row.status_code,
|
||||
'status_display': row.STATUS.get(row.status_code, six.text_type(row.status_code)),
|
||||
}
|
||||
|
@ -137,13 +146,16 @@ class LabelBatchRowViews(APIMasterView):
|
|||
|
||||
@classmethod
|
||||
def defaults(cls, config):
|
||||
permission_prefix = cls.get_permission_prefix()
|
||||
|
||||
# label batch rows
|
||||
resource.add_view(cls.collection_get, permission='labels.batch.view')
|
||||
resource.add_view(cls.get, permission='labels.batch.view')
|
||||
resource.add_view(cls.collection_get, permission='{}.view'.format(permission_prefix))
|
||||
resource.add_view(cls.get, permission='{}.view'.format(permission_prefix))
|
||||
rows_resource = resource.add_resource(cls, collection_path='/label-batch-rows', path='/label-batch-row/{uuid}')
|
||||
config.add_cornice_resource(rows_resource)
|
||||
|
||||
cls._batch_defaults(config)
|
||||
|
||||
|
||||
def includeme(config):
|
||||
LabelBatchViews.defaults(config)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue