Add 'person' column for customers grid

but don't show it by default, for now?
This commit is contained in:
Lance Edgar 2018-07-15 16:23:09 -05:00
parent 259d123876
commit 45f19517d3

View file

@ -99,35 +99,39 @@ class CustomersView(MasterView):
def configure_grid(self, g):
super(CustomersView, self).configure_grid(g)
g.joiners['email'] = lambda q: q.outerjoin(model.CustomerEmailAddress, sa.and_(
model.CustomerEmailAddress.parent_uuid == model.Customer.uuid,
model.CustomerEmailAddress.preference == 1))
g.joiners['phone'] = lambda q: q.outerjoin(model.CustomerPhoneNumber, sa.and_(
model.CustomerPhoneNumber.parent_uuid == model.Customer.uuid,
model.CustomerPhoneNumber.preference == 1))
g.filters['email'] = g.make_filter('email', model.CustomerEmailAddress.address,
label="Email Address")
g.filters['phone'] = g.make_filter('phone', model.CustomerPhoneNumber.number,
label="Phone Number")
# TODO
# name=self.filter_ilike_and_soundex(model.Customer.name),
# name
g.filters['name'].default_active = True
g.filters['name'].default_verb = 'contains'
g.set_sort_defaults('name')
g.sorters['email'] = lambda q, d: q.order_by(getattr(model.CustomerEmailAddress.address, d)())
# phone
g.set_joiner('phone', lambda q: q.outerjoin(model.CustomerPhoneNumber, sa.and_(
model.CustomerPhoneNumber.parent_uuid == model.Customer.uuid,
model.CustomerPhoneNumber.preference == 1)))
g.sorters['phone'] = lambda q, d: q.order_by(getattr(model.CustomerPhoneNumber.number, d)())
g.set_filter('phone', model.CustomerPhoneNumber.number)#, label="Phone Number")
g.set_label('phone', "Phone Number")
# email
g.set_joiner('email', lambda q: q.outerjoin(model.CustomerEmailAddress, sa.and_(
model.CustomerEmailAddress.parent_uuid == model.Customer.uuid,
model.CustomerEmailAddress.preference == 1)))
g.sorters['email'] = lambda q, d: q.order_by(getattr(model.CustomerEmailAddress.address, d)())
g.set_filter('email', model.CustomerEmailAddress.address)#, label="Email Address")
g.set_label('email', "Email Address")
# email_preference
g.set_enum('email_preference', self.enum.EMAIL_PREFERENCE)
g.set_sort_defaults('name')
g.set_label('id', "ID")
g.set_label('phone', "Phone Number")
g.set_label('email', "Email Address")
# person
g.set_joiner('person', lambda q:
q.outerjoin(model.CustomerPerson,
sa.and_(
model.CustomerPerson.customer_uuid == model.Customer.uuid,
model.CustomerPerson.ordinal == 1))\
.outerjoin(model.Person))
g.set_sorter('person', model.Person.display_name)
g.set_renderer('person', self.grid_render_person)
g.set_link('id')
g.set_link('number')
@ -225,6 +229,15 @@ class CustomersView(MasterView):
if customer.addresses:
return six.text_type(customer.addresses[0])
def grid_render_person(self, customer, field):
person = getattr(customer, field)
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 render_people(self, customer, field):
people = customer.people
if not people: