2011-07-31 10:46:29 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
openslides.participant.forms
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Forms 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
|
|
|
from django import forms
|
2012-08-11 10:51:52 +02:00
|
|
|
from django.contrib.auth.models import Permission
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2011-11-14 20:45:04 +01:00
|
|
|
|
2012-08-08 10:34:23 +02:00
|
|
|
from openslides.utils.forms import (
|
|
|
|
CssClassMixin, LocalizedModelMultipleChoiceField)
|
2011-11-14 20:45:04 +01:00
|
|
|
|
2012-08-11 10:09:54 +02:00
|
|
|
from openslides.participant.models import OpenSlidesUser, OpenSlidesGroup
|
2012-04-12 19:11:07 +02:00
|
|
|
|
2012-07-10 13:19:12 +02:00
|
|
|
|
2012-08-10 13:22:09 +02:00
|
|
|
class UserCreateForm(forms.ModelForm, CssClassMixin):
|
2012-07-07 15:26:00 +02:00
|
|
|
first_name = forms.CharField(label=_("First name"))
|
|
|
|
last_name = forms.CharField(label=_("Last name"))
|
2012-08-08 10:34:23 +02:00
|
|
|
groups = forms.ModelMultipleChoiceField(
|
2012-08-11 11:09:20 +02:00
|
|
|
queryset=OpenSlidesGroup.objects.exclude(name__iexact='anonymous'),
|
|
|
|
label=_("User groups"), required=False)
|
2012-08-08 10:34:23 +02:00
|
|
|
is_active = forms.BooleanField(
|
|
|
|
label=_("Active"), required=False, initial=True)
|
2011-09-04 09:57:23 +02:00
|
|
|
|
|
|
|
class Meta:
|
2012-08-10 13:22:09 +02:00
|
|
|
model = OpenSlidesUser
|
|
|
|
fields = ('first_name', 'last_name', 'is_active', 'groups', 'category',
|
|
|
|
'gender', 'type', 'committee', 'comment', 'firstpassword')
|
2011-09-04 09:57:23 +02:00
|
|
|
|
2011-09-03 17:17:29 +02:00
|
|
|
|
2012-08-10 13:22:09 +02:00
|
|
|
class UserUpdateForm(UserCreateForm):
|
2011-07-31 10:46:29 +02:00
|
|
|
class Meta:
|
2012-08-10 13:22:09 +02:00
|
|
|
model = OpenSlidesUser
|
|
|
|
fields = ('username', 'first_name', 'last_name', 'is_active', 'groups',
|
|
|
|
'category', 'gender', 'type', 'committee', 'comment',
|
|
|
|
'firstpassword')
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2011-09-03 17:17:29 +02:00
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
class GroupForm(forms.ModelForm, CssClassMixin):
|
|
|
|
permissions = LocalizedModelMultipleChoiceField(
|
2012-08-11 10:09:54 +02:00
|
|
|
queryset=Permission.objects.all(), label=_("Persmissions"),
|
|
|
|
required=False)
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-04-14 18:53:18 +02:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(GroupForm, self).__init__(*args, **kwargs)
|
|
|
|
if kwargs.get('instance', None) is not None:
|
2012-08-08 10:34:23 +02:00
|
|
|
self.fields['permissions'].initial = (
|
|
|
|
[p.pk for p in kwargs['instance'].permissions.all()])
|
2012-04-14 18:53:18 +02:00
|
|
|
|
2012-08-11 10:09:54 +02:00
|
|
|
def clean_name(self):
|
|
|
|
data = self.cleaned_data['name']
|
|
|
|
if self.instance.name.lower() == 'anonymous':
|
|
|
|
# Editing the anonymous-user
|
|
|
|
if self.instance.name.lower() != data.lower():
|
|
|
|
raise forms.ValidationError(
|
|
|
|
_('You can not edit the name for the anonymous user'))
|
|
|
|
else:
|
|
|
|
if data.lower() == 'anonymous':
|
|
|
|
raise forms.ValidationError(
|
|
|
|
_('Group name "%s" is reserved for internal use.') % data)
|
|
|
|
return data
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
class Meta:
|
2012-08-11 10:09:54 +02:00
|
|
|
model = OpenSlidesGroup
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-04-14 14:31:09 +02:00
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
class UsersettingsForm(forms.ModelForm, CssClassMixin):
|
2011-07-31 10:46:29 +02:00
|
|
|
class Meta:
|
2012-08-11 10:51:52 +02:00
|
|
|
model = OpenSlidesUser
|
2011-07-31 10:46:29 +02:00
|
|
|
fields = ('username', 'first_name', 'last_name', 'email')
|
|
|
|
|
2012-08-04 12:19:31 +02:00
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
class UserImportForm(forms.Form, CssClassMixin):
|
2012-08-08 10:34:23 +02:00
|
|
|
csvfile = forms.FileField(widget=forms.FileInput(attrs={'size': '50'}),
|
|
|
|
label=_("CSV File"))
|
2012-04-15 12:39:28 +02:00
|
|
|
|
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
class ConfigForm(forms.Form, CssClassMixin):
|
|
|
|
participant_pdf_system_url = forms.CharField(
|
|
|
|
widget=forms.TextInput(),
|
2012-04-15 12:39:28 +02:00
|
|
|
required=False,
|
|
|
|
label=_("System URL"),
|
2012-08-08 10:34:23 +02:00
|
|
|
help_text=_("Printed in PDF of first time passwords only."))
|
2012-07-07 15:26:00 +02:00
|
|
|
participant_pdf_welcometext = forms.CharField(
|
|
|
|
widget=forms.Textarea(),
|
2012-04-15 12:39:28 +02:00
|
|
|
required=False,
|
|
|
|
label=_("Welcome text"),
|
2012-08-08 10:34:23 +02:00
|
|
|
help_text=_("Printed in PDF of first time passwords only."))
|