Refactor label batch view to use master3
This commit is contained in:
parent
efdbc3c5b5
commit
d20601c359
|
@ -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)))
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue