From 8ac0bb23342174d6a6833990e917661794091680 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 17 Mar 2020 18:50:07 -0500 Subject: [PATCH] Expose default email address, phone number when editing a Person --- .../templates/people/view_profile_buefy.mako | 6 ++++ tailbone/views/customers.py | 10 +----- tailbone/views/master.py | 16 ++++++++- tailbone/views/people.py | 36 +++++++++++++++++-- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/tailbone/templates/people/view_profile_buefy.mako b/tailbone/templates/people/view_profile_buefy.mako index e683ce17..d44fd66a 100644 --- a/tailbone/templates/people/view_profile_buefy.mako +++ b/tailbone/templates/people/view_profile_buefy.mako @@ -65,6 +65,12 @@ + + {{ address.display }} + +
${self.render_customer_panel_buttons(customer)} diff --git a/tailbone/views/customers.py b/tailbone/views/customers.py index 084ee783..210393c1 100644 --- a/tailbone/views/customers.py +++ b/tailbone/views/customers.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2019 Lance Edgar +# Copyright © 2010-2020 Lance Edgar # # This file is part of Rattail. # @@ -263,14 +263,6 @@ class CustomersView(MasterView): if query.count(): raise colander.Invalid(node, "Customer ID must be unique") - def render_default_email(self, customer, field): - if customer.emails: - return customer.emails[0].address - - def render_default_phone(self, customer, field): - if customer.phones: - return customer.phones[0].number - def render_default_address(self, customer, field): if customer.addresses: return six.text_type(customer.addresses[0]) diff --git a/tailbone/views/master.py b/tailbone/views/master.py index 016ea41a..4c5aacc3 100644 --- a/tailbone/views/master.py +++ b/tailbone/views/master.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2019 Lance Edgar +# Copyright © 2010-2020 Lance Edgar # # This file is part of Rattail. # @@ -847,6 +847,20 @@ class MasterView(View): 'importer_host_title': importer_host_title, }) + def render_default_phone(self, obj, field): + """ + Render the "default" (first) phone number for the given contact. + """ + if obj.phones: + return obj.phones[0].number + + def render_default_email(self, obj, field): + """ + Render the "default" (first) email address for the given contact. + """ + if obj.emails: + return obj.emails[0].address + def render_product_key_value(self, obj): """ Render the "canonical" product key value for the given object. diff --git a/tailbone/views/people.py b/tailbone/views/people.py index ef78c91f..eb3f39fa 100644 --- a/tailbone/views/people.py +++ b/tailbone/views/people.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2019 Lance Edgar +# Copyright © 2010-2020 Lance Edgar # # This file is part of Rattail. # @@ -52,8 +52,14 @@ class PeopleView(MasterView): has_versions = True supports_mobile = True bulk_deletable = True + is_contact = True manage_notes_from_profile_view = False + labels = { + 'default_phone': "Phone Number", + 'default_email': "Email Address", + } + grid_columns = [ 'display_name', 'first_name', @@ -67,8 +73,8 @@ class PeopleView(MasterView): 'middle_name', 'last_name', 'display_name', - 'phone', - 'email', + 'default_phone', + 'default_email', 'address', 'employee', 'customers', @@ -197,15 +203,26 @@ class PeopleView(MasterView): def configure_common_form(self, f): super(PeopleView, self).configure_common_form(f) + person = f.model_instance f.set_label('display_name', "Full Name") + # TODO: should remove this? f.set_readonly('phone') f.set_label('phone', "Phone Number") + f.set_renderer('default_phone', self.render_default_phone) + if not self.creating and person.phones: + f.set_default('default_phone', person.phones[0].number) + + # TODO: should remove this? f.set_readonly('email') f.set_label('email', "Email Address") + f.set_renderer('default_email', self.render_default_email) + if not self.creating and person.emails: + f.set_default('default_email', person.emails[0].address) + f.set_readonly('address') f.set_label('address', "Mailing Address") @@ -319,6 +336,17 @@ class PeopleView(MasterView): 'view_profile_url': self.get_action_url('view_profile', person), } + def get_context_address(self, address): + return { + 'uuid': address.uuid, + 'street': address.street, + 'street2': address.street2, + 'city': address.city, + 'state': address.state, + 'zipcode': address.zipcode, + 'display': six.text_type(address), + } + def get_context_customers(self, person): data = [] for cp in person._customers: @@ -333,6 +361,8 @@ class PeopleView(MasterView): uuid=customer.uuid), 'people': [self.get_context_person(p) for p in customer.people], + 'addresses': [self.get_context_address(a) + for a in customer.addresses], }) return data