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
|
2013-02-05 18:46:46 +01:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2013-02-05 18:46:46 +01:00
|
|
|
Defines the DjangoForms for the motion app.
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2013-02-05 18:46:46 +01:00
|
|
|
:copyright: (c) 2011-2013 by the 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-04-22 19:59:05 +02:00
|
|
|
from django.utils.translation import ugettext as _, ugettext_lazy
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-07-01 15:35:05 +02:00
|
|
|
from openslides.utils.forms import CssClassMixin
|
2013-03-11 22:38:39 +01:00
|
|
|
from openslides.utils.forms import CleanHtmlFormMixin
|
2012-08-07 22:43:57 +02:00
|
|
|
from openslides.utils.person import PersonFormField, MultiplePersonFormField
|
2013-03-01 17:13:12 +01:00
|
|
|
from .models import Motion, Category
|
2012-02-20 18:44:02 +01:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2013-04-16 10:04:28 +02:00
|
|
|
class BaseMotionForm(CleanHtmlFormMixin, CssClassMixin, forms.ModelForm):
|
|
|
|
"""
|
|
|
|
Base FormClass for a Motion.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
For it's own, it append the version data to the fields.
|
2013-02-05 18:46:46 +01:00
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
The class can be mixed with the following mixins to add fields for the
|
2013-02-05 18:46:46 +01:00
|
|
|
submitter, supporters etc.
|
2013-01-26 15:25:54 +01:00
|
|
|
"""
|
2013-04-16 10:04:28 +02:00
|
|
|
clean_html_fields = ('text', 'reason')
|
2013-02-05 18:46:46 +01:00
|
|
|
|
2013-04-22 19:59:05 +02:00
|
|
|
title = forms.CharField(widget=forms.TextInput(), label=ugettext_lazy("Title"))
|
2013-04-16 10:04:28 +02:00
|
|
|
"""
|
|
|
|
Title of the motion. Will be saved in a MotionVersion object.
|
|
|
|
"""
|
2013-02-05 18:46:46 +01:00
|
|
|
|
2013-04-22 19:59:05 +02:00
|
|
|
text = forms.CharField(widget=forms.Textarea(), label=ugettext_lazy("Text"))
|
2013-04-16 10:04:28 +02:00
|
|
|
"""
|
|
|
|
Text of the motion. Will be saved in a MotionVersion object.
|
|
|
|
"""
|
2013-02-05 18:46:46 +01:00
|
|
|
|
|
|
|
reason = forms.CharField(
|
2013-04-22 19:59:05 +02:00
|
|
|
widget=forms.Textarea(), required=False, label=ugettext_lazy("Reason"))
|
2013-04-16 10:04:28 +02:00
|
|
|
"""
|
|
|
|
Reason of the motion. will be saved in a MotionVersion object.
|
|
|
|
"""
|
2013-02-05 18:46:46 +01:00
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
class Meta:
|
|
|
|
model = Motion
|
|
|
|
fields = ()
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
2013-02-05 18:46:46 +01:00
|
|
|
"""Fill the FormFields releated to the version data with initial data."""
|
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-06-30 11:31:35 +02:00
|
|
|
|
2013-01-26 15:25:54 +01:00
|
|
|
class MotionSubmitterMixin(forms.ModelForm):
|
2013-02-05 18:46:46 +01:00
|
|
|
"""Mixin to append the submitter field to a MotionForm."""
|
|
|
|
|
2013-04-22 19:59:05 +02:00
|
|
|
submitter = MultiplePersonFormField(label=ugettext_lazy("Submitter"))
|
2013-02-06 23:56:21 +01:00
|
|
|
"""Submitter of the motion. Can be one or more persons."""
|
2011-11-09 22:53:10 +01:00
|
|
|
|
2013-01-26 16:05:30 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
2013-02-05 18:46:46 +01:00
|
|
|
"""Fill in the submitter of the motion as default value."""
|
2013-01-26 16:05:30 +01:00
|
|
|
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):
|
2013-02-05 18:46:46 +01:00
|
|
|
"""Mixin to append the supporter field to a Motionform."""
|
|
|
|
|
2013-04-22 19:59:05 +02:00
|
|
|
supporter = MultiplePersonFormField(required=False, label=ugettext_lazy("Supporters"))
|
2013-02-06 23:56:21 +01:00
|
|
|
"""Supporter of the motion. Can be one or more persons."""
|
2013-01-26 15:25:54 +01:00
|
|
|
|
2013-01-26 16:42:23 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
2013-02-05 18:46:46 +01:00
|
|
|
"""Fill in the supporter of the motions as default value."""
|
2013-01-26 16:42:23 +01:00
|
|
|
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-02-06 23:56:21 +01:00
|
|
|
class MotionDisableVersioningMixin(forms.ModelForm):
|
|
|
|
"""Mixin to add the option to the form to choose to disable versioning."""
|
2013-02-05 18:46:46 +01:00
|
|
|
|
2013-02-06 23:56:21 +01:00
|
|
|
disable_versioning = forms.BooleanField(
|
2013-04-22 19:59:05 +02:00
|
|
|
required=False, label=ugettext_lazy("Don't create a new version"),
|
|
|
|
help_text=ugettext_lazy("Don't create a new version. Useful e.g. for trivial changes."))
|
2013-02-05 18:46:46 +01:00
|
|
|
"""BooleanField to decide, if a new version will be created, or the
|
|
|
|
last_version will be used."""
|
2012-03-16 14:31:59 +01:00
|
|
|
|
2012-04-17 17:35:50 +02:00
|
|
|
|
2013-03-11 20:41:02 +01:00
|
|
|
class MotionCategoryMixin(forms.ModelForm):
|
|
|
|
"""Mixin to let the user choose the category for the motion."""
|
|
|
|
|
2013-04-22 19:59:05 +02:00
|
|
|
category = forms.ModelChoiceField(queryset=Category.objects.all(), required=False, label=ugettext_lazy("Category"))
|
2013-03-11 20:41:02 +01:00
|
|
|
|
|
|
|
|
2013-03-12 23:35:08 +01:00
|
|
|
class MotionIdentifierMixin(forms.ModelForm):
|
|
|
|
"""Mixin to let the user choose the identifier for the motion."""
|
|
|
|
|
2013-04-22 19:59:05 +02:00
|
|
|
identifier = forms.CharField(required=False, label=ugettext_lazy("Identifier"))
|