From f216996d8931bb4ca5f8c537592db72d84334a42 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Fri, 29 Sep 2017 07:38:36 +0200 Subject: [PATCH] modified role filter as query parameter --- ordr2/resources/admin.py | 12 ++++++++---- ordr2/views/admin.py | 6 ++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ordr2/resources/admin.py b/ordr2/resources/admin.py index 044d90f..a41b850 100644 --- a/ordr2/resources/admin.py +++ b/ordr2/resources/admin.py @@ -1,7 +1,7 @@ from pyramid.security import Allow, Authenticated, Deny, Everyone from .base import BaseResource, PaginationResourceMixin -from ordr2.models import User +from ordr2.models import User, Role @@ -24,10 +24,14 @@ class UserList(BaseResource, PaginationResourceMixin): def prepare_filtered_query(self, dbsession, filter_params): ''' setup the base filtered query ''' query = dbsession.query(self.sql_model_class) - role = filter_params.get('role', None) - if role is not None: + role_name = filter_params.get('role', None) + try: + role_name = role_name.lower() + role = Role(role_name) query = query.filter_by(role=role) - self.filters['role'] = role + except (AttributeError, ValueError): + role_name = None + self.filters['role'] = role_name return query diff --git a/ordr2/views/admin.py b/ordr2/views/admin.py index 93b4a04..dd26e31 100644 --- a/ordr2/views/admin.py +++ b/ordr2/views/admin.py @@ -26,7 +26,9 @@ def admin_section(context, request): '''Please take a look at them and confirm or reject the registration by setting the role accordingly. This message will disappear when all new registrations have been - processed.'''.format(request.resource_url(context, 'users')) + processed.'''.format( + request.resource_url(context, 'users', query={'role': 'new'}) + ) ) return {} @@ -39,5 +41,5 @@ def admin_section(context, request): def user_list(context, request): ''' display the user list ''' users = context.items() - roles = [(role.name, role.value.capitalize()) for role in Role] + roles = [(role.value.lower(), role.value.capitalize()) for role in Role] return {'users':users, 'roles':roles}