From 7cee515187d5485b6b21f8aa046bc49223164262 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 4 Feb 2018 11:09:35 -0600 Subject: [PATCH] Refactor handheld batch views per master4 --- tailbone/views/handheld.py | 58 +++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/tailbone/views/handheld.py b/tailbone/views/handheld.py index bea1c378..015c7e41 100644 --- a/tailbone/views/handheld.py +++ b/tailbone/views/handheld.py @@ -34,9 +34,8 @@ from rattail.util import OrderedDict import formencode as fe from webhelpers2.html import tags -from tailbone import forms from tailbone.db import Session -from tailbone.views.batch import FileBatchMasterView3 as FileBatchMasterView +from tailbone.views.batch import FileBatchMasterView4 as FileBatchMasterView ACTION_OPTIONS = OrderedDict([ @@ -92,6 +91,10 @@ class HandheldBatchView(FileBatchMasterView): 'executed_by', ] + row_labels = { + 'upc': "UPC", + } + row_grid_columns = [ 'sequence', 'upc', @@ -103,6 +106,17 @@ class HandheldBatchView(FileBatchMasterView): 'status_code', ] + row_form_fields = [ + 'sequence', + 'upc', + 'brand_name', + 'description', + 'size', + 'status_code', + 'cases', + 'units', + ] + def configure_grid(self, g): super(HandheldBatchView, self).configure_grid(g) device_types = OrderedDict(sorted(self.enum.HANDHELD_DEVICE_TYPE.items(), @@ -153,33 +167,33 @@ class HandheldBatchView(FileBatchMasterView): super(HandheldBatchView, self).configure_row_grid(g) g.set_type('cases', 'quantity') g.set_type('units', 'quantity') - g.set_label('upc', "UPC") g.set_label('brand_name', "Brand") def row_grid_extra_class(self, row, i): if row.status_code == row.STATUS_PRODUCT_NOT_FOUND: return 'warning' - def _preconfigure_row_fieldset(self, fs): - super(HandheldBatchView, self)._preconfigure_row_fieldset(fs) - fs.upc.set(readonly=True, label="UPC", renderer=forms.renderers.GPCFieldRenderer, - attrs={'link': lambda r: self.request.route_url('products.view', uuid=r.product_uuid)}) - fs.brand_name.set(readonly=True) - fs.description.set(readonly=True) - fs.size.set(readonly=True) + def configure_row_form(self, f): + super(HandheldBatchView, self).configure_row_form(f) - def configure_row_fieldset(self, fs): - fs.configure( - include=[ - fs.sequence, - fs.upc, - fs.brand_name, - fs.description, - fs.size, - fs.status_code, - fs.cases, - fs.units, - ]) + # readonly fields + f.set_readonly('upc') + f.set_readonly('brand_name') + f.set_readonly('description') + f.set_readonly('size') + + # upc + f.set_renderer('upc', self.render_upc) + + def render_upc(self, row, field): + upc = row.upc + if not upc: + return "" + text = upc.pretty() + if row.product_uuid: + url = self.request.route_url('products.view', uuid=row.product_uuid) + return tags.link_to(text, url) + return text def get_exec_options_kwargs(self, **kwargs): kwargs['ACTION_OPTIONS'] = list(ACTION_OPTIONS.iteritems())