2011-07-31 10:46:29 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
openslides.application.forms
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Forms for the application 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-01 15:35:05 +02:00
|
|
|
from django import forms
|
2011-11-01 06:47:10 +01:00
|
|
|
from django.contrib.auth.models import User
|
2012-07-10 01:33:03 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _, ugettext_noop
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-07-01 15:35:05 +02:00
|
|
|
from openslides.utils.forms import CssClassMixin
|
|
|
|
from openslides.application.models import Application
|
2012-02-20 18:44:02 +01:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-07-01 15:35:05 +02:00
|
|
|
class UserModelChoiceField(forms.ModelChoiceField):
|
2011-11-01 06:47:10 +01:00
|
|
|
"""
|
|
|
|
Extend ModelChoiceField for users so that the choices are
|
|
|
|
listed as 'first_name last_name' instead of just 'username'.
|
|
|
|
"""
|
|
|
|
def label_from_instance(self, obj):
|
|
|
|
return obj.get_full_name()
|
|
|
|
|
2012-03-16 14:31:59 +01:00
|
|
|
|
2012-07-01 15:35:05 +02:00
|
|
|
class UserModelMultipleChoiceField(forms.ModelMultipleChoiceField):
|
2011-11-01 06:47:10 +01:00
|
|
|
"""
|
|
|
|
Extend ModelMultipleChoiceField for users so that the choices are
|
|
|
|
listed as 'first_name last_name' instead of just 'username'.
|
|
|
|
"""
|
|
|
|
def label_from_instance(self, obj):
|
|
|
|
return obj.get_full_name()
|
|
|
|
|
|
|
|
|
2012-07-01 15:35:05 +02:00
|
|
|
class ApplicationForm(forms.Form, CssClassMixin):
|
|
|
|
title = forms.CharField(widget=forms.TextInput(), label=_("Title"))
|
|
|
|
text = forms.CharField(widget=forms.Textarea(), label=_("Text"))
|
2012-07-08 09:21:39 +02:00
|
|
|
reason = forms.CharField(widget=forms.Textarea(), required=False,
|
|
|
|
label=_("Reason"))
|
2012-06-30 11:31:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ApplicationFormTrivialChanges(ApplicationForm):
|
2012-07-08 09:21:39 +02:00
|
|
|
trivial_change = forms.BooleanField(required=False,
|
|
|
|
label=_("Trivial change"),
|
2012-06-30 11:31:35 +02:00
|
|
|
help_text=_("Trivial changes don't create a new version."))
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-03-16 14:31:59 +01:00
|
|
|
|
2012-07-01 15:35:05 +02:00
|
|
|
class ApplicationManagerForm(forms.ModelForm, CssClassMixin):
|
2012-06-30 11:50:46 +02:00
|
|
|
submitter = UserModelChoiceField(
|
2012-07-08 09:21:39 +02:00
|
|
|
queryset=User.objects.all().exclude(profile=None).
|
|
|
|
order_by("first_name"),
|
2012-06-30 11:50:46 +02:00
|
|
|
label=_("Submitter"),
|
|
|
|
)
|
2011-11-01 06:47:10 +01:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
class Meta:
|
|
|
|
model = Application
|
2012-06-30 11:50:46 +02:00
|
|
|
exclude = ('number', 'status', 'permitted', 'log', 'supporter')
|
|
|
|
|
|
|
|
|
|
|
|
class ApplicationManagerFormSupporter(ApplicationManagerForm):
|
|
|
|
supporter = UserModelMultipleChoiceField(
|
2012-07-08 09:21:39 +02:00
|
|
|
queryset=User.objects.all().exclude(profile=None).
|
|
|
|
order_by("first_name"),
|
2012-06-30 11:50:46 +02:00
|
|
|
required=False, label=_("Supporters"),
|
|
|
|
)
|
2011-11-09 22:53:10 +01:00
|
|
|
|
2012-03-16 14:31:59 +01:00
|
|
|
|
2012-07-01 15:35:05 +02:00
|
|
|
class ApplicationImportForm(forms.Form, CssClassMixin):
|
|
|
|
csvfile = forms.FileField(
|
|
|
|
widget=forms.FileInput(attrs={'size':'50'}),
|
|
|
|
label=_("CSV File"),
|
|
|
|
)
|
|
|
|
import_permitted = forms.BooleanField(
|
|
|
|
required=False,
|
|
|
|
label=_("Import applications with status \"permitted\""),
|
2012-07-10 02:21:27 +02:00
|
|
|
help_text=_('Set the initial status for each application to ' \
|
|
|
|
'permitted"'),
|
2012-07-01 15:35:05 +02:00
|
|
|
)
|
2012-03-16 14:31:59 +01:00
|
|
|
|
2012-04-17 17:35:50 +02:00
|
|
|
|
2012-07-01 15:35:05 +02:00
|
|
|
class ConfigForm(forms.Form, CssClassMixin):
|
|
|
|
application_min_supporters = forms.IntegerField(
|
|
|
|
widget=forms.TextInput(attrs={'class':'small-input'}),
|
2012-03-16 14:31:59 +01:00
|
|
|
label=_("Number of (minimum) required supporters for a application"),
|
|
|
|
initial=4,
|
|
|
|
min_value=0,
|
|
|
|
max_value=8,
|
2012-06-30 16:28:15 +02:00
|
|
|
help_text=_("Choose 0 to disable the supporting system"),
|
2012-03-16 14:31:59 +01:00
|
|
|
)
|
2012-07-01 15:35:05 +02:00
|
|
|
application_preamble = forms.CharField(
|
|
|
|
widget=forms.TextInput(),
|
2012-03-16 14:31:59 +01:00
|
|
|
required=False,
|
|
|
|
label=_("Application preamble")
|
|
|
|
)
|
2012-07-01 15:35:05 +02:00
|
|
|
application_pdf_ballot_papers_selection = forms.ChoiceField(
|
|
|
|
widget=forms.Select(),
|
2012-03-16 14:31:59 +01:00
|
|
|
required=False,
|
|
|
|
label=_("Number of ballot papers (selection)"),
|
|
|
|
choices=[
|
2012-06-29 00:19:06 +02:00
|
|
|
("NUMBER_OF_DELEGATES", _("Number of all delegates")),
|
|
|
|
("NUMBER_OF_ALL_PARTICIPANTS", _("Number of all participants")),
|
|
|
|
("CUSTOM_NUMBER", _("Use the following custom number")),
|
2012-03-16 14:31:59 +01:00
|
|
|
]
|
|
|
|
)
|
2012-07-01 15:35:05 +02:00
|
|
|
application_pdf_ballot_papers_number = forms.IntegerField(
|
|
|
|
widget=forms.TextInput(attrs={'class':'small-input'}),
|
2012-03-16 14:31:59 +01:00
|
|
|
required=False,
|
|
|
|
min_value=1,
|
|
|
|
label=_("Custom number of ballot papers")
|
|
|
|
)
|
2012-07-01 15:35:05 +02:00
|
|
|
application_pdf_title = forms.CharField(
|
|
|
|
widget=forms.TextInput(),
|
2012-03-16 14:31:59 +01:00
|
|
|
required=False,
|
|
|
|
label=_("Title for PDF document (all applications)")
|
|
|
|
)
|
2012-07-01 15:35:05 +02:00
|
|
|
application_pdf_preamble = forms.CharField(
|
|
|
|
widget=forms.Textarea(),
|
2012-03-16 14:31:59 +01:00
|
|
|
required=False,
|
|
|
|
label=_("Preamble text for PDF document (all applications)")
|
|
|
|
)
|
2012-06-30 11:31:35 +02:00
|
|
|
|
2012-07-01 15:35:05 +02:00
|
|
|
application_allow_trivial_change = forms.BooleanField(
|
2012-06-30 11:31:35 +02:00
|
|
|
label=_("Allow trivial changes"),
|
2012-07-10 02:21:27 +02:00
|
|
|
help_text=_('Warning: Trivial changes undermine the application ' \
|
|
|
|
'permission system.'),
|
2012-06-30 11:31:35 +02:00
|
|
|
required=False,
|
|
|
|
)
|