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)
|
form = self.make_form(batch)
|
||||||
if self.request.method == 'POST':
|
if self.request.method == 'POST':
|
||||||
if form.validate():
|
if self.validate_form(form):
|
||||||
self.save_edit_form(form)
|
self.save_edit_form(form)
|
||||||
self.request.session.flash("{} has been updated: {}".format(
|
self.request.session.flash("{} has been updated: {}".format(
|
||||||
self.get_model_title(), self.get_instance_title(batch)))
|
self.get_model_title(), self.get_instance_title(batch)))
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2017 Lance Edgar
|
# Copyright © 2010-2018 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -28,10 +28,9 @@ from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
|
|
||||||
import formalchemy as fa
|
from webhelpers2.html import HTML, tags
|
||||||
|
|
||||||
from tailbone import forms
|
from tailbone.views.batch import BatchMasterView3 as BatchMasterView
|
||||||
from tailbone.views.batch import BatchMasterView2 as BatchMasterView
|
|
||||||
|
|
||||||
|
|
||||||
class LabelBatchView(BatchMasterView):
|
class LabelBatchView(BatchMasterView):
|
||||||
|
@ -64,28 +63,38 @@ class LabelBatchView(BatchMasterView):
|
||||||
'status_code',
|
'status_code',
|
||||||
]
|
]
|
||||||
|
|
||||||
def _preconfigure_fieldset(self, fs):
|
form_fields = [
|
||||||
super(LabelBatchView, self)._preconfigure_fieldset(fs)
|
'id',
|
||||||
fs.append(fa.Field('handheld_batches', renderer=forms.renderers.HandheldBatchesFieldRenderer, readonly=True,
|
'description',
|
||||||
value=lambda b: b._handhelds))
|
'static_prices',
|
||||||
|
'notes',
|
||||||
|
'created',
|
||||||
|
'created_by',
|
||||||
|
'handheld_batches',
|
||||||
|
'rowcount',
|
||||||
|
'executed',
|
||||||
|
'executed_by',
|
||||||
|
]
|
||||||
|
|
||||||
def configure_fieldset(self, fs):
|
def configure_form(self, f):
|
||||||
fs.configure(
|
super(LabelBatchView, self).configure_form(f)
|
||||||
include=[
|
|
||||||
fs.id,
|
# handheld_batches
|
||||||
fs.description,
|
f.set_readonly('handheld_batches')
|
||||||
fs.static_prices,
|
f.set_renderer('handheld_batches', self.render_handheld_batches)
|
||||||
fs.notes,
|
|
||||||
fs.created,
|
if self.viewing or self.deleting:
|
||||||
fs.created_by,
|
batch = self.get_instance()
|
||||||
fs.handheld_batches,
|
if not batch._handhelds:
|
||||||
fs.rowcount,
|
f.remove_field('handheld_batches')
|
||||||
fs.executed,
|
|
||||||
fs.executed_by,
|
def render_handheld_batches(self, label_batch, field):
|
||||||
])
|
items = ''
|
||||||
batch = fs.model
|
for handheld in label_batch._handhelds:
|
||||||
if self.viewing and not batch._handhelds:
|
text = handheld.handheld.id_str
|
||||||
del fs.handheld_batches
|
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):
|
def configure_row_grid(self, g):
|
||||||
super(LabelBatchView, self).configure_row_grid(g)
|
super(LabelBatchView, self).configure_row_grid(g)
|
||||||
|
|
Loading…
Reference in a new issue