2011-07-31 10:46:29 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
openslides.participant.views
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Views for the participant app.
|
|
|
|
|
2012-04-25 22:29:19 +02:00
|
|
|
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
|
2011-07-31 10:46:29 +02:00
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
# for python 2.5 support
|
2011-11-29 11:02:31 +01:00
|
|
|
from __future__ import with_statement
|
|
|
|
|
2011-09-10 00:16:57 +02:00
|
|
|
from urllib import urlencode
|
2012-04-13 11:35:53 +02:00
|
|
|
|
2011-09-12 08:32:05 +02:00
|
|
|
try:
|
|
|
|
from urlparse import parse_qs
|
2012-08-08 10:34:23 +02:00
|
|
|
except ImportError: # python <= 2.5 grab it from cgi
|
2011-09-12 08:32:05 +02:00
|
|
|
from cgi import parse_qs
|
2011-09-10 00:16:57 +02:00
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
from reportlab.lib import colors
|
|
|
|
from reportlab.lib.units import cm
|
2012-08-08 10:34:23 +02:00
|
|
|
from reportlab.platypus import (
|
2012-08-11 10:51:52 +02:00
|
|
|
SimpleDocTemplate, Paragraph, LongTable, Spacer, Table, TableStyle)
|
2012-07-07 15:26:00 +02:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
from django.contrib import messages
|
2012-07-07 15:26:00 +02:00
|
|
|
from django.contrib.auth.decorators import login_required
|
2012-07-11 09:46:15 +02:00
|
|
|
from django.contrib.auth.forms import PasswordChangeForm
|
2012-08-11 11:09:20 +02:00
|
|
|
from django.contrib.auth.models import User
|
2012-07-18 10:46:07 +02:00
|
|
|
from django.contrib.auth.views import login as django_login
|
2011-07-31 10:46:29 +02:00
|
|
|
from django.core.urlresolvers import reverse
|
2012-07-07 15:26:00 +02:00
|
|
|
from django.shortcuts import redirect
|
2012-08-11 10:51:52 +02:00
|
|
|
from django.utils.translation import ugettext as _, ugettext_lazy
|
2012-04-20 23:23:50 +02:00
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
from openslides.utils.pdf import stylesheet
|
|
|
|
from openslides.utils.template import Tab
|
2012-08-08 10:34:23 +02:00
|
|
|
from openslides.utils.utils import (
|
2012-08-11 10:51:52 +02:00
|
|
|
template, decodedict, encodedict, delete_default_permissions, html_strong)
|
2012-08-10 13:22:09 +02:00
|
|
|
from openslides.utils.views import (
|
2012-08-11 10:51:52 +02:00
|
|
|
FormView, PDFView, CreateView, UpdateView, DeleteView,
|
2012-08-10 21:24:26 +02:00
|
|
|
RedirectView, SingleObjectMixin, ListView, QuestionMixin)
|
2011-09-03 19:42:43 +02:00
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
from openslides.config.models import config
|
2012-04-20 23:23:50 +02:00
|
|
|
|
2012-10-25 23:58:32 +02:00
|
|
|
from openslides.projector.projector import Widget
|
|
|
|
|
|
|
|
from openslides.motion.models import Motion
|
|
|
|
from openslides.assignment.models import Assignment
|
|
|
|
|
2012-08-10 19:49:46 +02:00
|
|
|
from openslides.participant.api import gen_username, gen_password, import_users
|
2012-08-08 10:34:23 +02:00
|
|
|
from openslides.participant.forms import (
|
2012-08-11 10:09:54 +02:00
|
|
|
UserCreateForm, UserUpdateForm, UsersettingsForm,
|
2012-08-11 10:51:52 +02:00
|
|
|
UserImportForm, GroupForm, ConfigForm)
|
2012-08-12 12:52:38 +02:00
|
|
|
from openslides.participant.models import User, Group
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
|
2012-10-27 18:17:22 +02:00
|
|
|
class UserOverview(ListView):
|
2012-07-07 15:26:00 +02:00
|
|
|
"""
|
2012-09-14 03:02:00 +02:00
|
|
|
Show all participants (users).
|
2012-07-07 15:26:00 +02:00
|
|
|
"""
|
2012-08-10 11:51:45 +02:00
|
|
|
permission_required = 'participant.can_see_participant'
|
|
|
|
template_name = 'participant/overview.html'
|
2012-08-10 19:19:41 +02:00
|
|
|
context_object_name = 'users'
|
2012-08-10 11:51:45 +02:00
|
|
|
|
2012-08-10 19:19:41 +02:00
|
|
|
def get_queryset(self):
|
2011-07-31 10:46:29 +02:00
|
|
|
try:
|
2012-08-10 11:51:45 +02:00
|
|
|
sortfilter = encodedict(parse_qs(
|
|
|
|
self.request.COOKIES['participant_sortfilter']))
|
|
|
|
except KeyError:
|
|
|
|
sortfilter = {}
|
|
|
|
|
2012-10-24 12:30:45 +02:00
|
|
|
for value in ['gender', 'detail', 'type', 'committee', 'status',
|
|
|
|
'sort', 'reverse']:
|
2012-08-10 11:51:45 +02:00
|
|
|
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]]
|
|
|
|
|
2012-08-12 12:52:38 +02:00
|
|
|
query = User.objects
|
2012-08-10 11:51:45 +02:00
|
|
|
if 'gender' in sortfilter:
|
2012-08-10 19:19:41 +02:00
|
|
|
query = query.filter(gender__iexact=sortfilter['gender'][0])
|
2012-10-24 12:30:45 +02:00
|
|
|
if 'detail' in sortfilter:
|
|
|
|
query = query.filter(detail__iexact=sortfilter['detail'][0])
|
2012-08-10 11:51:45 +02:00
|
|
|
if 'type' in sortfilter:
|
2012-08-10 19:19:41 +02:00
|
|
|
query = query.filter(type__iexact=sortfilter['type'][0])
|
2012-08-10 11:51:45 +02:00
|
|
|
if 'committee' in sortfilter:
|
2012-08-10 19:19:41 +02:00
|
|
|
query = query.filter(committee__iexact=sortfilter['committee'][0])
|
2012-08-10 11:51:45 +02:00
|
|
|
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
|
2012-10-24 12:30:45 +02:00
|
|
|
['detail', 'type', 'committee', 'comment']):
|
2012-08-10 11:51:45 +02:00
|
|
|
query = query.order_by(
|
2012-08-12 12:52:38 +02:00
|
|
|
'%s' % sortfilter['sort'][0])
|
2012-08-07 22:43:57 +02:00
|
|
|
else:
|
2012-09-14 03:02:00 +02:00
|
|
|
if config['participant_sort_users_by_first_name']:
|
|
|
|
query = query.order_by('first_name')
|
2012-08-10 11:51:45 +02:00
|
|
|
|
|
|
|
if 'reverse' in sortfilter:
|
|
|
|
query = query.reverse()
|
|
|
|
|
2012-08-10 19:19:41 +02:00
|
|
|
self.sortfilter = sortfilter
|
|
|
|
|
|
|
|
return query.all()
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2012-10-27 18:17:22 +02:00
|
|
|
context = super(UserOverview, self).get_context_data(**kwargs)
|
2012-08-10 11:51:45 +02:00
|
|
|
|
2012-08-12 12:52:38 +02:00
|
|
|
all_users = User.objects.count()
|
2012-08-10 11:51:45 +02:00
|
|
|
|
|
|
|
# quotient of selected users and all users
|
|
|
|
if all_users > 0:
|
2012-08-10 19:19:41 +02:00
|
|
|
percent = self.object_list.count() * 100 / float(all_users)
|
2012-08-07 22:43:57 +02:00
|
|
|
else:
|
2012-08-10 11:51:45 +02:00
|
|
|
percent = 0
|
|
|
|
|
|
|
|
# list of all existing categories
|
2012-10-24 12:30:45 +02:00
|
|
|
details = [p['detail'] for p in User.objects.values('detail')
|
|
|
|
.exclude(detail='').distinct()]
|
2012-08-10 11:51:45 +02:00
|
|
|
|
|
|
|
# list of all existing committees
|
2012-08-12 12:52:38 +02:00
|
|
|
committees = [p['committee'] for p in User.objects.values('committee')
|
2012-08-10 11:51:45 +02:00
|
|
|
.exclude(committee='').distinct()]
|
|
|
|
context.update({
|
|
|
|
'allusers': all_users,
|
|
|
|
'percent': round(percent, 1),
|
2012-10-24 12:30:45 +02:00
|
|
|
'details': details,
|
2012-08-10 11:51:45 +02:00
|
|
|
'committees': committees,
|
2012-08-10 19:19:41 +02:00
|
|
|
'cookie': ['participant_sortfilter', urlencode(decodedict(self.sortfilter),
|
2012-08-10 11:51:45 +02:00
|
|
|
doseq=True)],
|
2012-08-10 19:19:41 +02:00
|
|
|
'sortfilter': self.sortfilter})
|
2012-08-10 11:51:45 +02:00
|
|
|
return context
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
|
2012-10-30 00:07:25 +01:00
|
|
|
from openslides.utils.views import DetailView, PermissionMixin
|
|
|
|
class UserDetailView(DetailView, PermissionMixin):
|
2012-10-27 18:17:22 +02:00
|
|
|
"""
|
|
|
|
Classed based view to show a specific user in the interface.
|
|
|
|
"""
|
2012-10-30 00:07:25 +01:00
|
|
|
permission_required = 'participant.can_see_participant'
|
2012-10-27 18:17:22 +02:00
|
|
|
model = User
|
2012-10-30 00:07:25 +01:00
|
|
|
template_name = 'participant/user_detail.html'
|
|
|
|
context_object_name = 'shown_user'
|
2012-10-27 18:17:22 +02:00
|
|
|
|
|
|
|
|
2012-10-30 00:07:25 +01:00
|
|
|
class GroupDetailView(DetailView, PermissionMixin):
|
2012-10-27 18:17:22 +02:00
|
|
|
"""
|
|
|
|
Classed based view to show a specific group in the interface.
|
|
|
|
"""
|
2012-10-30 00:07:25 +01:00
|
|
|
permission_required = 'participant.can_manage_participant'
|
2012-10-27 18:17:22 +02:00
|
|
|
model = Group
|
2012-10-30 00:07:25 +01:00
|
|
|
template_name = 'participant/group_detail.html'
|
|
|
|
context_object_name = 'group'
|
2012-10-27 18:17:22 +02:00
|
|
|
|
|
|
|
|
2012-08-10 13:22:09 +02:00
|
|
|
class UserCreateView(CreateView):
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2012-08-10 13:22:09 +02:00
|
|
|
Create a new participant.
|
2011-07-31 10:46:29 +02:00
|
|
|
"""
|
2012-08-10 13:22:09 +02:00
|
|
|
permission_required = 'participant.can_manage_participant'
|
|
|
|
template_name = 'participant/edit.html'
|
2012-08-12 12:52:38 +02:00
|
|
|
model = User
|
2012-08-10 13:22:09 +02:00
|
|
|
context_object_name = 'edit_user'
|
|
|
|
form_class = UserCreateForm
|
|
|
|
success_url = 'user_overview'
|
2012-08-11 11:09:20 +02:00
|
|
|
apply_url = 'user_edit'
|
2012-08-10 13:22:09 +02:00
|
|
|
|
|
|
|
def manipulate_object(self, form):
|
2012-08-11 10:51:52 +02:00
|
|
|
self.object.username = gen_username(form.cleaned_data['first_name'],
|
|
|
|
form.cleaned_data['last_name'])
|
2012-08-13 14:37:49 +02:00
|
|
|
if not self.object.default_password:
|
|
|
|
self.object.default_password = gen_password()
|
2012-08-15 11:01:38 +02:00
|
|
|
self.object.set_password(self.object.default_password)
|
2012-08-10 13:22:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
class UserUpdateView(UpdateView):
|
2012-08-10 13:29:46 +02:00
|
|
|
"""
|
|
|
|
Update an existing participant.
|
|
|
|
"""
|
2012-08-10 13:22:09 +02:00
|
|
|
permission_required = 'participant.can_manage_participant'
|
|
|
|
template_name = 'participant/edit.html'
|
2012-08-12 12:52:38 +02:00
|
|
|
model = User
|
2012-08-10 13:22:09 +02:00
|
|
|
context_object_name = 'edit_user'
|
|
|
|
form_class = UserUpdateForm
|
|
|
|
success_url = 'user_overview'
|
|
|
|
apply_url = 'participant_edit'
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
|
2012-08-10 13:29:46 +02:00
|
|
|
class UserDeleteView(DeleteView):
|
|
|
|
"""
|
|
|
|
Delete an participant.
|
|
|
|
"""
|
|
|
|
permission_required = 'participant.can_manage_participant'
|
2012-08-12 12:52:38 +02:00
|
|
|
model = User
|
2012-08-10 13:29:46 +02:00
|
|
|
url = 'user_overview'
|
|
|
|
|
|
|
|
|
2012-08-10 19:19:41 +02:00
|
|
|
class SetUserStatusView(RedirectView, SingleObjectMixin):
|
2012-07-07 15:26:00 +02:00
|
|
|
"""
|
2012-08-10 19:19:41 +02:00
|
|
|
Activate or deactivate an user.
|
2012-07-07 15:26:00 +02:00
|
|
|
"""
|
2012-08-10 19:19:41 +02:00
|
|
|
permission_required = 'participant.can_manage_participant'
|
|
|
|
allow_ajax = True
|
|
|
|
url = 'user_overview'
|
2012-08-12 12:52:38 +02:00
|
|
|
model = User
|
2012-04-02 08:35:10 +02:00
|
|
|
|
2012-08-10 19:19:41 +02:00
|
|
|
def pre_redirect(self, request, *args, **kwargs):
|
|
|
|
self.object = self.get_object()
|
|
|
|
action = kwargs['action']
|
|
|
|
if action == 'activate':
|
|
|
|
self.object.is_active = True
|
|
|
|
elif action == 'deactivate':
|
|
|
|
self.object.is_active = False
|
|
|
|
elif action == 'toggle':
|
|
|
|
self.object.is_active = not self.object.is_active
|
|
|
|
self.object.save()
|
|
|
|
return super(SetUserStatusView, self).pre_redirect(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def get_ajax_context(self, **kwargs):
|
|
|
|
context = super(SetUserStatusView, self).get_ajax_context(**kwargs)
|
|
|
|
context['active'] = self.object.is_active
|
|
|
|
return context
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
|
2012-08-10 19:19:41 +02:00
|
|
|
class ParticipantsListPDF(PDFView):
|
2012-07-07 15:26:00 +02:00
|
|
|
"""
|
2012-08-10 19:19:41 +02:00
|
|
|
Generate the userliste as PDF.
|
2012-07-07 15:26:00 +02:00
|
|
|
"""
|
2012-08-10 19:19:41 +02:00
|
|
|
permission_required = 'participant.can_see_participant'
|
|
|
|
filename = ugettext_lazy("Participant-list")
|
|
|
|
document_title = ugettext_lazy('List of Participants')
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-08-10 19:19:41 +02:00
|
|
|
def append_to_pdf(self, story):
|
|
|
|
data = [['#', _('Last Name'), _('First Name'), _('Group'), _('Type'),
|
2012-08-11 10:51:52 +02:00
|
|
|
_('Committee')]]
|
2012-08-10 19:19:41 +02:00
|
|
|
sort = 'last_name'
|
|
|
|
counter = 0
|
2012-08-12 12:52:38 +02:00
|
|
|
for user in User.objects.all().order_by(sort):
|
2012-08-10 19:19:41 +02:00
|
|
|
counter += 1
|
|
|
|
data.append([
|
|
|
|
counter,
|
|
|
|
Paragraph(user.last_name, stylesheet['Tablecell']),
|
|
|
|
Paragraph(user.first_name, stylesheet['Tablecell']),
|
2012-10-24 12:30:45 +02:00
|
|
|
Paragraph(user.detail, stylesheet['Tablecell']),
|
2012-08-10 19:19:41 +02:00
|
|
|
Paragraph(user.type, stylesheet['Tablecell']),
|
2012-08-11 10:51:52 +02:00
|
|
|
Paragraph(user.committee, stylesheet['Tablecell'])])
|
|
|
|
t = LongTable(data, style=[
|
|
|
|
('VALIGN', (0, 0), (-1, -1), 'TOP'),
|
|
|
|
('LINEABOVE', (0, 0), (-1, 0), 2, colors.black),
|
|
|
|
('LINEABOVE', (0, 1), (-1, 1), 1, colors.black),
|
|
|
|
('LINEBELOW', (0, -1), (-1, -1), 2, colors.black),
|
|
|
|
('ROWBACKGROUNDS', (0, 1), (-1, -1),
|
|
|
|
(colors.white, (.9, .9, .9)))])
|
2012-08-10 19:19:41 +02:00
|
|
|
t._argW[0] = 0.75 * cm
|
|
|
|
story.append(t)
|
2012-07-07 15:26:00 +02:00
|
|
|
|
2012-08-10 19:19:41 +02:00
|
|
|
|
|
|
|
class ParticipantsPasswordsPDF(PDFView):
|
2012-07-07 15:26:00 +02:00
|
|
|
"""
|
2012-08-10 19:19:41 +02:00
|
|
|
Generate the Welcomepaper for the users.
|
2012-07-07 15:26:00 +02:00
|
|
|
"""
|
2012-08-10 19:19:41 +02:00
|
|
|
permission_required = 'participant.can_manage_participant'
|
|
|
|
filename = ugettext_lazy("Participant-passwords")
|
|
|
|
top_space = 0
|
2011-11-14 16:37:12 +01:00
|
|
|
|
2012-08-10 19:19:41 +02:00
|
|
|
def get_template(self, buffer):
|
2012-08-11 10:51:52 +02:00
|
|
|
return SimpleDocTemplate(
|
|
|
|
buffer, topMargin=-6, bottomMargin=-6,
|
2012-08-10 19:19:41 +02:00
|
|
|
leftMargin=0, rightMargin=0, showBoundary=False)
|
2012-08-03 12:44:34 +02:00
|
|
|
|
2012-08-10 19:19:41 +02:00
|
|
|
def build_document(self, pdf_document, story):
|
|
|
|
pdf_document.build(story)
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-08-10 19:19:41 +02:00
|
|
|
def append_to_pdf(self, story):
|
|
|
|
data = []
|
|
|
|
participant_pdf_system_url = config["participant_pdf_system_url"]
|
|
|
|
participant_pdf_welcometext = config["participant_pdf_welcometext"]
|
2012-08-12 12:52:38 +02:00
|
|
|
for user in User.objects.all().order_by('last_name'):
|
2012-08-10 19:19:41 +02:00
|
|
|
cell = []
|
|
|
|
cell.append(Spacer(0, 0.8 * cm))
|
|
|
|
cell.append(Paragraph(_("Account for OpenSlides"),
|
|
|
|
stylesheet['Ballot_title']))
|
|
|
|
cell.append(Paragraph(_("for %s") % (user),
|
|
|
|
stylesheet['Ballot_subtitle']))
|
|
|
|
cell.append(Spacer(0, 0.5 * cm))
|
|
|
|
cell.append(Paragraph(_("User: %s") % (user.username),
|
|
|
|
stylesheet['Monotype']))
|
2012-08-11 10:51:52 +02:00
|
|
|
cell.append(
|
|
|
|
Paragraph(
|
|
|
|
_("Password: %s")
|
2012-09-11 19:30:12 +02:00
|
|
|
% (user.default_password), stylesheet['Monotype']))
|
2012-08-10 19:19:41 +02:00
|
|
|
cell.append(Spacer(0, 0.5 * cm))
|
2012-08-11 10:51:52 +02:00
|
|
|
cell.append(
|
|
|
|
Paragraph(
|
|
|
|
_("URL: %s") % (participant_pdf_system_url),
|
|
|
|
stylesheet['Ballot_option']))
|
2012-08-10 19:19:41 +02:00
|
|
|
cell.append(Spacer(0, 0.5 * cm))
|
|
|
|
cell2 = []
|
|
|
|
cell2.append(Spacer(0, 0.8 * cm))
|
|
|
|
if participant_pdf_welcometext is not None:
|
|
|
|
cell2.append(Paragraph(
|
|
|
|
participant_pdf_welcometext.replace('\r\n', '<br/>'),
|
|
|
|
stylesheet['Ballot_subtitle']))
|
|
|
|
|
|
|
|
data.append([cell, cell2])
|
2012-07-07 15:26:00 +02:00
|
|
|
|
2012-08-10 19:19:41 +02:00
|
|
|
# add empty table line if no participants available
|
|
|
|
if not data:
|
|
|
|
data.append(['', ''])
|
|
|
|
# build table
|
|
|
|
t = Table(data, 10.5 * cm, 7.42 * cm)
|
|
|
|
t.setStyle(TableStyle([
|
|
|
|
('LINEBELOW', (0, 0), (-1, 0), 0.25, colors.grey),
|
|
|
|
('LINEBELOW', (0, 1), (-1, 1), 0.25, colors.grey),
|
|
|
|
('LINEBELOW', (0, 1), (-1, -1), 0.25, colors.grey),
|
|
|
|
('VALIGN', (0, 0), (-1, -1), 'TOP'),
|
|
|
|
]))
|
|
|
|
story.append(t)
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
|
2012-08-10 19:49:46 +02:00
|
|
|
class UserImportView(FormView):
|
|
|
|
"""
|
|
|
|
Import Users via csv.
|
|
|
|
"""
|
|
|
|
permission_required = 'participant.can_manage_participant'
|
|
|
|
template_name = 'participant/import.html'
|
|
|
|
form_class = UserImportForm
|
|
|
|
|
|
|
|
def form_valid(self, form):
|
|
|
|
# check for valid encoding (will raise UnicodeDecodeError if not)
|
|
|
|
success, error_messages = import_users(self.request.FILES['csvfile'])
|
|
|
|
for message in error_messages:
|
|
|
|
messages.error(self.request, message)
|
|
|
|
if success:
|
2012-08-11 10:51:52 +02:00
|
|
|
messages.success(
|
|
|
|
self.request,
|
|
|
|
_('%d new participants were successfully imported.') % success)
|
2012-08-10 19:49:46 +02:00
|
|
|
return super(UserImportView, self).form_valid(form)
|
|
|
|
|
|
|
|
|
2012-08-10 21:24:26 +02:00
|
|
|
class ResetPasswordView(RedirectView, SingleObjectMixin, QuestionMixin):
|
2012-08-10 19:49:46 +02:00
|
|
|
"""
|
2012-09-11 19:30:12 +02:00
|
|
|
Set the Passwort for a user to his default password.
|
2012-08-10 19:49:46 +02:00
|
|
|
"""
|
2012-08-10 21:24:26 +02:00
|
|
|
permission_required = 'participant.can_manage_participant'
|
2012-08-12 12:52:38 +02:00
|
|
|
model = User
|
2012-08-10 21:24:26 +02:00
|
|
|
allow_ajax = True
|
|
|
|
question = ugettext_lazy('Do you really want to reset the password?')
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
self.object = self.get_object()
|
|
|
|
return super(ResetPasswordView, self).get(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def get_redirect_url(self, **kwargs):
|
|
|
|
return reverse('user_edit', args=[self.object.id])
|
|
|
|
|
|
|
|
def pre_redirect(self, request, *args, **kwargs):
|
|
|
|
self.confirm_form()
|
|
|
|
|
|
|
|
def pre_post_redirect(self, request, *args, **kwargs):
|
|
|
|
if self.get_answer().lower() == 'yes':
|
|
|
|
self.object.reset_password()
|
|
|
|
messages.success(request,
|
2012-08-11 10:51:52 +02:00
|
|
|
_('The Password for %s was successfully reset.') % html_strong(self.object))
|
2012-08-10 21:24:26 +02:00
|
|
|
|
|
|
|
def get_answer_url(self):
|
|
|
|
return reverse('user_reset_password', args=[self.object.id])
|
2012-08-10 19:49:46 +02:00
|
|
|
|
|
|
|
|
2012-10-27 18:17:22 +02:00
|
|
|
class GroupOverview(ListView):
|
2012-08-11 10:09:54 +02:00
|
|
|
"""
|
|
|
|
Overview over all groups.
|
|
|
|
"""
|
|
|
|
permission_required = 'participant.can_manage_participant'
|
|
|
|
template_name = 'participant/group_overview.html'
|
|
|
|
context_object_name = 'groups'
|
2012-08-12 12:52:38 +02:00
|
|
|
model = Group
|
2012-08-11 10:09:54 +02:00
|
|
|
|
|
|
|
|
2012-08-11 11:36:55 +02:00
|
|
|
class GroupCreateView(CreateView):
|
2012-08-11 10:09:54 +02:00
|
|
|
"""
|
|
|
|
Create a new group.
|
|
|
|
"""
|
|
|
|
permission_required = 'participant.can_manage_participant'
|
|
|
|
template_name = 'participant/group_edit.html'
|
|
|
|
context_object_name = 'group'
|
2012-08-12 12:52:38 +02:00
|
|
|
model = Group
|
2012-08-11 10:09:54 +02:00
|
|
|
form_class = GroupForm
|
|
|
|
success_url = 'user_group_overview'
|
|
|
|
apply_url = 'user_group_edit'
|
|
|
|
|
2012-08-11 11:36:55 +02:00
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
delete_default_permissions()
|
|
|
|
return super(GroupCreateView, self).get(request, *args, **kwargs)
|
|
|
|
|
2012-08-11 10:09:54 +02:00
|
|
|
|
2012-08-11 11:36:55 +02:00
|
|
|
class GroupUpdateView(UpdateView):
|
2012-08-11 10:09:54 +02:00
|
|
|
"""
|
|
|
|
Update an existing group.
|
|
|
|
"""
|
|
|
|
permission_required = 'participant.can_manage_participant'
|
|
|
|
template_name = 'participant/group_edit.html'
|
2012-08-12 12:52:38 +02:00
|
|
|
model = Group
|
2012-08-11 10:09:54 +02:00
|
|
|
context_object_name = 'group'
|
|
|
|
form_class = GroupForm
|
|
|
|
success_url = 'user_group_overview'
|
|
|
|
apply_url = 'user_group_edit'
|
|
|
|
|
2012-08-11 11:36:55 +02:00
|
|
|
def get(self, request, *args, **kwargs):
|
|
|
|
delete_default_permissions()
|
|
|
|
return super(GroupUpdateView, self).get(request, *args, **kwargs)
|
|
|
|
|
2012-08-11 10:09:54 +02:00
|
|
|
|
|
|
|
class GroupDeleteView(DeleteView):
|
|
|
|
"""
|
|
|
|
Delete a Group.
|
|
|
|
"""
|
|
|
|
permission_required = 'participant.can_manage_participant'
|
2012-08-12 12:52:38 +02:00
|
|
|
model = Group
|
2012-08-11 10:09:54 +02:00
|
|
|
url = 'user_group_overview'
|
|
|
|
|
|
|
|
|
|
|
|
class Config(FormView):
|
|
|
|
"""
|
|
|
|
Config page for the participant app.
|
|
|
|
"""
|
|
|
|
permission_required = 'config.can_manage_config'
|
|
|
|
form_class = ConfigForm
|
|
|
|
template_name = 'participant/config.html'
|
|
|
|
|
|
|
|
def get_initial(self):
|
|
|
|
return {
|
|
|
|
'participant_pdf_system_url': config['participant_pdf_system_url'],
|
2012-09-14 02:40:40 +02:00
|
|
|
'participant_pdf_welcometext': config['participant_pdf_welcometext'],
|
|
|
|
'participant_sort_users_by_first_name': config['participant_sort_users_by_first_name']}
|
2012-08-11 10:09:54 +02:00
|
|
|
|
|
|
|
def form_valid(self, form):
|
2012-08-11 10:51:52 +02:00
|
|
|
config['participant_pdf_system_url'] = (
|
|
|
|
form.cleaned_data['participant_pdf_system_url'])
|
|
|
|
config['participant_pdf_welcometext'] = (
|
|
|
|
form.cleaned_data['participant_pdf_welcometext'])
|
2012-09-14 02:40:40 +02:00
|
|
|
config['participant_sort_users_by_first_name'] = (
|
|
|
|
form.cleaned_data['participant_sort_users_by_first_name'])
|
2012-08-11 10:51:52 +02:00
|
|
|
messages.success(
|
|
|
|
self.request,
|
2012-08-11 10:09:54 +02:00
|
|
|
_('Participants settings successfully saved.'))
|
|
|
|
return super(Config, self).form_valid(form)
|
|
|
|
|
|
|
|
|
2012-08-13 19:16:42 +02:00
|
|
|
def login(request):
|
|
|
|
extra_content = {}
|
|
|
|
try:
|
|
|
|
admin = User.objects.get(pk=1)
|
2012-08-14 14:19:59 +02:00
|
|
|
if admin.check_password(admin.default_password):
|
2012-08-13 19:16:42 +02:00
|
|
|
extra_content['first_time_message'] = _(
|
|
|
|
"Installation was successfully! Use %(user)s "
|
|
|
|
"(password: %(password)s) for first login.<br>"
|
|
|
|
"<strong>Important:</strong> Please change the password after "
|
|
|
|
"first login! Otherwise this message still appears for "
|
|
|
|
"everyone and could be a security risk.") % {
|
|
|
|
'user': html_strong(admin.username),
|
2012-08-14 14:19:59 +02:00
|
|
|
'password': html_strong(admin.default_password)}
|
2012-08-13 19:16:42 +02:00
|
|
|
extra_content['next'] = reverse('password_change')
|
|
|
|
except User.DoesNotExist:
|
|
|
|
pass
|
|
|
|
return django_login(request, template_name='participant/login.html', extra_context=extra_content)
|
|
|
|
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
@login_required
|
|
|
|
@template('participant/settings.html')
|
|
|
|
def user_settings(request):
|
2012-07-07 15:26:00 +02:00
|
|
|
"""
|
|
|
|
Edit own user account.
|
|
|
|
"""
|
2011-07-31 10:46:29 +02:00
|
|
|
if request.method == 'POST':
|
2012-08-08 10:34:23 +02:00
|
|
|
form_user = UsersettingsForm(request.POST, instance=request.user)
|
2012-07-01 16:56:01 +02:00
|
|
|
if form_user.is_valid():
|
2011-07-31 10:46:29 +02:00
|
|
|
form_user.save()
|
|
|
|
messages.success(request, _('User settings successfully saved.'))
|
|
|
|
else:
|
|
|
|
messages.error(request, _('Please check the form for errors.'))
|
|
|
|
else:
|
2012-07-01 16:56:01 +02:00
|
|
|
form_user = UsersettingsForm(instance=request.user)
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
'form_user': form_user,
|
|
|
|
'edituser': request.user,
|
|
|
|
}
|
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
|
2012-07-11 09:46:15 +02:00
|
|
|
@login_required
|
|
|
|
@template('participant/password_change.html')
|
|
|
|
def user_settings_password(request):
|
|
|
|
"""
|
|
|
|
Edit own password.
|
|
|
|
"""
|
|
|
|
if request.method == 'POST':
|
|
|
|
form = PasswordChangeForm(request.user, request.POST)
|
|
|
|
if form.is_valid():
|
|
|
|
form.save()
|
|
|
|
messages.success(request, _('Password successfully changed.'))
|
|
|
|
return redirect(reverse('user_settings'))
|
|
|
|
else:
|
|
|
|
messages.error(request, _('Please check the form for errors.'))
|
|
|
|
else:
|
|
|
|
form = PasswordChangeForm(user=request.user)
|
|
|
|
|
|
|
|
return {
|
|
|
|
'form': form,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-10 19:19:41 +02:00
|
|
|
def register_tab(request):
|
|
|
|
"""
|
|
|
|
Register the participant tab.
|
|
|
|
"""
|
|
|
|
selected = request.path.startswith('/participant/')
|
|
|
|
return Tab(
|
|
|
|
title=_('Participants'),
|
|
|
|
url=reverse('user_overview'),
|
2012-08-11 10:51:52 +02:00
|
|
|
permission=request.user.has_perm('participant.can_see_participant') or
|
|
|
|
request.user.has_perm('participant.can_manage_participant'),
|
|
|
|
selected=selected)
|
2012-10-25 23:58:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_widgets(request):
|
|
|
|
"""
|
|
|
|
Returns all widgets of the participant app. This is a user_widget, a
|
|
|
|
group_widget and a personal_info_widget.
|
|
|
|
"""
|
|
|
|
return [
|
|
|
|
get_personal_info_widget(request),
|
2012-10-26 18:16:09 +02:00
|
|
|
get_user_widget(request),
|
|
|
|
get_group_widget(request)]
|
2012-10-25 23:58:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_personal_info_widget(request):
|
|
|
|
"""
|
|
|
|
Provides a widget for personal info. It shows your submitted motions
|
|
|
|
and where you are supporter or candidate.
|
|
|
|
"""
|
|
|
|
personal_info_context = {
|
|
|
|
'submitted_motions': Motion.objects.filter(submitter=request.user),
|
|
|
|
'config_motion_min_supporters': config['motion_min_supporters'],
|
|
|
|
'supported_motions': Motion.objects.filter(motionsupporter=request.user),
|
2012-10-26 17:14:46 +02:00
|
|
|
'assignments': Assignment.objects.filter(
|
|
|
|
assignmentcandidate__person=request.user,
|
|
|
|
assignmentcandidate__blocked=False),}
|
2012-10-25 23:58:32 +02:00
|
|
|
return Widget(
|
|
|
|
name='personal_info',
|
|
|
|
display_name=_('On You'),
|
|
|
|
template='participant/personal_info_widget.html',
|
|
|
|
context=personal_info_context,
|
|
|
|
permission_required=None,
|
|
|
|
default_column=1)
|
|
|
|
|
|
|
|
|
|
|
|
def get_user_widget(request):
|
|
|
|
"""
|
|
|
|
Provides a widget with all users. This is for short activation of
|
|
|
|
user slides.
|
|
|
|
"""
|
2012-10-26 18:16:09 +02:00
|
|
|
return Widget(
|
|
|
|
name='user',
|
|
|
|
display_name=_('Users'),
|
|
|
|
template='participant/user_widget.html',
|
|
|
|
context={'users': User.objects.all(),},
|
|
|
|
permission_required='projector.can_manage_projector',
|
|
|
|
default_column=1)
|
2012-10-25 23:58:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_group_widget(request):
|
|
|
|
"""
|
|
|
|
Provides a widget with all groups. This is for short activation of
|
|
|
|
group slides.
|
|
|
|
"""
|
2012-10-26 18:16:09 +02:00
|
|
|
return Widget(
|
|
|
|
name='group',
|
|
|
|
display_name=_('Groups'),
|
|
|
|
template='participant/group_widget.html',
|
|
|
|
context={'groups': Group.objects.all(),},
|
|
|
|
permission_required='projector.can_manage_projector',
|
|
|
|
default_column=1)
|