From 27a93e1ac8d588e05f8ce224281b63de9e000240 Mon Sep 17 00:00:00 2001 From: Brad Campbell Date: Mon, 29 Apr 2019 18:57:46 -0400 Subject: [PATCH] consolidate user role string code no need for it to be in views_admin and copied twice --- chezbetty/models/user.py | 9 +++++++++ chezbetty/templates/admin/users_list.jinja2 | 2 +- chezbetty/templates/admin/users_stats.jinja2 | 2 +- chezbetty/views_admin.py | 17 +++-------------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/chezbetty/models/user.py b/chezbetty/models/user.py index d1c95a3..9227c92 100644 --- a/chezbetty/models/user.py +++ b/chezbetty/models/user.py @@ -352,6 +352,15 @@ def check_password(self, cand): def has_password(self): return self._password != None + @property + def role_human_readable(self): + roles = {'user': 'User', + 'volunteer': 'Volunteer', + 'serviceaccount': 'Service Account', + 'manager': 'Manager', + 'administrator': 'Administrator'} + return roles[self.role] + def get_user(request): login = authenticated_userid(request) diff --git a/chezbetty/templates/admin/users_list.jinja2 b/chezbetty/templates/admin/users_list.jinja2 index 1b5222f..2ccc0f0 100644 --- a/chezbetty/templates/admin/users_list.jinja2 +++ b/chezbetty/templates/admin/users_list.jinja2 @@ -36,7 +36,7 @@ {{ user|make_link|safe }} {{ user.uniqname }} - {{ roles[user.role] }} + {{ user.role_human_readable }} {{ user.balance|format_currency|safe }} {% if user_page == 'archived' %} {{ user.archived_balance|format_currency|safe }} diff --git a/chezbetty/templates/admin/users_stats.jinja2 b/chezbetty/templates/admin/users_stats.jinja2 index 6a2bf0a..d7cead6 100644 --- a/chezbetty/templates/admin/users_stats.jinja2 +++ b/chezbetty/templates/admin/users_stats.jinja2 @@ -32,7 +32,7 @@ {% for user in normal_users %} {{ user|make_link|safe }} - {{ roles[user.role] }} + {{ user.role_human_readable }} {{ user.balance|format_currency|safe }} {{ user.days_since_last_purchase }} {{ user.created_at|pretty_date|safe }} diff --git a/chezbetty/views_admin.py b/chezbetty/views_admin.py index 6e7484a..d137d7e 100644 --- a/chezbetty/views_admin.py +++ b/chezbetty/views_admin.py @@ -2288,14 +2288,8 @@ def admin_users_list(request): users = User.get_disabled_users() page = 'disabled' - roles = {'user': 'User', - 'volunteer': 'Volunteer', - 'serviceaccount': 'Service Account', - 'manager': 'Manager', - 'administrator': 'Administrator'} return {'users': users, - 'user_page': page, - 'roles': roles} + 'user_page': page} @view_config(route_name='admin_users_stats', @@ -2305,16 +2299,11 @@ def admin_users_stats(request): normal_users = User.get_normal_users() archived_users = User.get_archived_users() disabled_users = User.get_disabled_users() - roles = {'user': 'User', - 'volunteer': 'Volunteer', - 'serviceaccount': 'Service Account', - 'manager': 'Manager', - 'administrator': 'Administrator'} + return {'normal_users': normal_users, 'archived_users': archived_users, 'disabled_users': disabled_users, - 'user_page': 'stats', - 'roles': roles} + 'user_page': 'stats'} @view_config(route_name='admin_uniqname',