From 97327a3b17c13d8d27839569379f6bfc55d4c8fa Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 10 Sep 2011 00:16:57 +0200 Subject: [PATCH] rewrote the filter and sort system for participant --- .../templates/participant/overview.html | 37 +++++++------- openslides/participant/views.py | 49 +++++++++++++------ 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/openslides/participant/templates/participant/overview.html b/openslides/participant/templates/participant/overview.html index 6a4eedc8f..1685bbadb 100644 --- a/openslides/participant/templates/participant/overview.html +++ b/openslides/participant/templates/participant/overview.html @@ -4,32 +4,33 @@ {% block content %}

{% trans "Participants" %}

-

+

+ {% csrf_token %} {%trans "Filter" %}: @@ -38,15 +39,15 @@ {{ users|length }} {% trans "Participant" %} - - - - - + + + + + {% if perms.participant.can_manage_participant %} - - - + + + {% endif %} diff --git a/openslides/participant/views.py b/openslides/participant/views.py index b17c0900d..b327d8f17 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -11,6 +11,9 @@ """ import csv +from urllib import urlencode +from urlparse import parse_qs + from django.http import HttpResponse from django.shortcuts import redirect from django.template import RequestContext @@ -33,24 +36,36 @@ from django.db.models import Avg, Max, Min, Count @permission_required('participant.can_see_participant') @template('participant/overview.html') def get_overview(request): - query = User.objects - if 'gender' in request.GET and '---' not in request.GET['gender']: - query = query.filter(profile__gender__iexact=request.GET['gender']) - if 'group' in request.GET and '---' not in request.GET['group']: - query = query.filter(profile__group__iexact=request.GET['group']) - if 'type' in request.GET and '---' not in request.GET['type']: - query = query.filter(profile__type__iexact=request.GET['type']) - if 'committee' in request.GET and '---' not in request.GET['committee']: - query = query.filter(profile__committee__iexact=request.GET['committee']) try: - sort = request.GET['sort'] - if sort in ['first_name', 'last_name','username','last_login','email']: - query = query.order_by(sort) - elif sort in ['group', 'type', 'committee']: - query = query.order_by('profile__%s' % sort) + sortfilter = parse_qs(request.COOKIES['participant_sortfilter']) except KeyError: - pass - if 'reverse' in request.GET: + sortfilter = {} + + for value in ['gender', 'group', 'type', 'committee', 'sort', 'reverse']: + if value in request.REQUEST: + if request.REQUEST[value] == '---': + try: + del sortfilter[value] + except KeyError: + pass + else: + sortfilter[value] = [request.REQUEST[value]] + + query = User.objects + if 'gender' in sortfilter: + query = query.filter(profile__gender__iexact=sortfilter['gender'][0]) + if 'group' in sortfilter: + query = query.filter(profile__group__iexact=sortfilter['group'][0]) + if 'type' in sortfilter: + query = query.filter(profile__type__iexact=sortfilter['type'][0]) + if 'committee' in sortfilter: + query = query.filter(profile__committee__iexact=sortfilter['committee'][0]) + if 'sort' in sortfilter: + if sortfilter['sort'][0] in ['first_name', 'last_name','username','last_login','email']: + query = query.order_by(sortfilter['sort'][0]) + elif sortfilter['sort'][0] in ['group', 'type', 'committee']: + query = query.order_by('profile__%s' % sortfilter['sort'][0]) + if 'reverse' in sortfilter: query = query.reverse() userlist = query.all() @@ -67,6 +82,8 @@ def get_overview(request): 'users': users, 'groups': groups, 'committees': committees, + 'cookie': ['participant_sortfilter', urlencode(sortfilter, doseq=True)], + 'sortfilter': sortfilter, } @permission_required('participant.can_manage_participant')
{%trans "First Name" %}{%trans "Last Name" %}{%trans "Group" %}{%trans "Type" %}{%trans "Committee" %}{%trans "First Name" %}{%trans "Last Name" %}{%trans "Group" %}{%trans "Type" %}{%trans "Committee" %}{%trans "Username" %}{%trans "Email" %}{%trans "Last Login" %}{%trans "Username" %}{%trans "Email" %}{%trans "Last Login" %} {%trans "Actions" %}