Browse Source

modified role filter as query parameter

php2python
Holger Frey 7 years ago
parent
commit
f216996d89
  1. 12
      ordr2/resources/admin.py
  2. 6
      ordr2/views/admin.py

12
ordr2/resources/admin.py

@ -1,7 +1,7 @@
from pyramid.security import Allow, Authenticated, Deny, Everyone from pyramid.security import Allow, Authenticated, Deny, Everyone
from .base import BaseResource, PaginationResourceMixin 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): def prepare_filtered_query(self, dbsession, filter_params):
''' setup the base filtered query ''' ''' setup the base filtered query '''
query = dbsession.query(self.sql_model_class) query = dbsession.query(self.sql_model_class)
role = filter_params.get('role', None) role_name = filter_params.get('role', None)
if role is not None: try:
role_name = role_name.lower()
role = Role(role_name)
query = query.filter_by(role=role) query = query.filter_by(role=role)
self.filters['role'] = role except (AttributeError, ValueError):
role_name = None
self.filters['role'] = role_name
return query return query

6
ordr2/views/admin.py

@ -26,7 +26,9 @@ def admin_section(context, request):
'''Please <a href="{}">take a look at them</a> and confirm or '''Please <a href="{}">take a look at them</a> and confirm or
reject the registration by setting the role accordingly. This reject the registration by setting the role accordingly. This
message will disappear when all new registrations have been 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 {} return {}
@ -39,5 +41,5 @@ def admin_section(context, request):
def user_list(context, request): def user_list(context, request):
''' display the user list ''' ''' display the user list '''
users = context.items() 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} return {'users':users, 'roles':roles}