rewrote participant overview as class based view

This commit is contained in:
Oskar Hahn 2012-08-10 11:51:45 +02:00
parent f008a4eb0a
commit 29049119f7
4 changed files with 171 additions and 165 deletions

View File

@ -37,7 +37,7 @@ class OpenSlidesUser(models.Model, PersonMixin):
user = models.OneToOneField(User, unique=True, editable=False) user = models.OneToOneField(User, unique=True, editable=False)
category = models.CharField( category = models.CharField(
max_length=100, null=True, blank=True, verbose_name=_("Name Surfix"), max_length=100, null=True, blank=True, verbose_name=_("Category"),
help_text=_('Shown behind the name.')) help_text=_('Shown behind the name.'))
gender = models.CharField( gender = models.CharField(
max_length=50, choices=GENDER_CHOICES, blank=True, max_length=50, choices=GENDER_CHOICES, blank=True,
@ -140,6 +140,7 @@ class OpenSlidesGroup(models.Model, PersonMixin):
group = models.OneToOneField(Group) group = models.OneToOneField(Group)
group_as_person = models.BooleanField(default=False) group_as_person = models.BooleanField(default=False)
description = models.TextField(blank=True)
def __unicode__(self): def __unicode__(self):
return unicode(self.group) return unicode(self.group)
@ -193,4 +194,10 @@ def default_config(sender, key, **kwargs):
@receiver(signals.post_save, sender=User) @receiver(signals.post_save, sender=User)
def user_post_save(sender, instance, signal, *args, **kwargs): def user_post_save(sender, instance, signal, *args, **kwargs):
# Creates OpenSlidesUser # Creates OpenSlidesUser
profile, new = OpenSlidesUser.objects.get_or_create(user=instance) openslidesuser, new = OpenSlidesUser.objects.get_or_create(user=instance)
@receiver(signals.post_save, sender=Group)
def group_post_save(sender, instance, signal, *args, **kwargs):
# Creates OpenSlidesGroup
openslidesgroup, new = OpenSlidesGroup.objects.get_or_create(group=instance)

View File

@ -8,99 +8,105 @@
{% block header %} {% block header %}
{% if perms.agenda.can_manage_agenda %} {% if perms.agenda.can_manage_agenda %}
<link type="text/css" rel="stylesheet" media="all" href="{% static 'styles/participant.css' %}" /> <link type="text/css" rel="stylesheet" media="all" href="{% static 'styles/participant.css' %}" />
<script type="text/javascript" src="{% static 'javascript/participant.js' %}"></script> <script type="text/javascript" src="{% static 'javascript/participant.js' %}"></script>
{% endif %} {% endif %}
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<h1>{% trans "Participants" %}</h1> <h1>{% trans "Participants" %}</h1>
<p><form action="{{request.url}}" name="filter" method="post"> <p>
{% csrf_token %} <form action="" name="filter" method="get">
{% trans "Filter" %}: {% trans "Filter" %}:
<select class="default-input" name="gender" onchange="document.forms['filter'].submit()"> <select class="default-input" name="gender" onchange="document.forms['filter'].submit()">
<option value="---">-- {% trans "Gender" %} --</option> <option value="---">-- {% trans "Gender" %} --</option>
<option value="male" {% if 'male' in sortfilter.gender %}selected{% endif %}>{% trans "Male" %}</option> <option value="male"{% if 'male' in sortfilter.gender %} selected{% endif %}>{% trans "Male" %}</option>
<option value="female" {% if 'female' in sortfilter.gender %}selected{% endif %}>{% trans "Female" %}</option> <option value="female"{% if 'female' in sortfilter.gender %} selected{% endif %}>{% trans "Female" %}</option>
<option value="" {% if '' in sortfilter.gender %}selected{% endif %}>{% trans "Not specified" %}</option> <option value=""{% if '' in sortfilter.gender %} selected{% endif %}>{% trans "Not specified" %}</option>
</select> </select>
<select class="default-input" name="group" onchange="document.forms['filter'].submit()"> <select class="default-input" name="category" onchange="document.forms['filter'].submit()">
<option value="---">-- {% trans "Group" %} --</option> <option value="---">-- {% trans "Category" %} --</option>
{% for group in groups %} {% for category in categories %}
<option value="{{ group }}" {% if group in sortfilter.group %}selected{% endif %}> <option value="{{ category }}"{% if category in sortfilter.category %} selected{% endif %}>
{{ group }}</option> {{ category }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select class="default-input" name="type" onchange="document.forms['filter'].submit()"> <select class="default-input" name="type" onchange="document.forms['filter'].submit()">
<option value="---">-- {% trans "Type" %} --</option> <option value="---">-- {% trans "Type" %} --</option>
<option value="delegate" {% if 'delegate' in sortfilter.type %}selected{% endif %}>{% trans "Delegate" %}</option> <option value="delegate"{% if 'delegate' in sortfilter.type %} selected{% endif %}>{% trans "Delegate" %}</option>
<option value="observer" {% if 'observer' in sortfilter.type %}selected{% endif %}>{% trans "Observer" %}</option> <option value="observer"{% if 'observer' in sortfilter.type %} selected{% endif %}>{% trans "Observer" %}</option>
<option value="staff" {% if 'staff' in sortfilter.type %}selected{% endif %}>{% trans "Staff" %}</option> <option value="staff"{% if 'staff' in sortfilter.type %} selected{% endif %}>{% trans "Staff" %}</option>
<option value="guest" {% if 'guest' in sortfilter.type %}selected{% endif %}>{% trans "Guest" %}</option> <option value="guest"{% if 'guest' in sortfilter.type %} selected{% endif %}>{% trans "Guest" %}</option>
<option value="" {% if '' in sortfilter.type %}selected{% endif %}>{% trans "Not specified" %}</option> <option value=""{% if '' in sortfilter.type %} selected{% endif %}>{% trans "Not specified" %}</option>
</select> </select>
<select class="default-input" name="committee" onchange="document.forms['filter'].submit()"> <select class="default-input" name="committee" onchange="document.forms['filter'].submit()">
<option value="---">-- {% trans "Committee" %} --</option> <option value="---">-- {% trans "Committee" %} --</option>
{% for committee in committees %} {% for committee in committees %}
<option value="{{ committee }}" {% if committee in sortfilter.committee %}selected{% endif %}> <option value="{{ committee }}"{% if committee in sortfilter.committee %} selected{% endif %}>
{{ committee }}</option> {{ committee }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select class="default-input" name="status" onchange="document.forms['filter'].submit()"> <select class="default-input" name="status" onchange="document.forms['filter'].submit()">
<option value="---">-- {% trans "Status" %} --</option> <option value="---">-- {% trans "Status" %} --</option>
<option value="1" {% if '1' in sortfilter.status %}selected{% endif %}>{% trans "Active" %}</option> <option value="1"{% if '1' in sortfilter.status %} selected{% endif %}>{% trans "Active" %}</option>
<option value="0" {% if '0' in sortfilter.status %}selected{% endif %}>{% trans "Inactive" %}</option> <option value="0"{% if '0' in sortfilter.status %} selected{% endif %}>{% trans "Inactive" %}</option>
</select> </select>
</form> </form>
</p> </p>
{% if users|length == allusers|length %} {% if users.count == allusers %}
{{ users|length }} {{ users.count }}
{% blocktrans count counter=users|length %}participant{% plural %}participants{% endblocktrans %} {% blocktrans count counter=users.count %}participant{% plural %}participants{% endblocktrans %}
{% else %} {% else %}
{{ users|length }} {% trans "of" %} {{ allusers|length }} {% trans "Participants" %} (= {{ percent }} %) {{ users.count }} {% trans "of" %} {{ allusers }} {% trans "Participants" %} (= {{ percent }} %)
{% endif %} {% endif %}
<table> <table>
<tr> <tr>
<th><a href="?sort=first_name&reverse={% if 'first_name' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "First Name" %}</a></th> <th><a href="?sort=first_name&reverse={% if 'first_name' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "First Name" %}</a></th>
<th><a href="?sort=last_name&reverse={% if 'last_name' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Last Name" %}</a></th> <th><a href="?sort=last_name&reverse={% if 'last_name' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Last Name" %}</a></th>
<th><a href="?sort=group&reverse={% if 'group' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Group" %}</a></th> <th><a href="?sort=group&reverse={% if 'category' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Category" %}</a></th>
<th><a href="?sort=type&reverse={% if 'type' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Type" %}</a></th> <th><a href="?sort=type&reverse={% if 'type' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Type" %}</a></th>
<th><a href="?sort=committee&reverse={% if 'committee' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Committee" %}</a></th> <th><a href="?sort=committee&reverse={% if 'committee' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Committee" %}</a></th>
{% if perms.participant.can_manage_participant %} {% if perms.participant.can_manage_participant %}
<th><a href="?sort=comment&reverse={% if 'comment' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Comment" %}</a></th> <th><a href="?sort=comment&reverse={% if 'comment' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Comment" %}</a></th>
<th><a href="?sort=last_login&reverse={% if 'last_login' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Last Login" %}</a></th> <th><a href="?sort=last_login&reverse={% if 'last_login' in sortfilter.sort and 'reverse' not in sortfilter %}1{% else %}---{%endif%}">{% trans "Last Login" %}</a></th>
<th>{% trans "Actions" %}</th> <th>{% trans "Actions" %}</th>
{% endif %} {% endif %}
</tr> </tr>
{% for user in users %} {% for user in users %}
<tr class="{% cycle '' 'odd' %}"> <tr class="{% cycle '' 'odd' %}">
<td>{{ user.first_name }}</td> <td>{{ user.first_name }}</td>
<td>{{ user.last_name }}</td> <td>{{ user.last_name }}</td>
<td>{{ user.openslidesuser.name_surfix }}</td> <td>{{ user.openslidesuser.category }}</td>
<td>{{ user.openslidesuser.get_type_display }}</td> <td>{{ user.openslidesuser.get_type_display }}</td>
<td>{{ user.openslidesuser.committee }}</td> <td>{{ user.openslidesuser.committee }}</td>
{% if perms.participant.can_manage_participant %} {% if perms.participant.can_manage_participant %}
<td>{{ user.openslidesuser.comment|first_line }}</td> <td>{{ user.openslidesuser.comment|first_line }}</td>
<td>{% if user.last_login > user.date_joined %} <td>
{{ user.last_login }} {% if user.last_login > user.date_joined %}
{% endif %}</td> {{ user.last_login }}
<td><span style="width: 1px; white-space: nowrap;"> {% endif %}
<a href="{% url user_edit user.id %}"><img src="{% static 'images/icons/edit.png' %}" title="{% trans 'Edit participant' %}"></a> </td>
<a href="{% url user_delete user.id %}"><img src="{% static 'images/icons/delete.png' %}" title="{% trans 'Delete participant' %}"></a> <td>
<a class="status_link {% if user.is_active %}active{% endif %}" <span style="width: 1px; white-space: nowrap;">
href="{% url user_status user.id %}" <a href="{% url user_edit user.id %}">
title="{% trans 'Change status (active/inactive)' %}"> <img src="{% static 'images/icons/edit.png' %}" title="{% trans 'Edit participant' %}">
<span></span> </a>
</a> <a href="{% url user_delete user.id %}">
</span> <img src="{% static 'images/icons/delete.png' %}" title="{% trans 'Delete participant' %}">
</td> </a>
{% endif %} <a class="status_link{% if user.is_active %} active{% endif %}" href="{% url user_status user.id %}" title="{% trans 'Change status (active/inactive)' %}">
</tr> <span></span>
{% empty %} </a>
<tr> </span>
<td colspan="9"><i>{% trans "No participants available." %}</i></td> </td>
</tr> {% endif %}
{% endfor %} </tr>
{% empty %}
<tr>
<td colspan="9"><i>{% trans "No participants available." %}</i></td>
</tr>
{% endfor %}
</table> </table>
{% endblock %} {% endblock %}

