rewrote participant overview as class based view
This commit is contained in:
parent
f008a4eb0a
commit
29049119f7
@ -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)
|
||||||
|
@ -13,11 +13,12 @@
|
|||||||
{% 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>
|
||||||
@ -25,11 +26,11 @@
|
|||||||
<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()">
|
||||||
@ -54,17 +55,17 @@
|
|||||||
</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 %}
|
||||||
@ -77,20 +78,25 @@
|
|||||||
<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>
|
||||||
|
{% if user.last_login > user.date_joined %}
|
||||||
{{ user.last_login }}
|
{{ user.last_login }}
|
||||||
{% endif %}</td>
|
{% endif %}
|
||||||
<td><span style="width: 1px; white-space: nowrap;">
|
</td>
|
||||||
<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>
|
<span style="width: 1px; white-space: nowrap;">
|
||||||
<a class="status_link {% if user.is_active %}active{% endif %}"
|
<a href="{% url user_edit user.id %}">
|
||||||
href="{% url user_status user.id %}"
|
<img src="{% static 'images/icons/edit.png' %}" title="{% trans 'Edit participant' %}">
|
||||||
title="{% trans 'Change status (active/inactive)' %}">
|
</a>
|
||||||
|
<a href="{% url user_delete user.id %}">
|
||||||
|
<img src="{% static 'images/icons/delete.png' %}" title="{% trans 'Delete participant' %}">
|
||||||
|
</a>
|
||||||
|
<a class="status_link{% if user.is_active %} active{% endif %}" href="{% url user_status user.id %}" title="{% trans 'Change status (active/inactive)' %}">
|
||||||
<span></span>
|
<span></span>
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
|
@ -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',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -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,36 +54,39 @@ 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.
|
||||||
"""
|
"""
|
||||||
|
permission_required = 'participant.can_see_participant'
|
||||||
|
template_name = 'participant/overview.html'
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super(Overview, self).get_context_data(**kwargs)
|
||||||
try:
|
try:
|
||||||
sortfilter = encodedict(parse_qs(
|
sortfilter = encodedict(parse_qs(
|
||||||
request.COOKIES['participant_sortfilter']))
|
self.request.COOKIES['participant_sortfilter']))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
sortfilter = {}
|
sortfilter = {}
|
||||||
|
|
||||||
for value in [u'gender', u'group', u'type', u'committee', u'status',
|
for value in [u'gender', u'category', u'type', u'committee', u'status',
|
||||||
u'sort', u'reverse']:
|
u'sort', u'reverse']:
|
||||||
if value in request.REQUEST:
|
if value in self.request.REQUEST:
|
||||||
if request.REQUEST[value] == '---':
|
if self.request.REQUEST[value] == '---':
|
||||||
try:
|
try:
|
||||||
del sortfilter[value]
|
del sortfilter[value]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
sortfilter[value] = [request.REQUEST[value]]
|
sortfilter[value] = [self.request.REQUEST[value]]
|
||||||
|
|
||||||
query = User.objects
|
query = User.objects
|
||||||
if 'gender' in sortfilter:
|
if 'gender' in sortfilter:
|
||||||
query = query.filter(
|
query = query.filter(
|
||||||
openslidesuser__gender__iexact=sortfilter['gender'][0])
|
openslidesuser__gender__iexact=sortfilter['gender'][0])
|
||||||
if 'group' in sortfilter:
|
if 'category' in sortfilter:
|
||||||
query = query.filter(
|
query = query.filter(
|
||||||
openslidesuser__name_surfix__iexact=sortfilter['group'][0])
|
openslidesuser__category__iexact=sortfilter['category'][0])
|
||||||
if 'type' in sortfilter:
|
if 'type' in sortfilter:
|
||||||
query = query.filter(
|
query = query.filter(
|
||||||
openslidesuser__type__iexact=sortfilter['type'][0])
|
openslidesuser__type__iexact=sortfilter['type'][0])
|
||||||
@ -96,54 +99,44 @@ def get_overview(request):
|
|||||||
if sortfilter['sort'][0] in ['first_name', 'last_name', 'last_login']:
|
if sortfilter['sort'][0] in ['first_name', 'last_name', 'last_login']:
|
||||||
query = query.order_by(sortfilter['sort'][0])
|
query = query.order_by(sortfilter['sort'][0])
|
||||||
elif (sortfilter['sort'][0] in
|
elif (sortfilter['sort'][0] in
|
||||||
['name_surfix', 'type', 'committee', 'comment']):
|
['category', 'type', 'committee', 'comment']):
|
||||||
query = query.order_by(
|
query = query.order_by(
|
||||||
'openslidesuser__%s' % sortfilter['sort'][0])
|
'openslidesuser__%s' % sortfilter['sort'][0])
|
||||||
else:
|
else:
|
||||||
query = query.order_by('last_name')
|
query = query.order_by('last_name')
|
||||||
|
|
||||||
if 'reverse' in sortfilter:
|
if 'reverse' in sortfilter:
|
||||||
query = query.reverse()
|
query = query.reverse()
|
||||||
|
|
||||||
# list of filtered users
|
# list of filtered users
|
||||||
userlist = query.all()
|
users = query.all()
|
||||||
users = []
|
|
||||||
for user in userlist:
|
|
||||||
try:
|
|
||||||
user.openslidesuser
|
|
||||||
except OpenSlidesUser.DoesNotExist:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
users.append(user)
|
|
||||||
# list of all existing users
|
# list of all existing users
|
||||||
allusers = []
|
all_users = User.objects.count()
|
||||||
for user in User.objects.all():
|
|
||||||
try:
|
|
||||||
user.openslidesuser
|
|
||||||
except OpenSlidesUser.DoesNotExist:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
allusers.append(user)
|
|
||||||
# quotient of selected users and all users
|
# quotient of selected users and all users
|
||||||
if len(allusers) > 0:
|
if all_users > 0:
|
||||||
percent = float(len(users)) * 100 / float(len(allusers))
|
percent = float(len(users)) * 100 / float(all_users)
|
||||||
else:
|
else:
|
||||||
percent = 0
|
percent = 0
|
||||||
# list of all existing groups
|
|
||||||
groups = [p['name_surfix'] for p in OpenSlidesUser.objects.values('name_surfix')
|
# list of all existing categories
|
||||||
.exclude(name_surfix='').distinct()]
|
categories = [p['category'] for p in OpenSlidesUser.objects.values('category')
|
||||||
|
.exclude(category='').distinct()]
|
||||||
|
|
||||||
# list of all existing committees
|
# list of all existing committees
|
||||||
committees = [p['committee'] for p in OpenSlidesUser.objects.values('committee')
|
committees = [p['committee'] for p in OpenSlidesUser.objects.values('committee')
|
||||||
.exclude(committee='').distinct()]
|
.exclude(committee='').distinct()]
|
||||||
return {
|
context.update({
|
||||||
'users': users,
|
'users': users,
|
||||||
'allusers': allusers,
|
'allusers': all_users,
|
||||||
'percent': round(percent, 1),
|
'percent': round(percent, 1),
|
||||||
'groups': groups,
|
'categories': categories,
|
||||||
'committees': committees,
|
'committees': committees,
|
||||||
'cookie': ['participant_sortfilter', urlencode(decodedict(sortfilter),
|
'cookie': ['participant_sortfilter', urlencode(decodedict(sortfilter),
|
||||||
doseq=True)],
|
doseq=True)],
|
||||||
'sortfilter': sortfilter,
|
'sortfilter': sortfilter})
|
||||||
}
|
return context
|
||||||
|
|
||||||
|
|
||||||
@permission_required('participant.can_manage_participant')
|
@permission_required('participant.can_manage_participant')
|
||||||
|
Loading…
Reference in New Issue
Block a user