Refactor vendors view to use master3
This commit is contained in:
parent
dfba168504
commit
7d79727c2e
63
tailbone/views/vendors/core.py
vendored
63
tailbone/views/vendors/core.py
vendored
|
@ -26,11 +26,13 @@ Vendor Views
|
|||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
import six
|
||||
|
||||
from rattail.db import model
|
||||
|
||||
from tailbone import forms
|
||||
from tailbone.db import Session
|
||||
from tailbone.views import MasterView2 as MasterView, AutocompleteView
|
||||
from webhelpers2.html import tags
|
||||
|
||||
from tailbone.views import MasterView3 as MasterView, AutocompleteView
|
||||
|
||||
|
||||
class VendorsView(MasterView):
|
||||
|
@ -48,12 +50,23 @@ class VendorsView(MasterView):
|
|||
'contact',
|
||||
]
|
||||
|
||||
form_fields = [
|
||||
'id',
|
||||
'name',
|
||||
'special_discount',
|
||||
'lead_time_days',
|
||||
'order_interval_days',
|
||||
'phone',
|
||||
'email',
|
||||
'contact',
|
||||
]
|
||||
|
||||
def configure_grid(self, g):
|
||||
super(VendorsView, self).configure_grid(g)
|
||||
|
||||
g.filters['name'].default_active = True
|
||||
g.filters['name'].default_verb = 'contains'
|
||||
g.default_sortkey = 'name'
|
||||
g.set_sort_defaults('name')
|
||||
|
||||
g.set_label('id', "ID")
|
||||
g.set_label('phone', "Phone Number")
|
||||
|
@ -62,26 +75,38 @@ class VendorsView(MasterView):
|
|||
g.set_link('id')
|
||||
g.set_link('name')
|
||||
|
||||
def configure_fieldset(self, fs):
|
||||
fs.append(forms.AssociationProxyField('contact'))
|
||||
fs.configure(
|
||||
include=[
|
||||
fs.id.label("ID"),
|
||||
fs.name,
|
||||
fs.special_discount,
|
||||
fs.lead_time_days.label("Lead Time in Days"),
|
||||
fs.order_interval_days.label("Order Interval in Days"),
|
||||
fs.phone.label("Phone Number").readonly(),
|
||||
fs.email.label("Email Address").readonly(),
|
||||
fs.contact.with_renderer(forms.PersonFieldRenderer).readonly(),
|
||||
])
|
||||
def configure_form(self, f):
|
||||
super(VendorsView, self).configure_form(f)
|
||||
|
||||
f.set_label('id', "ID")
|
||||
|
||||
f.set_label('lead_time_days', "Lead Time in Days")
|
||||
|
||||
f.set_label('order_interval', "Order Interval in Days")
|
||||
|
||||
f.set_readonly('phone')
|
||||
f.set_label('phone', "Phone Number")
|
||||
|
||||
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):
|
||||
# Remove all product costs.
|
||||
q = Session.query(model.ProductCost).filter(
|
||||
q = self.Session.query(model.ProductCost).filter(
|
||||
model.ProductCost.vendor == vendor)
|
||||
for cost in q:
|
||||
Session.delete(cost)
|
||||
self.Session.delete(cost)
|
||||
|
||||
def get_version_child_classes(self):
|
||||
return [
|
||||
|
|
Loading…
Reference in a new issue