2011-07-31 10:46:29 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
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-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
|
2013-09-25 10:01:01 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from django.utils.translation import activate, ugettext_lazy
|
2013-10-21 16:49:11 +02:00
|
|
|
from reportlab.graphics.barcode.qr import QrCodeWidget
|
|
|
|
from reportlab.graphics.shapes import Drawing
|
2013-09-25 10:01:01 +02:00
|
|
|
from reportlab.lib import colors
|
|
|
|
from reportlab.lib.units import cm
|
2013-10-23 23:47:25 +02:00
|
|
|
from reportlab.platypus import (LongTable, PageBreak, Paragraph, Spacer, Table,
|
|
|
|
TableStyle)
|
2012-04-20 23:23:50 +02:00
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
from openslides.config.api import config
|
2012-10-25 23:58:32 +02:00
|
|
|
from openslides.projector.projector import Widget
|
2013-09-25 10:01:01 +02:00
|
|
|
from openslides.utils.pdf import stylesheet
|
|
|
|
from openslides.utils.template import Tab
|
|
|
|
from openslides.utils.utils import (delete_default_permissions, html_strong,
|
|
|
|
template)
|
|
|
|
from openslides.utils.views import (CreateView, DeleteView, DetailView,
|
|
|
|
FormView, ListView, PDFView,
|
|
|
|
PermissionMixin, QuestionView,
|
|
|
|
RedirectView, SingleObjectMixin, UpdateView)
|
2013-08-04 12:59:11 +02:00
|
|
|
|
2013-09-25 10:01:01 +02:00
|
|
|
from .api import gen_password, gen_username, import_users
|
|
|
|
from .forms import (GroupForm, UserCreateForm, UserImportForm, UsersettingsForm,
|
|
|
|
UserUpdateForm)
|
|
|
|
from .models import get_protected_perm, Group, User
|
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):
|
2012-08-12 12:52:38 +02:00
|
|
|
query = User.objects
|
2013-03-12 21:33:29 +01:00
|
|
|
if config['participant_sort_users_by_first_name']:
|
|
|
|
query = query.order_by('first_name')
|
2012-08-07 22:43:57 +02:00
|
|
|
else:
|
2013-03-12 21:33:29 +01:00
|
|
|
query = query.order_by('last_name')
|
2012-08-10 19:19:41 +02:00
|
|
|
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-12 12:52:38 +02:00
|
|
|
all_users = User.objects.count()
|
2012-11-08 18:57:53 +01:00
|
|
|
# context vars
|
2012-08-10 11:51:45 +02:00
|
|
|
context.update({
|
|
|
|
'allusers': all_users,
|
2013-03-12 21:33:29 +01:00
|
|
|
'request_user': self.request.user})
|
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
|
|
|
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-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
|
2013-02-03 19:43:36 +01:00
|
|
|
success_url_name = 'user_overview'
|
2013-10-20 21:42:17 +02:00
|
|
|
url_name_args = []
|
2012-08-10 13:22:09 +02:00
|
|
|
|
|
|
|
def manipulate_object(self, form):
|
2012-11-24 14:01:21 +01: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
|
|
|
|
2013-05-15 23:26:24 +02:00
|
|
|
def post_save(self, form):
|
|
|
|
super(UserCreateView, self).post_save(form)
|
|
|
|
# TODO: find a better solution that makes the following lines obsolete
|
|
|
|
# Background: motion.models.use_post_save adds already the registerd group
|
|
|
|
# to new user but super(..).post_save(form) removes it and sets only the
|
|
|
|
# groups selected in the form (without 'registered')
|
|
|
|
# workaround: add registered group again manually
|
|
|
|
from openslides.participant.api import get_registered_group # TODO: Test, if global import is possible
|
|
|
|
registered = get_registered_group()
|
|
|
|
self.object.groups.add(registered)
|
|
|
|
|
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
|
2013-02-03 19:43:36 +01:00
|
|
|
success_url_name = 'user_overview'
|
2013-10-20 21:42:17 +02:00
|
|
|
url_name_args = []
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2013-04-13 19:18:51 +02:00
|
|
|
def get_form_kwargs(self, *args, **kwargs):
|
|
|
|
form_kwargs = super(UserUpdateView, self).get_form_kwargs(*args, **kwargs)
|
|
|
|
form_kwargs.update({'request': self.request})
|
|
|
|
return form_kwargs
|
|
|
|
|
2013-06-21 09:51:17 +02:00
|
|
|
def manipulate_object(self, form):
|
|
|
|
self.object.username = form.cleaned_data['user_name']
|
|
|
|
|
2013-05-28 20:31:01 +02:00
|
|
|
def post_save(self, form):
|
|
|
|
super(UserUpdateView, self).post_save(form)
|
|
|
|
# TODO: find a better solution that makes the following lines obsolete
|
|
|
|
# Background: motion.models.use_post_save adds already the registerd group
|
|
|
|
# to new user but super(..).post_save(form) removes it and sets only the
|
|
|
|
# groups selected in the form (without 'registered')
|
|
|
|
# workaround: add registered group again manually
|
|
|
|
from openslides.participant.api import get_registered_group # TODO: Test, if global import is possible
|
|
|
|
registered = get_registered_group()
|
|
|
|
self.object.groups.add(registered)
|
|
|
|
|
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
|
2013-02-01 17:35:27 +01:00
|
|
|
success_url_name = 'user_overview'
|
2013-09-25 12:53:44 +02:00
|
|
|
url_name_args = []
|
2012-08-10 13:29:46 +02:00
|
|
|
|
2012-11-08 18:57:53 +01:00
|
|
|
def pre_redirect(self, request, *args, **kwargs):
|
2013-06-03 20:13:06 +02:00
|
|
|
if self.object == self.request.user:
|
2012-11-08 18:57:53 +01:00
|
|
|
messages.error(request, _("You can not delete yourself."))
|
|
|
|
else:
|
2012-11-22 17:29:49 +01:00
|
|
|
super(UserDeleteView, self).pre_redirect(request, *args, **kwargs)
|
2012-08-10 13:29:46 +02:00
|
|
|
|
2013-06-03 20:13:06 +02:00
|
|
|
def pre_post_redirect(self, request, *args, **kwargs):
|
|
|
|
if self.object == self.request.user:
|
|
|
|
messages.error(self.request, _("You can not delete yourself."))
|
|
|
|
else:
|
|
|
|
super(UserDeleteView, self).pre_post_redirect(request, *args, **kwargs)
|
|
|
|
|
2012-11-24 14:01:21 +01:00
|
|
|
|
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
|
2013-02-01 17:35:27 +01:00
|
|
|
url_name = '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':
|
2013-06-03 20:13:06 +02:00
|
|
|
if self.object.user == self.request.user:
|
2012-11-08 18:57:53 +01:00
|
|
|
messages.error(request, _("You can not deactivate yourself."))
|
|
|
|
return
|
2012-08-10 19:19:41 +02:00
|
|
|
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):
|
2013-04-09 11:21:55 +02:00
|
|
|
data = [['#', _('Title'), _('Last Name'), _('First Name'),
|
|
|
|
_('Structure level'), _('Group'), _('Committee')]]
|
2012-10-30 23:00:24 +01:00
|
|
|
if config['participant_sort_users_by_first_name']:
|
|
|
|
sort = 'first_name'
|
|
|
|
else:
|
|
|
|
sort = 'last_name'
|
2012-08-10 19:19:41 +02:00
|
|
|
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
|
2013-04-09 11:21:55 +02:00
|
|
|
groups = ''
|
|
|
|
for group in user.groups.all():
|
2013-05-15 23:26:24 +02:00
|
|
|
if group.pk != 2:
|
2013-07-05 15:49:10 +02:00
|
|
|
groups += "%s<br/>" % unicode(_(group.name))
|
2012-08-10 19:19:41 +02:00
|
|
|
data.append([
|
|
|
|
counter,
|
2013-04-08 21:47:33 +02:00
|
|
|
Paragraph(user.title, stylesheet['Tablecell']),
|
2012-08-10 19:19:41 +02:00
|
|
|
Paragraph(user.last_name, stylesheet['Tablecell']),
|
|
|
|
Paragraph(user.first_name, stylesheet['Tablecell']),
|
2012-11-19 23:30:09 +01:00
|
|
|
Paragraph(user.structure_level, stylesheet['Tablecell']),
|
2013-04-09 11:21:55 +02:00
|
|
|
Paragraph(groups, 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'
|
2013-10-23 23:47:25 +02:00
|
|
|
filename = ugettext_lazy("Participant-access-data")
|
2012-08-10 19:19:41 +02:00
|
|
|
top_space = 0
|
2011-11-14 16:37:12 +01: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):
|
2013-10-23 23:47:25 +02:00
|
|
|
system_wlan_ssid = config["system_wlan_ssid"] or "-"
|
|
|
|
system_wlan_password = config["system_wlan_password"] or "-"
|
|
|
|
system_wlan_encryption = config["system_wlan_encryption"] or "-"
|
|
|
|
system_url = config["system_url"] or "-"
|
|
|
|
participant_pdf_welcometitle = config["participant_pdf_welcometitle"]
|
2012-08-10 19:19:41 +02:00
|
|
|
participant_pdf_welcometext = config["participant_pdf_welcometext"]
|
2012-10-30 23:00:24 +01:00
|
|
|
if config['participant_sort_users_by_first_name']:
|
|
|
|
sort = 'first_name'
|
|
|
|
else:
|
|
|
|
sort = 'last_name'
|
2013-10-23 23:47:25 +02:00
|
|
|
qrcode_size = 2 * cm
|
|
|
|
# qrcode for system url
|
|
|
|
qrcode_url = QrCodeWidget(system_url)
|
|
|
|
qrcode_url.barHeight = qrcode_size
|
|
|
|
qrcode_url.barWidth = qrcode_size
|
|
|
|
qrcode_url.barBorder = 0
|
|
|
|
qrcode_url_draw = Drawing(45, 45)
|
|
|
|
qrcode_url_draw.add(qrcode_url)
|
|
|
|
# qrcode for wlan
|
|
|
|
text = "WIFI:S:%s;T:%s;P:%s;;" % (system_wlan_ssid, system_wlan_encryption, system_wlan_password)
|
|
|
|
qrcode_wlan = QrCodeWidget(text)
|
|
|
|
qrcode_wlan.barHeight = qrcode_size
|
|
|
|
qrcode_wlan.barWidth = qrcode_size
|
|
|
|
qrcode_wlan.barBorder = 0
|
|
|
|
qrcode_wlan_draw = Drawing(45, 45)
|
|
|
|
qrcode_wlan_draw.add(qrcode_wlan)
|
2013-10-21 16:49:11 +02:00
|
|
|
|
2012-10-30 23:00:24 +01:00
|
|
|
for user in User.objects.all().order_by(sort):
|
2013-10-23 23:47:25 +02:00
|
|
|
story.append(Paragraph(unicode(user), stylesheet['h1']))
|
|
|
|
story.append(Spacer(0, 1 * cm))
|
|
|
|
data = []
|
|
|
|
# WLAN access data
|
2012-08-10 19:19:41 +02:00
|
|
|
cell = []
|
2013-10-23 23:47:25 +02:00
|
|
|
cell.append(Paragraph(_("WLAN access data"),
|
|
|
|
stylesheet['h2']))
|
|
|
|
cell.append(Paragraph("%s:" % _("WLAN name (SSID)"),
|
|
|
|
stylesheet['formfield']))
|
|
|
|
cell.append(Paragraph(system_wlan_ssid,
|
|
|
|
stylesheet['formfield_value']))
|
|
|
|
cell.append(Paragraph("%s:" % _("WLAN password"),
|
|
|
|
stylesheet['formfield']))
|
|
|
|
cell.append(Paragraph(system_wlan_password,
|
|
|
|
stylesheet['formfield_value']))
|
|
|
|
cell.append(Paragraph("%s:" % _("WLAN encryption"),
|
|
|
|
stylesheet['formfield']))
|
|
|
|
cell.append(Paragraph(system_wlan_encryption,
|
|
|
|
stylesheet['formfield_value']))
|
2012-08-10 19:19:41 +02:00
|
|
|
cell.append(Spacer(0, 0.5 * cm))
|
2013-10-23 23:47:25 +02:00
|
|
|
# OpenSlides access data
|
2012-08-10 19:19:41 +02:00
|
|
|
cell2 = []
|
2013-10-23 23:47:25 +02:00
|
|
|
cell2.append(Paragraph(_("OpenSlides access data"),
|
|
|
|
stylesheet['h2']))
|
|
|
|
cell2.append(Paragraph("%s:" % _("Username"),
|
|
|
|
stylesheet['formfield']))
|
|
|
|
cell2.append(Paragraph(user.username,
|
|
|
|
stylesheet['formfield_value']))
|
|
|
|
cell2.append(Paragraph("%s:" % _("Password"),
|
|
|
|
stylesheet['formfield']))
|
|
|
|
cell2.append(Paragraph(user.default_password,
|
|
|
|
stylesheet['formfield_value']))
|
|
|
|
cell2.append(Paragraph("URL:",
|
|
|
|
stylesheet['formfield']))
|
|
|
|
cell2.append(Paragraph(system_url,
|
|
|
|
stylesheet['formfield_value']))
|
2012-08-10 19:19:41 +02:00
|
|
|
data.append([cell, cell2])
|
2013-10-23 23:47:25 +02:00
|
|
|
# QRCodes
|
|
|
|
cell = []
|
|
|
|
if system_wlan_ssid != "-" and system_wlan_encryption != "-":
|
|
|
|
cell.append(qrcode_wlan_draw)
|
|
|
|
cell.append(Paragraph(_("Scan this QRCode to connect WLAN."),
|
|
|
|
stylesheet['qrcode_comment']))
|
|
|
|
cell2 = []
|
|
|
|
if system_url != "-":
|
|
|
|
cell2.append(qrcode_url_draw)
|
|
|
|
cell2.append(Paragraph(_("Scan this QRCode to open URL."),
|
|
|
|
stylesheet['qrcode_comment']))
|
|
|
|
data.append([cell, cell2])
|
|
|
|
# build table
|
|
|
|
table = Table(data)
|
|
|
|
table._argW[0] = 8 * cm
|
|
|
|
table._argW[1] = 8 * cm
|
|
|
|
table.setStyle(TableStyle([('VALIGN', (0, 0), (-1, -1), 'TOP')]))
|
|
|
|
story.append(table)
|
|
|
|
story.append(Spacer(0, 2 * cm))
|
|
|
|
|
|
|
|
# welcome title and text
|
|
|
|
story.append(Paragraph(participant_pdf_welcometitle,
|
|
|
|
stylesheet['h2']))
|
|
|
|
story.append(Paragraph(participant_pdf_welcometext.replace('\r\n', '<br/>'),
|
|
|
|
stylesheet['Paragraph12']))
|
|
|
|
story.append(PageBreak())
|
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
|
2013-04-09 11:21:55 +02:00
|
|
|
success_url_name = 'user_overview'
|
2012-08-10 19:49:46 +02:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2013-09-25 12:53:44 +02:00
|
|
|
class ResetPasswordView(SingleObjectMixin, QuestionView):
|
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
|
2013-09-25 12:53:44 +02:00
|
|
|
question_message = ugettext_lazy('Do you really want to reset the password?')
|
2012-08-10 21:24:26 +02:00
|
|
|
|
|
|
|
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])
|
|
|
|
|
2013-09-25 12:53:44 +02:00
|
|
|
def on_clicked_yes(self):
|
2012-10-28 19:59:41 +01:00
|
|
|
self.object.reset_password()
|
2012-08-10 21:24:26 +02:00
|
|
|
|
2013-09-25 12:53:44 +02:00
|
|
|
def get_final_message(self):
|
2012-10-28 19:59:41 +01:00
|
|
|
return _('The Password for %s was successfully reset.') % html_strong(self.object)
|
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
|
|
|
|
|
|
|
|
2013-04-09 19:53:18 +02:00
|
|
|
class GroupDetailView(DetailView, PermissionMixin):
|
|
|
|
"""
|
|
|
|
Classed based view to show a specific group in the interface.
|
|
|
|
"""
|
|
|
|
permission_required = 'participant.can_manage_participant'
|
|
|
|
model = Group
|
|
|
|
template_name = 'participant/group_detail.html'
|
|
|
|
context_object_name = 'group'
|
|
|
|
|
2013-04-13 18:13:11 +02:00
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
|
|
context = super(GroupDetailView, self).get_context_data(*args, **kwargs)
|
|
|
|
query = User.objects
|
|
|
|
if config['participant_sort_users_by_first_name']:
|
|
|
|
query = query.order_by('first_name')
|
|
|
|
else:
|
|
|
|
query = query.order_by('last_name')
|
|
|
|
context['group_members'] = query.filter(django_user__groups__in=[context['group']])
|
|
|
|
return context
|
|
|
|
|
2013-04-09 19:53:18 +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
|
2013-02-03 19:43:36 +01:00
|
|
|
success_url_name = 'user_group_overview'
|
2013-10-20 21:42:17 +02:00
|
|
|
url_name_args = []
|
2012-08-11 10:09:54 +02:00
|
|
|
|
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
|
2013-02-03 19:43:36 +01:00
|
|
|
success_url_name = 'user_group_overview'
|
2013-10-20 21:42:17 +02:00
|
|
|
url_name_args = []
|
2012-08-11 10:09:54 +02:00
|
|
|
|
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)
|
|
|
|
|
2013-06-03 20:13:06 +02:00
|
|
|
def get_form_kwargs(self, *args, **kwargs):
|
|
|
|
form_kwargs = super(GroupUpdateView, self).get_form_kwargs(*args, **kwargs)
|
|
|
|
form_kwargs.update({'request': self.request})
|
|
|
|
return form_kwargs
|
|
|
|
|
2012-08-11 10:09:54 +02:00
|
|
|
|
|
|
|
class GroupDeleteView(DeleteView):
|
|
|
|
"""
|
2013-06-03 20:13:06 +02:00
|
|
|
Delete a group.
|
2012-08-11 10:09:54 +02:00
|
|
|
"""
|
|
|
|
permission_required = 'participant.can_manage_participant'
|
2012-08-12 12:52:38 +02:00
|
|
|
model = Group
|
2013-02-01 17:35:27 +01:00
|
|
|
success_url_name = 'user_group_overview'
|
2013-09-25 12:53:44 +02:00
|
|
|
url_name_args = []
|
2012-08-11 10:09:54 +02:00
|
|
|
|
2012-11-22 17:29:49 +01:00
|
|
|
def pre_redirect(self, request, *args, **kwargs):
|
2013-06-03 20:13:06 +02:00
|
|
|
if not self.is_protected_from_deleting():
|
2012-11-22 17:29:49 +01:00
|
|
|
super(GroupDeleteView, self).pre_redirect(request, *args, **kwargs)
|
|
|
|
|
2013-06-03 20:13:06 +02:00
|
|
|
def pre_post_redirect(self, request, *args, **kwargs):
|
|
|
|
if not self.is_protected_from_deleting():
|
|
|
|
super(GroupDeleteView, self).pre_post_redirect(request, *args, **kwargs)
|
|
|
|
|
|
|
|
def is_protected_from_deleting(self):
|
|
|
|
"""
|
|
|
|
Checks whether the group is protected.
|
|
|
|
"""
|
|
|
|
if self.object.pk in [1, 2]:
|
2013-09-25 10:01:01 +02:00
|
|
|
messages.error(self.request, _('You can not delete this group.'))
|
2013-06-03 20:13:06 +02:00
|
|
|
return True
|
|
|
|
if (not self.request.user.is_superuser and
|
|
|
|
get_protected_perm() in self.object.permissions.all() and
|
|
|
|
not Group.objects.exclude(pk=self.object.pk).filter(
|
|
|
|
permissions__in=[get_protected_perm()],
|
|
|
|
user__pk=self.request.user.pk).exists()):
|
|
|
|
messages.error(
|
|
|
|
self.request,
|
|
|
|
_('You can not delete the last group containing the permission '
|
|
|
|
'to manage participants you are in.'))
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2012-08-11 10:09:54 +02:00
|
|
|
|
2012-08-13 19:16:42 +02:00
|
|
|
def login(request):
|
|
|
|
extra_content = {}
|
|
|
|
try:
|
|
|
|
admin = User.objects.get(pk=1)
|
2013-01-04 12:39:42 +01:00
|
|
|
if admin.check_password(admin.default_password):
|
2013-09-25 12:53:44 +02:00
|
|
|
user_data = {
|
|
|
|
'user': html_strong(admin.username),
|
|
|
|
'password': html_strong(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 "
|
2013-09-25 12:53:44 +02:00
|
|
|
"everyone and could be a security risk.") % user_data
|
|
|
|
|
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():
|
2013-06-21 09:51:17 +02:00
|
|
|
user = form_user.save(commit=False)
|
|
|
|
user.username = form_user.cleaned_data['user_name']
|
|
|
|
user.save()
|
2012-12-16 17:26:53 +01:00
|
|
|
language = request.LANGUAGE_CODE = \
|
|
|
|
request.session['django_language'] = form_user.cleaned_data['language']
|
|
|
|
activate(language)
|
2011-07-31 10:46:29 +02:00
|
|
|
messages.success(request, _('User settings successfully saved.'))
|
|
|
|
else:
|
|
|
|
messages.error(request, _('Please check the form for errors.'))
|
|
|
|
else:
|
2012-12-16 17:26:53 +01:00
|
|
|
language = request.session.get('django_language', request.LANGUAGE_CODE)
|
|
|
|
form_user = UsersettingsForm(instance=request.user, initial={'language': language})
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
return {
|
2013-01-08 23:05:35 +01:00
|
|
|
'form': form_user,
|
2011-07-31 10:46:29 +02:00
|
|
|
'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.'))
|
2012-09-10 21:02:58 +02:00
|
|
|
return redirect(reverse('dashboard'))
|
2012-07-11 09:46:15 +02:00
|
|
|
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):
|
|
|
|
"""
|
2013-03-01 17:13:12 +01:00
|
|
|
Registers the participant tab.
|
2012-08-10 19:19:41 +02:00
|
|
|
"""
|
|
|
|
selected = request.path.startswith('/participant/')
|
|
|
|
return Tab(
|
|
|
|
title=_('Participants'),
|
2012-09-05 00:20:28 +02:00
|
|
|
app='participant',
|
2012-08-10 19:19:41 +02:00
|
|
|
url=reverse('user_overview'),
|
2012-11-24 14:01:21 +01:00
|
|
|
permission=(
|
|
|
|
request.user.has_perm('participant.can_see_participant') or
|
|
|
|
request.user.has_perm('participant.can_manage_participant')),
|
2012-08-11 10:51:52 +02:00
|
|
|
selected=selected)
|
2012-10-25 23:58:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_widgets(request):
|
|
|
|
"""
|
2013-04-02 17:40:57 +02:00
|
|
|
Returns all widgets of the participant app. This is a user_widget
|
|
|
|
and a group_widget.
|
|
|
|
"""
|
|
|
|
return [get_user_widget(request), get_group_widget(request)]
|
2012-10-25 23:58:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
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(
|
2013-06-13 23:38:58 +02:00
|
|
|
request,
|
2012-10-26 18:16:09 +02:00
|
|
|
name='user',
|
2012-11-08 09:43:04 +01:00
|
|
|
display_name=_('Participants'),
|
2012-10-26 18:16:09 +02:00
|
|
|
template='participant/user_widget.html',
|
2012-11-24 14:01:21 +01:00
|
|
|
context={'users': User.objects.all()},
|
2012-10-26 18:16:09 +02:00
|
|
|
permission_required='projector.can_manage_projector',
|
2013-09-07 15:09:37 +02:00
|
|
|
default_column=1,
|
|
|
|
default_weight=60)
|
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(
|
2013-06-13 23:38:58 +02:00
|
|
|
request,
|
2012-10-26 18:16:09 +02:00
|
|
|
name='group',
|
|
|
|
display_name=_('Groups'),
|
|
|
|
template='participant/group_widget.html',
|
2012-11-24 14:01:21 +01:00
|
|
|
context={'groups': Group.objects.all()},
|
2012-10-26 18:16:09 +02:00
|
|
|
permission_required='projector.can_manage_projector',
|
2013-09-07 15:09:37 +02:00
|
|
|
default_column=1,
|
|
|
|
default_weight=70)
|