load form-css-classes from utils.forms.py instead to define it on every form

This commit is contained in:
Oskar Hahn 2012-02-20 18:44:02 +01:00
parent efb3774beb
commit 8c597a2eb3
7 changed files with 36 additions and 68 deletions

View File

@ -16,12 +16,12 @@ from django.utils.translation import ugettext as _
from mptt.forms import TreeNodeChoiceField
from utils.forms import CssClassMixin
from agenda.models import Item
class ItemForm(ModelForm):
error_css_class = 'error'
required_css_class = 'required'
class ItemForm(ModelForm, CssClassMixin):
parent = TreeNodeChoiceField(queryset=Item.objects.all(), label=_("Parent item"), required=False)
class Meta:
model = Item
@ -35,7 +35,7 @@ def genweightchoices():
return l
class ItemOrderForm(Form):
class ItemOrderForm(Form, CssClassMixin):
weight = ChoiceField(choices=genweightchoices(),
widget=Select(attrs={'class': 'menu-weight'}),
label="")

View File

@ -126,7 +126,6 @@ class Item(MPTTModel, Slide):
('can_manage_agenda', "Can manage agenda"),
('can_see_projector', "Can see projector"),
)
#ordering = ['weight']
class MPTTMeta:
order_insertion_by = ['weight', 'title']

View File

@ -14,7 +14,9 @@ from django.forms import ModelForm, Form, CharField, Textarea, TextInput, ModelM
from django.contrib.auth.models import User
from django.utils.translation import ugettext as _
from openslides.application.models import Application
from utils.forms import CssClassMixin
from application.models import Application
class UserModelChoiceField(ModelChoiceField):
@ -34,19 +36,13 @@ class UserModelMultipleChoiceField(ModelMultipleChoiceField):
return obj.get_full_name()
class ApplicationForm(Form):
error_css_class = 'error'
required_css_class = 'required'
class ApplicationForm(Form, CssClassMixin):
title = CharField(widget=TextInput(), label=_("Title"))
text = CharField(widget=Textarea(), label=_("Text"))
reason = CharField(widget=Textarea(), required=False, label=_("Reason"))
trivial_change = BooleanField(required=False, label=_("Trivial change"), help_text=_("Trivial changes don't create a new version."))
class ApplicationManagerForm(ModelForm):
error_css_class = 'error'
required_css_class = 'required'
class ApplicationManagerForm(ModelForm, CssClassMixin):
users = User.objects.all().exclude(profile=None).order_by("first_name")
submitter = UserModelChoiceField(queryset=users, label=_("Submitter"))
supporter = UserModelMultipleChoiceField(queryset=users, required=False, label=_("Supporters"))
@ -55,8 +51,5 @@ class ApplicationManagerForm(ModelForm):
model = Application
exclude = ('number', 'status', 'permitted', 'log')
class ApplicationImportForm(Form):
error_css_class = 'error'
required_css_class = 'required'
class ApplicationImportForm(Form, CssClassMixin):
csvfile = FileField(widget=FileInput(attrs={'size':'50'}), label=_("CSV File"))

View File

@ -13,23 +13,20 @@
from django.forms import ModelForm, Form, ModelChoiceField, Select
from django.utils.translation import ugettext as _
from utils.forms import CssClassMixin
from participant.models import Profile
from assignment.models import Assignment
class AssignmentForm(ModelForm):
error_css_class = 'error'
required_css_class = 'required'
class AssignmentForm(ModelForm, CssClassMixin):
class Meta:
model = Assignment
exclude = ('status', 'profile', 'elected')
class AssignmentRunForm(Form):
error_css_class = 'error'
class AssignmentRunForm(Form, CssClassMixin):
candidate = ModelChoiceField(
widget=Select(attrs={'class': 'medium-input'}), \
queryset=Profile.objects.all().order_by('user__first_name'), \
label=_("Nominate a participant"))
widget=Select(attrs={'class': 'medium-input'}),
queryset=Profile.objects.all().order_by('user__first_name'),
label=_("Nominate a participant"),
)

View File

