diff --git a/tailbone/templates/members/view.mako b/tailbone/templates/members/view.mako new file mode 100644 index 00000000..1af22f98 --- /dev/null +++ b/tailbone/templates/members/view.mako @@ -0,0 +1,17 @@ +## -*- coding: utf-8; -*- +<%inherit file="/master/view.mako" /> +<%namespace file="/util.mako" import="view_profiles_helper" /> + +<%def name="object_helpers()"> + ${parent.object_helpers()} + <% people = [] %> + % if instance.person: + <% people.append(instance.person) %> + % endif + % if instance.customer: + <% people.extend(instance.customer.people) %> + % endif + ${view_profiles_helper(people)} +%def> + +${parent.body()} diff --git a/tailbone/templates/people/view_profile_buefy.mako b/tailbone/templates/people/view_profile_buefy.mako index d44fd66a..c10b808b 100644 --- a/tailbone/templates/people/view_profile_buefy.mako +++ b/tailbone/templates/people/view_profile_buefy.mako @@ -9,6 +9,76 @@ ${self.page_content()} %def> +<%def name="render_member_tab()"> + + + + + + {{ person.display_name }} is associated with {{ members.length }} member account(s) + + + + + + + + + #{{ member.id }} {{ member.display }} + + + + + + + + {{ member.id }} + + + + {{ member.active }} + + + + {{ member.joined }} + + + + {{ member.withdrew }} + + + + + ${self.render_member_panel_buttons(member)} + + + + + + + + {{ person.display_name }} has never had a member account. + + + +%def> + +<%def name="render_member_panel_buttons(member)"> + % if request.has_perm('members.view'): + + View Member + + % endif +%def> + <%def name="render_customer_tab()"> @@ -236,6 +306,8 @@ ${self.render_customer_tab()} + ${self.render_member_tab()} + % if employee: @@ -402,6 +474,7 @@ activeTab: 0, person: ${json.dumps(person_data)|n}, customers: ${json.dumps(customers_data)|n}, + members: ${json.dumps(members_data)|n}, } }, } diff --git a/tailbone/views/customers.py b/tailbone/views/customers.py index 210393c1..cdb44429 100644 --- a/tailbone/views/customers.py +++ b/tailbone/views/customers.py @@ -92,6 +92,7 @@ class CustomersView(MasterView): 'active_in_pos_sticky', 'people', 'groups', + 'members', ] mobile_form_fields = [ @@ -250,6 +251,18 @@ class CustomersView(MasterView): f.set_renderer('groups', self.render_groups) f.set_readonly('groups') + def configure_form(self, f): + super(CustomersView, self).configure_form(f) + customer = f.model_instance + permission_prefix = self.get_permission_prefix() + + # members + if self.creating: + f.remove_field('members') + else: + f.set_renderer('members', self.render_members) + f.set_readonly('members') + def template_kwargs_view(self, **kwargs): kwargs['show_profiles_helper'] = self.show_profiles_helper return kwargs @@ -336,6 +349,17 @@ class CustomersView(MasterView): items.append(HTML.tag('li', tags.link_to(text, url))) return HTML.tag('ul', HTML.literal('').join(items)) + def render_members(self, customer, field): + members = customer.members + if not members: + return "" + items = [] + for member in members: + text = six.text_type(member) + url = self.request.route_url('members.view', uuid=member.uuid) + items.append(HTML.tag('li', tags.link_to(text, url))) + return HTML.tag('ul', HTML.literal('').join(items)) + def get_version_child_classes(self): return [ (model.CustomerPhoneNumber, 'parent_uuid'), diff --git a/tailbone/views/members.py b/tailbone/views/members.py index a39fb8c1..f887ae9f 100644 --- a/tailbone/views/members.py +++ b/tailbone/views/members.py @@ -113,7 +113,7 @@ class MemberView(MasterView): def grid_extra_class(self, member, i): if not member.active: return 'warning' - if not member.equity_current: + if member.equity_current is False: return 'notice' def configure_form(self, f): @@ -158,7 +158,7 @@ class MemberView(MasterView): f.set_label('customer_uuid', "Customer") else: f.set_readonly('customer') - # f.set_renderer('customer', self.render_customer) + f.set_renderer('customer', self.render_customer) # default_email f.set_renderer('default_email', self.render_default_email) diff --git a/tailbone/views/people.py b/tailbone/views/people.py index eb3f39fa..402cd493 100644 --- a/tailbone/views/people.py +++ b/tailbone/views/people.py @@ -32,6 +32,7 @@ from sqlalchemy import orm from rattail.db import model, api from rattail.time import localtime +from rattail.util import OrderedDict import colander from pyramid.httpexceptions import HTTPFound, HTTPNotFound @@ -316,6 +317,7 @@ class PeopleView(MasterView): 'today': localtime(self.rattail_config).date(), 'person_data': self.get_context_person(person), 'customers_data': self.get_context_customers(person), + 'members_data': self.get_context_members(person), 'employee': employee, 'employee_view_url': self.request.route_url('employees.view', uuid=employee.uuid) if employee else None, 'employee_history': employee.get_current_history() if employee else None, @@ -366,6 +368,30 @@ class PeopleView(MasterView): }) return data + def get_context_members(self, person): + data = OrderedDict() + + for member in person.members: + data[member.uuid] = self.get_context_member(member) + + for customer in person.customers: + for member in customer.members: + if member.uuid not in data: + data[member.uuid] = self.get_context_member(member) + + return list(data.values()) + + def get_context_member(self, member): + return { + 'uuid': member.uuid, + 'id': member.id, + 'active': member.active, + 'joined': six.text_type(member.joined) if member.joined else None, + 'withdrew': six.text_type(member.withdrew) if member.withdrew else None, + 'display': six.text_type(member), + 'view_url': self.request.route_url('members.view', uuid=member.uuid), + } + def get_context_employee_history(self, employee): data = [] if employee:
{{ person.display_name }} is associated with {{ members.length }} member account(s)
{{ person.display_name }} has never had a member account.