2011-07-31 10:46:29 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
openslides.participant.forms
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Forms for the participant app.
|
|
|
|
|
|
|
|
:copyright: 2011 by the OpenSlides team, see AUTHORS.
|
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
|
2012-04-12 19:11:07 +02:00
|
|
|
from django.forms import Form, ModelForm, CharField, EmailField, FileField, FileInput, MultipleChoiceField, ModelMultipleChoiceField, ChoiceField, BooleanField
|
2011-11-14 20:45:04 +01:00
|
|
|
from django.contrib.auth.models import User, Group, Permission
|
2011-09-03 17:17:29 +02:00
|
|
|
from django.contrib.auth.forms import AdminPasswordChangeForm
|
2011-07-31 10:46:29 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
2011-11-14 20:45:04 +01:00
|
|
|
|
2012-02-20 18:44:02 +01:00
|
|
|
from utils.forms import CssClassMixin
|
|
|
|
|
2011-11-14 20:45:04 +01:00
|
|
|
# required for USER_VISIBLE_PERMISSIONS
|
|
|
|
from agenda.models import Item
|
|
|
|
from application.models import Application
|
|
|
|
from assignment.models import Assignment
|
2011-07-31 10:46:29 +02:00
|
|
|
from participant.models import Profile
|
2012-02-15 12:04:11 +01:00
|
|
|
from system.models import ConfigStore
|
2011-11-14 20:45:04 +01:00
|
|
|
|
|
|
|
USER_VISIBLE_PERMISSIONS = reduce(list.__add__, [
|
|
|
|
[p[0] for p in Item._meta.permissions],
|
|
|
|
[p[0] for p in Application._meta.permissions],
|
|
|
|
[p[0] for p in Assignment._meta.permissions],
|
|
|
|
[p[0] for p in Profile._meta.permissions],
|
2012-02-15 12:04:11 +01:00
|
|
|
[p[0] for p in ConfigStore._meta.permissions]
|
2011-11-14 20:45:04 +01:00
|
|
|
])
|
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-02-20 18:44:02 +01:00
|
|
|
class UserNewForm(ModelForm, CssClassMixin):
|
2011-09-04 09:57:23 +02:00
|
|
|
first_name = CharField(label=_("First name"))
|
|
|
|
last_name = CharField(label=_("Last name"))
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = User
|
|
|
|
exclude = ('username', 'password', 'is_staff', 'last_login', 'date_joined', 'user_permissions')
|
|
|
|
|
2011-09-03 17:17:29 +02:00
|
|
|
|
2012-02-20 18:44:02 +01:00
|
|
|
class UserEditForm(ModelForm, CssClassMixin):
|
2011-07-31 10:46:29 +02:00
|
|
|
first_name = CharField(label=_("First name"))
|
|
|
|
last_name = CharField(label=_("Last name"))
|
2011-09-03 17:17:29 +02:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
class Meta:
|
|
|
|
model = User
|
2011-09-03 17:17:29 +02:00
|
|
|
exclude = ('password', 'is_staff', 'last_login', 'date_joined', 'user_permissions')
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2011-09-03 17:17:29 +02:00
|
|
|
|
2012-02-20 18:44:02 +01:00
|
|
|
class UsernameForm(ModelForm, CssClassMixin):
|
2011-07-31 10:46:29 +02:00
|
|
|
class Meta:
|
|
|
|
model = User
|
|
|
|
exclude = ('first_name', 'last_name', 'email', 'is_active','is_superuser', 'groups', 'password', 'is_staff', 'last_login', 'date_joined', 'user_permissions')
|
|
|
|
|
2012-02-20 18:44:02 +01:00
|
|
|
class ProfileForm(ModelForm, CssClassMixin):
|
2011-07-31 10:46:29 +02:00
|
|
|
class Meta:
|
|
|
|
model = Profile
|
|
|
|
|
2012-02-20 18:44:02 +01:00
|
|
|
class GroupForm(ModelForm, CssClassMixin):
|
2011-11-14 20:45:04 +01:00
|
|
|
permissions = ModelMultipleChoiceField(queryset=Permission.objects.filter(codename__in=USER_VISIBLE_PERMISSIONS))
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(GroupForm, self).__init__(*args, **kwargs)
|
|
|
|
if kwargs.get('instance', None) is not None:
|
|
|
|
self.fields['permissions'].initial = [p.pk for p in kwargs['instance'].permissions.all()]
|
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-02-20 18:44:02 +01:00
|
|
|
class UsersettingsForm(UserEditForm, CssClassMixin):
|
2011-07-31 10:46:29 +02:00
|
|
|
class Meta:
|
|
|
|
model = User
|
|
|
|
fields = ('username', 'first_name', 'last_name', 'email')
|
|
|
|
|
2012-02-20 18:44:02 +01:00
|
|
|
class UserImportForm(Form, CssClassMixin):
|
2011-09-03 17:17:29 +02:00
|
|
|
csvfile = FileField(widget=FileInput(attrs={'size':'50'}), label=_("CSV File"))
|
2012-04-12 19:11:07 +02:00
|
|
|
application_handling = ChoiceField(required=True, choices=USER_APPLICATION_IMPORT_OPTIONS, label=_("For existing applications"))
|