Refactor vendors view to use master3

This commit is contained in:
Lance Edgar 2017-12-04 22:02:46 -06:00
parent dfba168504
commit 7d79727c2e

View file

@ -26,11 +26,13 @@ Vendor Views
from __future__ import unicode_literals, absolute_import from __future__ import unicode_literals, absolute_import
import six
from rattail.db import model 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, AutocompleteView from tailbone.views import MasterView3 as MasterView, AutocompleteView
class VendorsView(MasterView): class VendorsView(MasterView):
@ -48,12 +50,23 @@ class VendorsView(MasterView):
'contact', 'contact',
] ]
form_fields = [
'id',
'name',
'special_discount',
'lead_time_days',
'order_interval_days',
'phone',
'email',
'contact',
]
def configure_grid(self, g): def configure_grid(self, g):
super(VendorsView, self).configure_grid(g) super(VendorsView, self).configure_grid(g)
g.filters['name'].default_active = True g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains' g.filters['name'].default_verb = 'contains'
g.default_sortkey = 'name' g.set_sort_defaults('name')
g.set_label('id', "ID") g.set_label('id', "ID")
g.set_label('phone', "Phone Number") g.set_label('phone', "Phone Number")
@ -62,26 +75,38 @@ class VendorsView(MasterView):
g.set_link('id') g.set_link('id')
g.set_link('name') g.set_link('name')
def configure_fieldset(self, fs): def configure_form(self, f):
fs.append(forms.AssociationProxyField('contact')) super(VendorsView, self).configure_form(f)
fs.configure(
include=[ f.set_label('id', "ID")
fs.id.label("ID"),
fs.name, f.set_label('lead_time_days', "Lead Time in Days")
fs.special_discount,
fs.lead_time_days.label("Lead Time in Days"), f.set_label('order_interval', "Order Interval in Days")
fs.order_interval_days.label("Order Interval in Days"),
fs.phone.label("Phone Number").readonly(), f.set_readonly('phone')
fs.email.label("Email Address").readonly(), f.set_label('phone', "Phone Number")
fs.contact.with_renderer(forms.PersonFieldRenderer).readonly(),
]) f.set_readonly('email')
f.set_label('email', "Email Address")
f.set_readonly('contact')
f.set_renderer('contact', self.render_contact)
def render_contact(self, vendor, field):
person = vendor.contact
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 before_delete(self, vendor): def before_delete(self, vendor):
# Remove all product costs. # Remove all product costs.
q = Session.query(model.ProductCost).filter( q = self.Session.query(model.ProductCost).filter(
model.ProductCost.vendor == vendor) model.ProductCost.vendor == vendor)
for cost in q: for cost in q:
Session.delete(cost) self.Session.delete(cost)
def get_version_child_classes(self): def get_version_child_classes(self):
return [ return [