From ce0195bd51ef7d28455d98cfc19300c7b715da82 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 8 Jan 2018 20:41:31 -0600 Subject: [PATCH] Refactor several more straggler views to use master3 --- tailbone/views/custorders/items.py | 93 ++++++++++++++++++----------- tailbone/views/custorders/orders.py | 53 ++++++++++------ tailbone/views/depositlinks.py | 18 +++--- tailbone/views/families.py | 18 +++--- tailbone/views/labels/profiles.py | 34 +++++------ tailbone/views/purchases/credits.py | 8 +-- tailbone/views/reportcodes.py | 17 +++--- tailbone/views/tables.py | 4 +- tailbone/views/taxes.py | 18 +++--- tailbone/views/trainwreck.py | 72 ++++++++++++---------- 10 files changed, 187 insertions(+), 148 deletions(-) diff --git a/tailbone/views/custorders/items.py b/tailbone/views/custorders/items.py index 4a14da89..7963763f 100644 --- a/tailbone/views/custorders/items.py +++ b/tailbone/views/custorders/items.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. # @@ -33,10 +33,7 @@ from sqlalchemy import orm from rattail.db import model from rattail.time import localtime -import formalchemy as fa - -from tailbone import forms -from tailbone.views import MasterView2 as MasterView +from tailbone.views import MasterView3 as MasterView from tailbone.util import raw_datetime @@ -78,6 +75,21 @@ class CustomerOrderItemsView(MasterView): 'note', ] + form_fields = [ + 'person', + 'product', + 'product_brand', + 'product_description', + 'product_size', + 'case_quantity', + 'cases_ordered', + 'units_ordered', + 'unit_price', + 'total_price', + 'paid_amount', + 'status_code', + ] + def query(self, session): return session.query(model.CustomerOrderItem)\ .join(model.CustomerOrder)\ @@ -118,36 +130,49 @@ class CustomerOrderItemsView(MasterView): value = localtime(self.rattail_config, item.order.created, from_utc=True) return raw_datetime(self.rattail_config, value) - def _preconfigure_fieldset(self, fs): - fs.order.set(renderer=forms.renderers.CustomerOrderFieldRenderer) - fs.product.set(renderer=forms.renderers.ProductFieldRenderer) - fs.product_unit_of_measure.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.UNIT_OF_MEASURE)) - fs.case_quantity.set(renderer=forms.renderers.QuantityFieldRenderer) - fs.cases_ordered.set(renderer=forms.renderers.QuantityFieldRenderer) - fs.units_ordered.set(renderer=forms.renderers.QuantityFieldRenderer) - fs.unit_price.set(renderer=forms.renderers.CurrencyFieldRenderer) - fs.total_price.set(renderer=forms.renderers.CurrencyFieldRenderer) - fs.paid_amount.set(renderer=forms.renderers.CurrencyFieldRenderer) - fs.status_code.set(label="Status") - fs.append(fa.Field('person', value=lambda i: i.order.person, - renderer=forms.renderers.PersonFieldRenderer)) + def configure_form(self, f): + super(CustomerOrderItemsView, self).configure_form(f) - def configure_fieldset(self, fs): - fs.configure( - include=[ - fs.person, - fs.product, - fs.product_brand, - fs.product_description, - fs.product_size, - fs.case_quantity, - fs.cases_ordered, - fs.units_ordered, - fs.unit_price, - fs.total_price, - fs.paid_amount, - fs.status_code, - ]) + # order + f.set_renderer('order', self.render_order) + + # product + f.set_renderer('product', self.render_product) + + # product uom + f.set_enum('product_unit_of_measure', self.enum.UNIT_OF_MEASURE) + + # quantity fields + f.set_type('case_quantity', 'quantity') + f.set_type('cases_ordered', 'quantity') + f.set_type('units_ordered', 'quantity') + + # currency fields + f.set_type('unit_price', 'currency') + f.set_type('total_price', 'currency') + f.set_type('paid_amount', 'currency') + + # person + f.set_renderer('person', self.render_person) + + # label overrides + f.set_label('status_code', "Status") + + def render_order(self, item, field): + order = item.order + if not order: + return "" + text = six.text_type(order) + url = self.request.route_url('custorders.view', uuid=order.uuid) + return tags.link_to(text, url) + + def render_product(self, order, field): + product = order.product + if not product: + return "" + text = six.text_type(product) + url = self.request.route_url('products.view', uuid=product.uuid) + return tags.link_to(text, url) def get_row_data(self, item): return self.Session.query(model.CustomerOrderItemEvent)\ diff --git a/tailbone/views/custorders/orders.py b/tailbone/views/custorders/orders.py index c10333eb..eb8b89a6 100644 --- a/tailbone/views/custorders/orders.py +++ b/tailbone/views/custorders/orders.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. # @@ -26,13 +26,15 @@ Customer Order Views from __future__ import unicode_literals, absolute_import +import six from sqlalchemy import orm from rattail.db import model -from tailbone import forms +from webhelpers2.html import tags + from tailbone.db import Session -from tailbone.views import MasterView2 as MasterView +from tailbone.views import MasterView as MasterView class CustomerOrdersView(MasterView): @@ -53,6 +55,14 @@ class CustomerOrdersView(MasterView): 'status_code', ] + form_fields = [ + 'id', + 'customer', + 'person', + 'created', + 'status_code', + ] + def query(self, session): return session.query(model.CustomerOrder)\ .options(orm.joinedload(model.CustomerOrder.customer)) @@ -81,22 +91,29 @@ class CustomerOrdersView(MasterView): g.set_label('status_code', "Status") g.set_label('id', "ID") - def _preconfigure_fieldset(self, fs): - fs.customer.set(options=[]) - fs.id.set(label="ID", readonly=True) - fs.person.set(renderer=forms.renderers.PersonFieldRenderer) - fs.created.set(readonly=True) - fs.status_code.set(label="Status") + def configure_form(self, f): + super(CustomerOrdersView, self).configure_form(f) - def configure_fieldset(self, fs): - fs.configure( - include=[ - fs.id, - fs.customer, - fs.person, - fs.created, - fs.status_code, - ]) + # id + f.set_readonly('id') + f.set_label('id', "ID") + + # person + f.set_renderer('person', self.render_person) + + # created + f.set_readonly('created') + + # label overrides + f.set_label('status_code', "Status") + + def render_person(self, order, field): + person = order.person + if not person: + return "" + text = six.text_type(person) + url = self.request.route_url('people.view', uuid=person.uuid) + return tags.link_to(text, url) def includeme(config): diff --git a/tailbone/views/depositlinks.py b/tailbone/views/depositlinks.py index b7f5876d..340cf818 100644 --- a/tailbone/views/depositlinks.py +++ b/tailbone/views/depositlinks.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. # @@ -29,7 +29,7 @@ from __future__ import unicode_literals, absolute_import from rattail.db import model from tailbone import forms -from tailbone.views import MasterView2 as MasterView +from tailbone.views import MasterView3 as MasterView class DepositLinksView(MasterView): @@ -46,6 +46,12 @@ class DepositLinksView(MasterView): 'amount', ] + form_fields = [ + 'code', + 'description', + 'amount', + ] + def configure_grid(self, g): super(DepositLinksView, self).configure_grid(g) g.filters['description'].default_active = True @@ -55,14 +61,6 @@ class DepositLinksView(MasterView): g.set_link('code') g.set_link('description') - def configure_fieldset(self, fs): - fs.configure( - include=[ - fs.code, - fs.description, - fs.amount, - ]) - def includeme(config): DepositLinksView.defaults(config) diff --git a/tailbone/views/families.py b/tailbone/views/families.py index b9babf66..02c370b6 100644 --- a/tailbone/views/families.py +++ b/tailbone/views/families.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,7 +28,7 @@ from __future__ import unicode_literals, absolute_import from rattail.db import model -from tailbone.views import MasterView2 as MasterView +from tailbone.views import MasterView3 as MasterView class FamiliesView(MasterView): @@ -46,19 +46,17 @@ class FamiliesView(MasterView): 'name', ] + form_fields = [ + 'code', + 'name', + ] + def configure_grid(self, g): + super(FamiliesView, self).configure_grid(g) g.filters['name'].default_active = True g.filters['name'].default_verb = 'contains' g.set_sort_defaults('code') - def configure_fieldset(self, fs): - fs.configure( - include=[ - fs.code, - fs.name, - ]) - return fs - def includeme(config): FamiliesView.defaults(config) diff --git a/tailbone/views/labels/profiles.py b/tailbone/views/labels/profiles.py index de2eaac7..7a71913e 100644 --- a/tailbone/views/labels/profiles.py +++ b/tailbone/views/labels/profiles.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. # @@ -30,9 +30,8 @@ from rattail.db import model from pyramid.httpexceptions import HTTPFound -from tailbone import forms from tailbone.db import Session -from tailbone.views import MasterView2 as MasterView +from tailbone.views import MasterView3 as MasterView class ProfilesView(MasterView): @@ -51,6 +50,16 @@ class ProfilesView(MasterView): 'visible', ] + form_fields = [ + 'ordinal', + 'code', + 'description', + 'printer_spec', + 'formatter_spec', + 'format', + 'visible', + ] + def configure_grid(self, g): super(ProfilesView, self).configure_grid(g) g.set_sort_defaults('ordinal') @@ -58,20 +67,11 @@ class ProfilesView(MasterView): g.set_link('code') g.set_link('description') - def configure_fieldset(self, fs): - fs.printer_spec.set(renderer=forms.renderers.StrippedTextFieldRenderer) - fs.formatter_spec.set(renderer=forms.renderers.StrippedTextFieldRenderer) - fs.format.set(renderer=forms.renderers.CodeTextAreaFieldRenderer) - fs.configure( - include=[ - fs.ordinal, - fs.code, - fs.description, - fs.printer_spec, - fs.formatter_spec, - fs.format, - fs.visible, - ]) + def configure_form(self, f): + super(ProfilesView, self).configure_form(f) + + # format + f.set_type('format', 'codeblock') def after_create(self, profile): self.after_edit(profile) diff --git a/tailbone/views/purchases/credits.py b/tailbone/views/purchases/credits.py index 464e194b..b32c6172 100644 --- a/tailbone/views/purchases/credits.py +++ b/tailbone/views/purchases/credits.py @@ -1,8 +1,8 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2017 Lance Edgar +# Copyright © 2010-2018 Lance Edgar # # This file is part of Rattail. # @@ -30,8 +30,8 @@ from rattail.db import model from webhelpers2.html import tags -from tailbone import forms, grids -from tailbone.views import MasterView2 as MasterView +from tailbone import grids +from tailbone.views import MasterView3 as MasterView class PurchaseCreditView(MasterView): diff --git a/tailbone/views/reportcodes.py b/tailbone/views/reportcodes.py index bb3b03ec..c60dbfe9 100644 --- a/tailbone/views/reportcodes.py +++ b/tailbone/views/reportcodes.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,7 +28,7 @@ from __future__ import unicode_literals, absolute_import from rattail.db import model -from tailbone.views import MasterView2 as MasterView +from tailbone.views import MasterView3 as MasterView class ReportCodesView(MasterView): @@ -44,6 +44,11 @@ class ReportCodesView(MasterView): 'name', ] + form_fields = [ + 'code', + 'name', + ] + def configure_grid(self, g): super(ReportCodesView, self).configure_grid(g) g.filters['name'].default_active = True @@ -52,14 +57,6 @@ class ReportCodesView(MasterView): g.set_link('code') g.set_link('name') - def configure_fieldset(self, fs): - fs.configure( - include=[ - fs.code, - fs.name, - ]) - return fs - def includeme(config): ReportCodesView.defaults(config) diff --git a/tailbone/views/tables.py b/tailbone/views/tables.py index b94d590f..4fb08008 100644 --- a/tailbone/views/tables.py +++ b/tailbone/views/tables.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. # @@ -26,7 +26,7 @@ Views with info about the underlying Rattail tables from __future__ import unicode_literals, absolute_import -from tailbone.views import MasterView2 as MasterView +from tailbone.views import MasterView3 as MasterView class TablesView(MasterView): diff --git a/tailbone/views/taxes.py b/tailbone/views/taxes.py index ef2efd75..1f53de5e 100644 --- a/tailbone/views/taxes.py +++ b/tailbone/views/taxes.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,7 +28,7 @@ from __future__ import unicode_literals, absolute_import from rattail.db import model -from tailbone.views import MasterView2 as MasterView +from tailbone.views import MasterView3 as MasterView class TaxesView(MasterView): @@ -46,6 +46,12 @@ class TaxesView(MasterView): 'rate', ] + form_fields = [ + 'code', + 'description', + 'rate', + ] + def configure_grid(self, g): super(TaxesView, self).configure_grid(g) g.filters['description'].default_active = True @@ -54,14 +60,6 @@ class TaxesView(MasterView): g.set_link('code') g.set_link('description') - def configure_fieldset(self, fs): - fs.configure( - include=[ - fs.code, - fs.description, - fs.rate, - ]) - def includeme(config): TaxesView.defaults(config) diff --git a/tailbone/views/trainwreck.py b/tailbone/views/trainwreck.py index 5d314106..d1b994ee 100644 --- a/tailbone/views/trainwreck.py +++ b/tailbone/views/trainwreck.py @@ -32,7 +32,7 @@ from rattail.time import localtime from tailbone import forms from tailbone.db import TrainwreckSession -from tailbone.views import MasterView2 as MasterView +from tailbone.views import MasterView3 as MasterView class TransactionView(MasterView): @@ -77,6 +77,27 @@ class TransactionView(MasterView): 'void', ] + form_fields = [ + 'system', + 'system_id', + 'terminal_id', + 'receipt_number', + 'start_time', + 'end_time', + 'upload_time', + 'cashier_id', + 'cashier_name', + 'customer_id', + 'customer_name', + 'shopper_id', + 'shopper_name', + 'subtotal', + 'discounted_subtotal', + 'tax', + 'total', + 'void', + ] + def configure_grid(self, g): super(TransactionView, self).configure_grid(g) g.filters['receipt_number'].default_active = True @@ -98,39 +119,24 @@ class TransactionView(MasterView): g.set_link('customer_name') g.set_link('total') - def _preconfigure_fieldset(self, fs): - fs.system.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.TRAINWRECK_SYSTEM)) - fs.system_id.set(label="System ID") - fs.terminal_id.set(label="Terminal") - fs.cashier_id.set(label="Cashier ID") - fs.customer_id.set(label="Customer ID") - fs.shopper_id.set(label="Shopper ID") - fs.subtotal.set(renderer=forms.renderers.CurrencyFieldRenderer) - fs.discounted_subtotal.set(renderer=forms.renderers.CurrencyFieldRenderer) - fs.tax.set(renderer=forms.renderers.CurrencyFieldRenderer) - fs.total.set(renderer=forms.renderers.CurrencyFieldRenderer) + def configure_form(self, f): + super(TransactionView, self).configure_form(f) - def configure_fieldset(self, fs): - fs.configure(include=[ - fs.system, - fs.system_id, - fs.terminal_id, - fs.receipt_number, - fs.start_time, - fs.end_time, - fs.upload_time, - fs.cashier_id, - fs.cashier_name, - fs.customer_id, - fs.customer_name, - fs.shopper_id, - fs.shopper_name, - fs.subtotal, - fs.discounted_subtotal, - fs.tax, - fs.total, - fs.void, - ]) + # system + f.set_enum('system', self.enum.TRAINWRECK_SYSTEM) + + # currency fields + f.set_type('subtotal', 'currency') + f.set_type('discounted_subtotal', 'currency') + f.set_type('tax', 'currency') + f.set_type('total', 'currency') + + # label overrides + f.set_label('system_id', "System ID") + f.set_label('terminal_id', "Terminal") + f.set_label('cashier_id', "Cashier ID") + f.set_label('customer_id', "Customer ID") + f.set_label('shopper_id', "Shopper ID") def get_row_data(self, transaction): return self.Session.query(self.model_row_class)\