Skip to content

Commit

Permalink
consolidate user role string code
Browse files Browse the repository at this point in the history
no need for it to be in views_admin and copied twice
  • Loading branch information
bradjc committed Apr 29, 2019
1 parent 75ebc28 commit 27a93e1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
9 changes: 9 additions & 0 deletions chezbetty/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion chezbetty/templates/admin/users_list.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<tr id="user-{{ user.id }}" class="edit-user-row {% if user.enabled == False %} disabled-row {% endif %}">
<td data-value="{{ user.name }}">{{ user|make_link|safe }}</td>
<td data-value="{{ user.uniqname }}">{{ user.uniqname }}</td>
<td data-value="{{ user.role }}">{{ roles[user.role] }}</td>
<td data-value="{{ user.role }}">{{ user.role_human_readable }}</td>
<td class="right" data-value="{{ user.balance|round(2) }}">{{ user.balance|format_currency|safe }}</td>
{% if user_page == 'archived' %}
<td class="right" data-value="{{ user.archived_balance|round(2) }}">{{ user.archived_balance|format_currency|safe }}</td>
Expand Down
2 changes: 1 addition & 1 deletion chezbetty/templates/admin/users_stats.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{% for user in normal_users %}
<tr id="user-{{ user.id }}" class="edit-user-row {% if user.enabled == False %} disabled-row {% endif %}">
<td data-value="{{ user.name }}">{{ user|make_link|safe }}</td>
<td data-value="{{ user.role }}">{{ roles[user.role] }}</td>
<td data-value="{{ user.role }}">{{ user.role_human_readable }}</td>
<td class="right" data-value="{{ user.balance|round(2) }}">{{ user.balance|format_currency|safe }}</td>
<td data-value="{{ user.days_since_last_purchase }}" class="right">{{ user.days_since_last_purchase }}</td>
<td data-value="{{ user.created_at }}">{{ user.created_at|pretty_date|safe }}</td>
Expand Down
17 changes: 3 additions & 14 deletions chezbetty/views_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit 27a93e1

Please sign in to comment.