2011-07-31 10:46:29 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
openslides.application.forms
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Forms for the application app.
|
|
|
|
|
|
|
|
:copyright: 2011 by the OpenSlides team, see AUTHORS.
|
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
|
2011-11-09 22:53:10 +01:00
|
|
|
from django.forms import ModelForm, Form, CharField, Textarea, TextInput, ModelMultipleChoiceField, ModelChoiceField, BooleanField, FileField, FileInput
|
2011-11-01 06:47:10 +01:00
|
|
|
from django.contrib.auth.models import User
|
2011-07-31 10:46:29 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
2012-02-20 18:44:02 +01:00
|
|
|
from utils.forms import CssClassMixin
|
|
|
|
from application.models import Application
|
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
|
2011-11-01 06:47:10 +01:00
|
|
|
class UserModelChoiceField(ModelChoiceField):
|
|
|
|
"""
|
|
|
|
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()
|
|
|
|
|
|
|
|
class UserModelMultipleChoiceField(ModelMultipleChoiceField):
|
|
|
|
"""
|
|
|
|
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-02-20 18:44:02 +01:00
|
|
|
class ApplicationForm(Form, CssClassMixin):
|
2011-07-31 10:46:29 +02:00
|
|
|
title = CharField(widget=TextInput(), label=_("Title"))
|
|
|
|
text = CharField(widget=Textarea(), label=_("Text"))
|
|
|
|
reason = CharField(widget=Textarea(), required=False, label=_("Reason"))
|
2011-11-09 22:53:10 +01:00
|
|
|
trivial_change = BooleanField(required=False, label=_("Trivial change"), help_text=_("Trivial changes don't create a new version."))
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-02-20 18:44:02 +01:00
|
|
|
class ApplicationManagerForm(ModelForm, CssClassMixin):
|
2011-11-01 06:47:10 +01:00
|
|
|
users = User.objects.all().exclude(profile=None).order_by("first_name")
|
|
|
|
submitter = UserModelChoiceField(queryset=users, label=_("Submitter"))
|
2011-11-01 14:35:58 +01:00
|
|
|
supporter = UserModelMultipleChoiceField(queryset=users, required=False, label=_("Supporters"))
|
2011-11-01 06:47:10 +01:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
class Meta:
|
|
|
|
model = Application
|
|
|
|
exclude = ('number', 'status', 'permitted', 'log')
|
2011-11-09 22:53:10 +01:00
|
|
|
|
2012-02-20 18:44:02 +01:00
|
|
|
class ApplicationImportForm(Form, CssClassMixin):
|
2011-11-09 22:53:10 +01:00
|
|
|
csvfile = FileField(widget=FileInput(attrs={'size':'50'}), label=_("CSV File"))
|