diff --git a/tailbone/views/customers.py b/tailbone/views/customers.py index f009295a..04db6de2 100644 --- a/tailbone/views/customers.py +++ b/tailbone/views/customers.py @@ -136,6 +136,7 @@ class CustomersView(MasterView): g.set_link('id') g.set_link('number') g.set_link('name') + g.set_link('person') def get_mobile_data(self, session=None): # TODO: hacky! @@ -172,7 +173,9 @@ class CustomersView(MasterView): raise HTTPNotFound def configure_form(self, f): - super(CustomersView, self).configure_form(f) + if not self.mobile: + super(CustomersView, self).configure_form(f) + customer = f.model_instance permission_prefix = self.get_permission_prefix() @@ -196,6 +199,13 @@ class CustomersView(MasterView): preferences.insert(0, ('', "(no preference)")) f.set_widget('email_preference', dfwidget.SelectWidget(values=preferences)) + # person + if self.creating: + f.remove_field('person') + else: + f.set_readonly('person') + f.set_renderer('person', self.form_render_person) + # people if self.creating: f.remove_field('people') @@ -212,6 +222,10 @@ class CustomersView(MasterView): f.set_renderer('groups', self.render_groups) f.set_readonly('groups') + def configure_mobile_form(self, f): + super(CustomersView, self).configure_mobile_form(f) + self.configure_form(f) + def objectify(self, form, data): customer = super(CustomersView, self).objectify(form, data) customer = self.objectify_contact(customer, data) @@ -230,6 +244,12 @@ class CustomersView(MasterView): return six.text_type(customer.addresses[0]) def grid_render_person(self, customer, field): + person = getattr(customer, field) + if not person: + return "" + return six.text_type(person) + + def form_render_person(self, customer, field): person = getattr(customer, field) if not person: return "" @@ -245,9 +265,12 @@ class CustomersView(MasterView): items = [] for person in people: - link = tags.link_to(person, self.request.route_url('people.view', uuid=person.uuid)) - items.append(HTML.tag('li', link)) - return HTML.tag('ul', HTML.literal('').join(items)) + text = six.text_type(person) + route = '{}people.view'.format('mobile.' if self.mobile else '') + url = self.request.route_url(route, uuid=person.uuid) + link = tags.link_to(text, url) + items.append(HTML.tag('li', c=[link])) + return HTML.tag('ul', c=items) def render_people_removable(self, customer, field): people = customer.people diff --git a/tailbone/views/people.py b/tailbone/views/people.py index 2f63e3ad..5060cc18 100644 --- a/tailbone/views/people.py +++ b/tailbone/views/people.py @@ -45,6 +45,7 @@ class PeopleView(MasterView): model_title_plural = "People" route_prefix = 'people' has_versions = True + supports_mobile = True grid_columns = [ 'display_name', @@ -67,6 +68,19 @@ class PeopleView(MasterView): 'users', ] + mobile_form_fields = [ + 'first_name', + 'middle_name', + 'last_name', + 'display_name', + 'phone', + 'email', + 'address', + 'employee', + 'customers', + 'users', + ] + def configure_grid(self, g): super(PeopleView, self).configure_grid(g) @@ -126,7 +140,8 @@ class PeopleView(MasterView): return True def configure_form(self, f): - super(PeopleView, self).configure_form(f) + if not self.mobile: + super(PeopleView, self).configure_form(f) f.set_label('display_name', "Full Name") @@ -148,6 +163,10 @@ class PeopleView(MasterView): f.set_readonly('users') f.set_renderer('users', self.render_users) + def configure_mobile_form(self, f): + super(PeopleView, self).configure_mobile_form(f) + self.configure_form(f) + def render_employee(self, person, field): employee = person.employee if not employee: @@ -168,7 +187,8 @@ class PeopleView(MasterView): text = "({}) {}".format(customer.id, text) elif customer.number: text = "({}) {}".format(customer.number, text) - url = self.request.route_url('customers.view', uuid=customer.uuid) + route = '{}customers.view'.format('mobile.' if self.mobile else '') + url = self.request.route_url(route, uuid=customer.uuid) items.append(HTML.tag('li', c=[tags.link_to(text, url)])) return HTML.tag('ul', c=items)