2011-07-31 10:46:29 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2012-10-24 11:04:23 +02:00
|
|
|
openslides.motion.forms
|
2011-07-31 10:46:29 +02:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2012-10-24 11:04:23 +02:00
|
|
|
Forms for the motion app.
|
2011-07-31 10:46:29 +02:00
|
|
|
|
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
|
2013-01-06 12:07:37 +01:00
|
|
|
from django.utils.translation import ugettext as _
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-07-01 15:35:05 +02:00
|
|
|
from openslides.utils.forms import CssClassMixin
|
2012-08-07 22:43:57 +02:00
|
|
|
from openslides.utils.person import PersonFormField, MultiplePersonFormField
|
2013-01-06 12:07:37 +01:00
|
|
|
from .models import Motion
|
2013-02-01 16:33:45 +01:00
|
|
|
from .workflow import motion_workflow_choices
|
2012-02-20 18:44:02 +01:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
class BaseMotionForm(forms.ModelForm, CssClassMixin):
|
2013-01-26 15:25:54 +01:00
|
|
|
"""
|
|
|
|
Form to automaticly save the version data for a motion.
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
class Meta:
|
|
|
|
model = Motion
|
|
|
|
fields = ()
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2013-01-26 16:05:30 +01:00
|
|
|
self.motion = kwargs.get('instance', None)
|
|
|
|
self.initial = kwargs.setdefault('initial', {})
|
|
|
|
if self.motion is not None:
|
|
|
|
self.initial['title'] = self.motion.title
|
|
|
|
self.initial['text'] = self.motion.text
|
|
|
|
self.initial['reason'] = self.motion.reason
|
2013-01-06 12:07:37 +01:00
|
|
|
super(BaseMotionForm, self).__init__(*args, **kwargs)
|
|
|
|
|
2012-07-01 15:35:05 +02:00
|
|
|
title = forms.CharField(widget=forms.TextInput(), label=_("Title"))
|
|
|
|
text = forms.CharField(widget=forms.Textarea(), label=_("Text"))
|
2012-11-24 14:01:21 +01:00
|
|
|
reason = forms.CharField(
|
|
|
|
widget=forms.Textarea(), required=False, label=_("Reason"))
|
2012-06-30 11:31:35 +02:00
|
|
|
|
|
|
|
|
2013-01-26 15:25:54 +01:00
|
|
|
class MotionSubmitterMixin(forms.ModelForm):
|
|
|
|
submitter = MultiplePersonFormField(label=_("Submitter"))
|
2011-11-09 22:53:10 +01:00
|
|
|
|
2013-01-26 16:05:30 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if self.motion is not None:
|
|
|
|
submitter = [submitter.person.person_id for submitter in self.motion.submitter.all()]
|
|
|
|
self.initial['submitter'] = submitter
|
|
|
|
super(MotionSubmitterMixin, self).__init__(*args, **kwargs)
|
|
|
|
|
2012-03-16 14:31:59 +01:00
|
|
|
|
2013-01-26 15:25:54 +01:00
|
|
|
class MotionSupporterMixin(forms.ModelForm):
|
|
|
|
supporter = MultiplePersonFormField(required=False, label=_("Supporters"))
|
|
|
|
|
2013-01-26 16:42:23 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
if self.motion is not None:
|
|
|
|
supporter = [supporter.person.person_id for supporter in self.motion.supporter.all()]
|
|
|
|
self.initial['supporter'] = supporter
|
|
|
|
super(MotionSupporterMixin, self).__init__(*args, **kwargs)
|
|
|
|
|
2013-01-26 15:25:54 +01:00
|
|
|
|
2013-01-26 17:09:13 +01:00
|
|
|
class MotionCreateNewVersionMixin(forms.ModelForm):
|
|
|
|
new_version = forms.BooleanField(
|
|
|
|
required=False, label=_("Create new version"), initial=True,
|
2013-01-26 15:25:54 +01:00
|
|
|
help_text=_("Trivial changes don't create a new version."))
|
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):
|
2012-10-24 11:04:23 +02:00
|
|
|
motion_min_supporters = forms.IntegerField(
|
2012-11-24 14:01:21 +01:00
|
|
|
widget=forms.TextInput(attrs={'class': 'small-input'}),
|
2012-08-05 22:31:20 +02:00
|
|
|
label=_("Number of (minimum) required supporters for a motion"),
|
2012-03-16 14:31:59 +01:00
|
|
|
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-10-24 11:04:23 +02:00
|
|
|
motion_preamble = forms.CharField(
|
2012-07-01 15:35:05 +02:00
|
|
|
widget=forms.TextInput(),
|
2012-03-16 14:31:59 +01:00
|
|
|
required=False,
|
2012-08-05 22:31:20 +02:00
|
|
|
label=_("Motion preamble")
|
2012-03-16 14:31:59 +01:00
|
|
|
)
|
2012-10-24 11:04:23 +02:00
|
|
|
motion_pdf_ballot_papers_selection = forms.ChoiceField(
|
2012-07-01 15:35:05 +02:00
|
|
|
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-10-24 11:04:23 +02:00
|
|
|
motion_pdf_ballot_papers_number = forms.IntegerField(
|
2012-11-24 14:01:21 +01:00
|
|
|
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-10-24 11:04:23 +02:00
|
|
|
motion_pdf_title = forms.CharField(
|
2012-07-01 15:35:05 +02:00
|
|
|
widget=forms.TextInput(),
|
2012-03-16 14:31:59 +01:00
|
|
|
required=False,
|
2012-08-05 22:31:20 +02:00
|
|
|
label=_("Title for PDF document (all motions)")
|
2012-03-16 14:31:59 +01:00
|
|
|
)
|
2012-10-24 11:04:23 +02:00
|
|
|
motion_pdf_preamble = forms.CharField(
|
2012-07-01 15:35:05 +02:00
|
|
|
widget=forms.Textarea(),
|
2012-03-16 14:31:59 +01:00
|
|
|
required=False,
|
2012-08-05 22:31:20 +02:00
|
|
|
label=_("Preamble text for PDF document (all motions)")
|
2012-03-16 14:31:59 +01:00
|
|
|
)
|
2012-06-30 11:31:35 +02:00
|
|
|
|
2013-01-26 17:09:13 +01:00
|
|
|
motion_create_new_version = forms.ChoiceField(
|
|
|
|
widget=forms.Select(),
|
|
|
|
label=_("Create new versions"),
|
2012-06-30 11:31:35 +02:00
|
|
|
required=False,
|
2013-01-26 17:09:13 +01:00
|
|
|
choices=(
|
|
|
|
('ALLWASY_CREATE_NEW_VERSION', _('create allways a new versions')),
|
|
|
|
('NEVER_CREATE_NEW_VERSION', _('create never a new version')),
|
|
|
|
('ASK_USER', _('Let the user choose if he wants to create a new version')))
|
2012-06-30 11:31:35 +02:00
|
|
|
)
|
2013-02-01 16:33:45 +01:00
|
|
|
|
|
|
|
motion_workflow = forms.ChoiceField(
|
|
|
|
widget=forms.Select(),
|
|
|
|
label=_("Workflow for the motions"),
|
|
|
|
required=True,
|
|
|
|
choices=motion_workflow_choices())
|