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
|
2011-09-03 17:17:29 +02:00
|
|
|
from django.contrib.auth.forms import AdminPasswordChangeForm
|
2012-07-07 15:26:00 +02:00
|
|
|
from django.contrib.auth.models import User, Group, Permission
|
2012-07-10 01:33:03 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _, ugettext_noop
|
2011-11-14 20:45:04 +01:00
|
|
|
|
2012-07-10 13:19:12 +02:00
|
|
|
from openslides.utils.forms import CssClassMixin, LocalizedModelMultipleChoiceField
|
2011-11-14 20:45:04 +01:00
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
from openslides.participant.models import Profile
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2011-09-04 09:57:23 +02:00
|
|
|
|
2012-04-12 19:11:07 +02:00
|
|
|
USER_APPLICATION_IMPORT_OPTIONS = [
|
|
|
|
('REASSIGN', _('Keep applications, try to reassign submitter')),
|
|
|
|
('INREVIEW', _('Keep applications, set status to "needs review"')),
|
|
|
|
('DISCARD' , _('Discard applications'))
|
|
|
|
]
|
|
|
|
|
2012-07-10 13:19:12 +02:00
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
class UserNewForm(forms.ModelForm, CssClassMixin):
|
|
|
|
first_name = forms.CharField(label=_("First name"))
|
|
|
|
last_name = forms.CharField(label=_("Last name"))
|
|
|
|
groups = forms.ModelMultipleChoiceField(queryset=Group.objects.all(),
|
|
|
|
label=_("User groups"), required=False)
|
|
|
|
is_active = forms.BooleanField(label=_("Active"), required=False,
|
|
|
|
initial=True)
|
2011-09-04 09:57:23 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = User
|
2012-07-07 15:26:00 +02:00
|
|
|
exclude = ('username', 'password', 'is_staff', 'is_superuser',
|
|
|
|
'last_login', 'date_joined', 'user_permissions')
|
2011-09-04 09:57:23 +02:00
|
|
|
|
2011-09-03 17:17:29 +02:00
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
class UserEditForm(forms.ModelForm, CssClassMixin):
|
|
|
|
first_name = forms.CharField(label=_("First name"))
|
|
|
|
last_name = forms.CharField(label=_("Last name"))
|
|
|
|
groups = forms.ModelMultipleChoiceField(queryset=Group.objects.all(),
|
|
|
|
label=_("User groups"), required=False)
|
|
|
|
is_active = forms.BooleanField(label=_("Active"), required=False)
|
2011-09-03 17:17:29 +02:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
class Meta:
|
|
|
|
model = User
|
2012-07-07 15:26:00 +02:00
|
|
|
exclude = ('password', 'is_staff', 'is_superuser', 'last_login',
|
|
|
|
'date_joined', 'user_permissions')
|
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 UsernameForm(forms.ModelForm, CssClassMixin):
|
2011-07-31 10:46:29 +02:00
|
|
|
class Meta:
|
|
|
|
model = User
|
2012-07-07 15:26:00 +02:00
|
|
|
exclude = ('first_name', 'last_name', 'email', 'is_active',
|
|
|
|
'is_superuser', 'groups', 'password', 'is_staff', 'last_login',
|
|
|
|
'date_joined', 'user_permissions')
|
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 ProfileForm(forms.ModelForm, CssClassMixin):
|
2011-07-31 10:46:29 +02:00
|
|
|
class Meta:
|
|
|
|
model = Profile
|
|
|
|
|
2011-11-14 20:45:04 +01:00
|
|
|
|
2012-07-07 15:26:00 +02:00
|
|
|
class GroupForm(forms.ModelForm, CssClassMixin):
|
2012-08-03 12:44:34 +02:00
|
|
|
as_user = forms.BooleanField(initial=False, required=False,
|
|
|
|
label=_("Treat Group as User"),
|
|
|
|
help_text=_("The Group will appear on any place, other user does."))
|
2012-07-07 15:26:00 +02:00
|
|
|
permissions = LocalizedModelMultipleChoiceField(
|
|
|
|
queryset=Permission.objects.all(), label=_("Persmissions"))
|
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-07-07 15:26:00 +02:00
|
|
|
self.fields['permissions'].initial = \
|
|
|
|
[p.pk for p in kwargs['instance'].permissions.all()]
|
2012-04-14 18:53:18 +02:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
class Meta:
|
|
|
|
model = Group
|
2011-11-14 20:45:04 +01:00
|
|
|
exclude = ('permissions',)
|
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:
|
|
|
|
model = User
|
|
|
|
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):
|
|
|
|
csvfile = forms.FileField(widget=forms.FileInput(attrs={'size':'50'}),
|
|
|
|
label=_("CSV File"))
|
|
|
|
application_handling = forms.ChoiceField(
|
|
|
|
required=True,
|
|
|
|
choices=USER_APPLICATION_IMPORT_OPTIONS,
|
|
|
|
label=_("For existing applications"),
|
|
|
|
)
|
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-04-22 16:51:22 +02:00
|
|
|
help_text=_("Printed in PDF of first time passwords only."),
|
2012-04-15 12:39:28 +02:00
|
|
|
)
|
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-04-22 16:51:22 +02:00
|
|
|
help_text=_("Printed in PDF of first time passwords only."),
|
2012-04-15 12:39:28 +02:00
|
|
|
)
|