@ -15,6 +15,8 @@ from django.contrib.auth.models import User, Group, Permission
from django.contrib.auth.forms import AdminPasswordChangeForm
from django.utils.translation import ugettext as _
from utils.forms import CssClassMixin
# required for USER_VISIBLE_PERMISSIONS
from agenda.models import Item
from application.models import Application
@ -30,10 +32,8 @@ USER_VISIBLE_PERMISSIONS = reduce(list.__add__, [
[p[0] for p in ConfigStore._meta.permissions]
])
class UserNewForm(ModelForm):
error_css_class = 'error'
required_css_class = 'required'
class UserNewForm(ModelForm, CssClassMixin):
first_name = CharField(label=_("First name"))
last_name = CharField(label=_("Last name"))
@ -41,10 +41,8 @@ class UserNewForm(ModelForm):
model = User
exclude = ('username', 'password', 'is_staff', 'last_login', 'date_joined', 'user_permissions')
class UserEditForm(ModelForm):
error_css_class = 'error'
required_css_class = 'required'
class UserEditForm(ModelForm, CssClassMixin):
first_name = CharField(label=_("First name"))
last_name = CharField(label=_("Last name"))
@ -52,24 +50,17 @@ class UserEditForm(ModelForm):
model = User
exclude = ('password', 'is_staff', 'last_login', 'date_joined', 'user_permissions')
class UsernameForm(ModelForm):
error_css_class = 'error'
required_css_class = 'required'
class UsernameForm(ModelForm, CssClassMixin):
class Meta:
model = User
exclude = ('first_name', 'last_name', 'email', 'is_active','is_superuser', 'groups', 'password', 'is_staff', 'last_login', 'date_joined', 'user_permissions')
class ProfileForm(ModelForm):
error_css_class = 'error'
required_css_class = 'required'
class ProfileForm(ModelForm, CssClassMixin):
class Meta:
model = Profile
class GroupForm(ModelForm):
error_css_class = 'error'
required_css_class = 'required'
class GroupForm(ModelForm, CssClassMixin):
permissions = ModelMultipleChoiceField(queryset=Permission.objects.filter(codename__in=USER_VISIBLE_PERMISSIONS))
def __init__(self, *args, **kwargs):
@ -81,13 +72,10 @@ class GroupForm(ModelForm):
model = Group
exclude = ('permissions',)
class UsersettingsForm(UserEditForm):
class UsersettingsForm(UserEditForm, CssClassMixin):
class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email')
class UserImportForm(Form):
error_css_class = 'error'
required_css_class = 'required'
class UserImportForm(Form, CssClassMixin):
csvfile = FileField(widget=FileInput(attrs={'size':'50'}), label=_("CSV File"))

View File

@ -1,8 +1,10 @@
from django import forms
from django.utils.translation import ugettext as _
from utils.forms import CssClassMixin
class OptionForm(forms.Form):
class OptionForm(forms.Form, CssClassMixin):
def __init__(self, *args, **kwargs):
extra = kwargs.pop('extra')
formid = kwargs.pop('formid')

View File

@ -12,37 +12,29 @@
from django.forms import Form, CharField, TextInput, BooleanField, IntegerField, ChoiceField, Textarea, Select
from django.utils.translation import ugettext as _
from utils.forms import CssClassMixin
from system import config
class SystemConfigForm(Form):
error_css_class = 'error'
required_css_class = 'required'
#user_registration = BooleanField(label=_("User registration"), required=False)
class SystemConfigForm(Form, CssClassMixin):
system_url = CharField(widget=TextInput(), required=False, label=_("System URL"))
system_welcometext = CharField(widget=Textarea(), required=False, label=_("Welcome text (for password PDF)"))
system_enable_anonymous = BooleanField(required=False, label=_("Access for anonymous / guest users"), help_text=_("Allow access for guest users"))
class EventConfigForm(Form):
error_css_class = 'error'
required_css_class = 'required'
class EventConfigForm(Form, CssClassMixin):
event_name = CharField(widget=TextInput(),label=_("Event name"), max_length=30)
event_description = CharField(widget=TextInput(),label=_("Short description of event"), max_length=100, required=False)
event_date = CharField(widget=TextInput(), required=False, label=_("Event date"))
event_location = CharField(widget=TextInput(), required=False, label=_("Event location"))
event_organizer = CharField(widget=TextInput(), required=False, label=_("Event organizer"))
class AgendaConfigForm(Form):
error_css_class = 'error'
required_css_class = 'required'
class AgendaConfigForm(Form, CssClassMixin):
agenda_countdown_time = IntegerField(widget=TextInput(attrs={'class':'small-input'}),label=_("Countdown (in seconds)"),initial=60, min_value=0)
class ApplicationConfigForm(Form):
error_css_class = 'error'
required_css_class = 'required'
class ApplicationConfigForm(Form, CssClassMixin):
application_min_supporters = IntegerField(widget=TextInput(attrs={'class':'small-input'}),label=_("Number of (minimum) required supporters for a application"),initial=4, min_value=0, max_value=8)
application_preamble = CharField(widget=TextInput(), required=False, label=_("Application preamble"))
application_pdf_ballot_papers_selection = ChoiceField(widget=Select(), required=False, label=_("Number of ballot papers (selection)"), choices=[("1", _("Number of all delegates")),("2", _("Number of all participants")),("0", _("Use the following custum number"))])
@ -50,10 +42,7 @@ class ApplicationConfigForm(Form):
application_pdf_title = CharField(widget=TextInput(), required=False, label=_("Title for PDF document (all applications)"))
application_pdf_preamble = CharField(widget=Textarea(), required=False, label=_("Preamble text for PDF document (all applications)"))
class AssignmentConfigForm(Form):
error_css_class = 'error'
required_css_class = 'required'
class AssignmentConfigForm(Form, CssClassMixin):
assignment_publish_winner_results_only = BooleanField(required=False, label=_("Only publish voting results for selected winners (Projector view only)"))
assignment_pdf_ballot_papers_selection = ChoiceField(widget=Select(), required=False, label=_("Number of ballot papers (selection)"), choices=[("1", _("Number of all delegates")),("2", _("Number of all participants")),("0", _("Use the following custum number"))])
assignment_pdf_ballot_papers_number = IntegerField(widget=TextInput(attrs={'class':'small-input'}), required=False, min_value=1, label=_("Custom number of ballot papers"))