From bf1726a52b1b0744373012b9214ca6a4fd19cb02 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 16 Jun 2023 17:04:39 -0500 Subject: [PATCH] Add users context data for profile view instead of using server-side data/logic for users tab --- .../templates/people/view_profile_buefy.mako | 86 +++++++++---------- tailbone/views/people.py | 18 ++++ 2 files changed, 59 insertions(+), 45 deletions(-) diff --git a/tailbone/templates/people/view_profile_buefy.mako b/tailbone/templates/people/view_profile_buefy.mako index dacbe083..eaaf9422 100644 --- a/tailbone/templates/people/view_profile_buefy.mako +++ b/tailbone/templates/people/view_profile_buefy.mako @@ -1038,61 +1038,56 @@ <%def name="render_user_tab()"> - % if person.users: -

${person} is associated with ${len(person.users)} user account(s)

-
-
- % for user in person.users: + icon-pack="fas" + :icon="users.length ? 'check' : null"> - +
-
- ${user.username} -
+

{{ person.display_name }} is associated with {{ users.length }} user account(s)

+
+
-
+ -
+
+ {{ user.username }} +
-
- -
-
- -
- ${user.username} -
-
-
+
+
+
+
+
+ +
+ {{ user.username }}
- -
- % if request.has_perm('users.view'): - ${h.link_to("View User", url('users.view', uuid=user.uuid), class_='button')} - % endif -
-
-
- - % endfor -
+
- % else: -

${person} has never been a user.

- % endif +
+ % if request.has_perm('users.view'): + + View User + + % endif +
+ +
+
+ +
+
+ +
+

{{ person.display_name }} has never been a user.

+
@@ -1791,6 +1786,7 @@ members: ${json.dumps(members_data)|n}, employee: ${json.dumps(employee_data)|n}, employeeHistory: ${json.dumps(employee_history_data)|n}, + users: ${json.dumps(users_data)|n}, phoneTypeOptions: ${json.dumps(phone_type_options)|n}, emailTypeOptions: ${json.dumps(email_type_options)|n}, maxLengths: ${json.dumps(max_lengths)|n}, diff --git a/tailbone/views/people.py b/tailbone/views/people.py index 5b7ffdc4..48e445e9 100644 --- a/tailbone/views/people.py +++ b/tailbone/views/people.py @@ -459,6 +459,7 @@ class PersonView(MasterView): '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, 'employee_history_data': self.get_context_employee_history(employee), + 'users_data': self.get_context_users(person), 'dynamic_content_title': self.get_context_content_title(person), } @@ -720,6 +721,23 @@ class PersonView(MasterView): }) return data + def get_context_users(self, person): + data = [] + users = person.users + for user in users: + data.append(self.get_context_user(user)) + return data + + def get_context_user(self, user): + app = self.get_rattail_app() + return { + 'uuid': user.uuid, + 'username': user.username, + 'display_name': user.display_name, + 'email_address': app.get_contact_email_address(user), + 'view_url': self.request.route_url('users.view', uuid=user.uuid), + } + def ensure_customer(self, person): """ Return the `Customer` record for the given person, establishing it