View File

@ -13,12 +13,12 @@
from django.conf.urls.defaults import url, patterns from django.conf.urls.defaults import url, patterns
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from openslides.participant.views import (ParticipantsListPDF, from openslides.participant.views import (
ParticipantsPasswordsPDF) ParticipantsListPDF, ParticipantsPasswordsPDF, Overview)
urlpatterns = patterns('openslides.participant.views', urlpatterns = patterns('openslides.participant.views',
url(r'^$', url(r'^$',
'get_overview', Overview.as_view(),
name='user_overview', name='user_overview',
), ),

View File

@ -43,7 +43,7 @@ from openslides.utils.template import Tab
from openslides.utils.utils import ( from openslides.utils.utils import (
template, permission_required, gen_confirm_form, ajax_request, decodedict, template, permission_required, gen_confirm_form, ajax_request, decodedict,
encodedict, delete_default_permissions, html_strong) encodedict, delete_default_permissions, html_strong)
from openslides.utils.views import FormView, PDFView from openslides.utils.views import FormView, PDFView, TemplateView
from openslides.config.models import config from openslides.config.models import config
@ -54,96 +54,89 @@ from openslides.participant.forms import (
UserImportForm, GroupForm, AdminPasswordChangeForm, ConfigForm) UserImportForm, GroupForm, AdminPasswordChangeForm, ConfigForm)
@permission_required('participant.can_see_participant') class Overview(TemplateView):
@template('participant/overview.html')
def get_overview(request):
""" """
Show all users. Show all participants.
""" """
try: permission_required = 'participant.can_see_participant'
sortfilter = encodedict(parse_qs( template_name = 'participant/overview.html'
request.COOKIES['participant_sortfilter']))
except KeyError:
sortfilter = {}
for value in [u'gender', u'group', u'type', u'committee', u'status', def get_context_data(self, **kwargs):
u'sort', u'reverse']: context = super(Overview, self).get_context_data(**kwargs)
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(
openslidesuser__gender__iexact=sortfilter['gender'][0])
if 'group' in sortfilter:
query = query.filter(
openslidesuser__name_surfix__iexact=sortfilter['group'][0])
if 'type' in sortfilter:
query = query.filter(
openslidesuser__type__iexact=sortfilter['type'][0])
if 'committee' in sortfilter:
query = query.filter(
openslidesuser__committee__iexact=sortfilter['committee'][0])
if 'status' in sortfilter:
query = query.filter(is_active=sortfilter['status'][0])
if 'sort' in sortfilter:
if sortfilter['sort'][0] in ['first_name', 'last_name', 'last_login']:
query = query.order_by(sortfilter['sort'][0])
elif (sortfilter['sort'][0] in
['name_surfix', 'type', 'committee', 'comment']):
query = query.order_by(
'openslidesuser__%s' % sortfilter['sort'][0])
else:
query = query.order_by('last_name')
if 'reverse' in sortfilter:
query = query.reverse()
# list of filtered users
userlist = query.all()
users = []
for user in userlist:
try: try:
user.openslidesuser sortfilter = encodedict(parse_qs(
except OpenSlidesUser.DoesNotExist: self.request.COOKIES['participant_sortfilter']))
pass except KeyError:
sortfilter = {}
for value in [u'gender', u'category', u'type', u'committee', u'status',
u'sort', u'reverse']:
if value in self.request.REQUEST:
if self.request.REQUEST[value] == '---':
try:
del sortfilter[value]
except KeyError:
pass
else:
sortfilter[value] = [self.request.REQUEST[value]]
query = User.objects
if 'gender' in sortfilter:
query = query.filter(
openslidesuser__gender__iexact=sortfilter['gender'][0])
if 'category' in sortfilter:
query = query.filter(
openslidesuser__category__iexact=sortfilter['category'][0])
if 'type' in sortfilter:
query = query.filter(
openslidesuser__type__iexact=sortfilter['type'][0])
if 'committee' in sortfilter:
query = query.filter(
openslidesuser__committee__iexact=sortfilter['committee'][0])
if 'status' in sortfilter:
query = query.filter(is_active=sortfilter['status'][0])
if 'sort' in sortfilter:
if sortfilter['sort'][0] in ['first_name', 'last_name', 'last_login']:
query = query.order_by(sortfilter['sort'][0])
elif (sortfilter['sort'][0] in
['category', 'type', 'committee', 'comment']):
query = query.order_by(
'openslidesuser__%s' % sortfilter['sort'][0])
else: else:
users.append(user) query = query.order_by('last_name')
# list of all existing users
allusers = [] if 'reverse' in sortfilter:
for user in User.objects.all(): query = query.reverse()
try:
user.openslidesuser # list of filtered users
except OpenSlidesUser.DoesNotExist: users = query.all()
pass
# list of all existing users
all_users = User.objects.count()
# quotient of selected users and all users
if all_users > 0:
percent = float(len(users)) * 100 / float(all_users)
else: else:
allusers.append(user) percent = 0
# quotient of selected users and all users
if len(allusers) > 0: # list of all existing categories
percent = float(len(users)) * 100 / float(len(allusers)) categories = [p['category'] for p in OpenSlidesUser.objects.values('category')
else: .exclude(category='').distinct()]
percent = 0
# list of all existing groups # list of all existing committees
groups = [p['name_surfix'] for p in OpenSlidesUser.objects.values('name_surfix') committees = [p['committee'] for p in OpenSlidesUser.objects.values('committee')
.exclude(name_surfix='').distinct()] .exclude(committee='').distinct()]
# list of all existing committees context.update({
committees = [p['committee'] for p in OpenSlidesUser.objects.values('committee') 'users': users,
.exclude(committee='').distinct()] 'allusers': all_users,
return { 'percent': round(percent, 1),
'users': users, 'categories': categories,
'allusers': allusers, 'committees': committees,
'percent': round(percent, 1), 'cookie': ['participant_sortfilter', urlencode(decodedict(sortfilter),
'groups': groups, doseq=True)],
'committees': committees, 'sortfilter': sortfilter})
'cookie': ['participant_sortfilter', urlencode(decodedict(sortfilter), return context
doseq=True)],
'sortfilter': sortfilter,
}
@permission_required('participant.can_manage_participant') @permission_required('participant.can_manage_participant')