From d20601c35949226407e6dbdf1e498021dcf41a0b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 26 Jan 2018 19:14:15 -0600 Subject: [PATCH] Refactor label batch view to use master3 --- tailbone/views/batch/core.py | 2 +- tailbone/views/labels/batch.py | 59 ++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/tailbone/views/batch/core.py b/tailbone/views/batch/core.py index 720ef62f..b2ec1669 100644 --- a/tailbone/views/batch/core.py +++ b/tailbone/views/batch/core.py @@ -336,7 +336,7 @@ class BatchMasterView(MasterView): form = self.make_form(batch) if self.request.method == 'POST': - if form.validate(): + if self.validate_form(form): self.save_edit_form(form) self.request.session.flash("{} has been updated: {}".format( self.get_model_title(), self.get_instance_title(batch))) diff --git a/tailbone/views/labels/batch.py b/tailbone/views/labels/batch.py index 0e97d0bf..e08a6a17 100644 --- a/tailbone/views/labels/batch.py +++ b/tailbone/views/labels/batch.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2017 Lance Edgar +# Copyright © 2010-2018 Lance Edgar # # This file is part of Rattail. # @@ -28,10 +28,9 @@ from __future__ import unicode_literals, absolute_import from rattail.db import model -import formalchemy as fa +from webhelpers2.html import HTML, tags -from tailbone import forms -from tailbone.views.batch import BatchMasterView2 as BatchMasterView +from tailbone.views.batch import BatchMasterView3 as BatchMasterView class LabelBatchView(BatchMasterView): @@ -64,28 +63,38 @@ class LabelBatchView(BatchMasterView): 'status_code', ] - def _preconfigure_fieldset(self, fs): - super(LabelBatchView, self)._preconfigure_fieldset(fs) - fs.append(fa.Field('handheld_batches', renderer=forms.renderers.HandheldBatchesFieldRenderer, readonly=True, - value=lambda b: b._handhelds)) + form_fields = [ + 'id', + 'description', + 'static_prices', + 'notes', + 'created', + 'created_by', + 'handheld_batches', + 'rowcount', + 'executed', + 'executed_by', + ] - def configure_fieldset(self, fs): - fs.configure( - include=[ - fs.id, - fs.description, - fs.static_prices, - fs.notes, - fs.created, - fs.created_by, - fs.handheld_batches, - fs.rowcount, - fs.executed, - fs.executed_by, - ]) - batch = fs.model - if self.viewing and not batch._handhelds: - del fs.handheld_batches + def configure_form(self, f): + super(LabelBatchView, self).configure_form(f) + + # handheld_batches + f.set_readonly('handheld_batches') + f.set_renderer('handheld_batches', self.render_handheld_batches) + + if self.viewing or self.deleting: + batch = self.get_instance() + if not batch._handhelds: + f.remove_field('handheld_batches') + + def render_handheld_batches(self, label_batch, field): + items = '' + for handheld in label_batch._handhelds: + text = handheld.handheld.id_str + url = self.request.route_url('batch.handheld.view', uuid=handheld.handheld_uuid) + items += HTML.tag('li', c=tags.link_to(text, url)) + return HTML.tag('ul', c=items) def configure_row_grid(self, g): super(LabelBatchView, self).configure_row_grid(g)