Tweak how customer/person relationships are displayed

expose just a little more to make it easier to track down a data issue i had
This commit is contained in:
Lance Edgar 2017-07-03 16:58:30 -05:00
parent 24a2c15850
commit 4aa91414a5
4 changed files with 32 additions and 6 deletions

View file

@ -35,7 +35,7 @@ from .common import (StrippedTextFieldRenderer, CodeTextAreaFieldRenderer, Autoc
from .files import FileFieldRenderer
from .people import PersonFieldRenderer, CustomerFieldRenderer
from .people import PersonFieldRenderer, PeopleFieldRenderer, CustomerFieldRenderer
from .users import UserFieldRenderer, PermissionsFieldRenderer
from .employees import EmployeeFieldRenderer

View file

@ -27,7 +27,8 @@ People Field Renderers
from __future__ import unicode_literals, absolute_import
import six
from webhelpers.html import tags
import formalchemy as fa
from webhelpers.html import tags, HTML
from tailbone.forms.renderers.common import AutocompleteFieldRenderer
@ -45,6 +46,23 @@ class PersonFieldRenderer(AutocompleteFieldRenderer):
return tags.link_to(person, self.request.route_url('people.view', uuid=person.uuid))
class PeopleFieldRenderer(fa.FieldRenderer):
"""
Renderer for "people" list relationship
"""
def render_readonly(self, **kwargs):
html = ''
people = self.raw_value
if not people:
return html
for person in people:
link = tags.link_to(person, self.request.route_url('people.view', uuid=person.uuid))
html += HTML.tag('li', c=link)
html = HTML.tag('ul', c=html)
return html
class CustomerFieldRenderer(AutocompleteFieldRenderer):
"""
Renderer for :class:`rattail.db.model.Customer` instance fields.

View file

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2015 Lance Edgar
# Copyright © 2010-2017 Lance Edgar
#
# This file is part of Rattail.
#
@ -121,6 +121,7 @@ class CustomersView(MasterView):
fs.append(forms.fields.DefaultPhoneField('default_phone', label="Phone Number"))
fs.append(forms.fields.DefaultEmailField('default_email', label="Email Address"))
fs.email_preference.set(renderer=forms.EnumFieldRenderer(self.enum.EMAIL_PREFERENCE))
fs.append(forms.AssociationProxyField('people', renderer=forms.renderers.PeopleFieldRenderer))
def configure_fieldset(self, fs):
fs.configure(
@ -132,6 +133,7 @@ class CustomersView(MasterView):
# fs.email.label("Email Address").readonly(),
fs.default_email,
fs.email_preference,
fs.people,
])
def configure_mobile_fieldset(self, fs):

View file

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2016 Lance Edgar
# Copyright © 2010-2017 Lance Edgar
#
# This file is part of Rattail.
#
@ -32,6 +32,7 @@ import formalchemy as fa
from pyramid.httpexceptions import HTTPFound, HTTPNotFound
from webhelpers.html import HTML, tags
from tailbone import forms
from tailbone.views import MasterView, AutocompleteView
from rattail.db import model
@ -74,6 +75,9 @@ class PeopleView(MasterView):
g.filters['phone'] = g.make_filter('phone', model.PersonPhoneNumber.number,
label="Phone Number")
g.joiners['customer_id'] = lambda q: q.outerjoin(model.CustomerPerson).outerjoin(model.Customer)
g.filters['customer_id'] = g.make_filter('customer_id', model.Customer.id, label="Customer ID")
g.filters['first_name'].default_active = True
g.filters['first_name'].default_verb = 'contains'
@ -122,6 +126,7 @@ class PeopleView(MasterView):
fs.phone.set(label="Phone Number", readonly=True)
fs.email.set(label="Email Address", readonly=True)
fs.address.set(label="Mailing Address", readonly=True)
fs.employee.set(renderer=forms.renderers.EmployeeFieldRenderer, attrs={'hyperlink': True})
fs._customers.set(renderer=CustomersFieldRenderer, readonly=True)
def configure_fieldset(self, fs):
@ -134,6 +139,7 @@ class PeopleView(MasterView):
fs.phone,
fs.email,
fs.address,
fs.employee,
fs._customers,
])