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 mptt.forms import TreeNodeChoiceField
from utils.forms import CssClassMixin
from agenda.models import Item 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) parent = TreeNodeChoiceField(queryset=Item.objects.all(), label=_("Parent item"), required=False)
class Meta: class Meta:
model = Item model = Item
@ -35,7 +35,7 @@ def genweightchoices():
return l return l
class ItemOrderForm(Form): class ItemOrderForm(Form, CssClassMixin):
weight = ChoiceField(choices=genweightchoices(), weight = ChoiceField(choices=genweightchoices(),
widget=Select(attrs={'class': 'menu-weight'}), widget=Select(attrs={'class': 'menu-weight'}),
label="") label="")

View File

@ -126,7 +126,6 @@ class Item(MPTTModel, Slide):
('can_manage_agenda', "Can manage agenda"), ('can_manage_agenda', "Can manage agenda"),
('can_see_projector', "Can see projector"), ('can_see_projector', "Can see projector"),
) )
#ordering = ['weight']
class MPTTMeta: class MPTTMeta:
order_insertion_by = ['weight', 'title'] 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.contrib.auth.models import User
from django.utils.translation import ugettext as _ 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): class UserModelChoiceField(ModelChoiceField):
@ -34,19 +36,13 @@ class UserModelMultipleChoiceField(ModelMultipleChoiceField):
return obj.get_full_name() return obj.get_full_name()
class ApplicationForm(Form): class ApplicationForm(Form, CssClassMixin):
error_css_class = 'error'
required_css_class = 'required'
title = CharField(widget=TextInput(), label=_("Title")) title = CharField(widget=TextInput(), label=_("Title"))
text = CharField(widget=Textarea(), label=_("Text")) text = CharField(widget=Textarea(), label=_("Text"))
reason = CharField(widget=Textarea(), required=False, label=_("Reason")) 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.")) trivial_change = BooleanField(required=False, label=_("Trivial change"), help_text=_("Trivial changes don't create a new version."))
class ApplicationManagerForm(ModelForm): class ApplicationManagerForm(ModelForm, CssClassMixin):
error_css_class = 'error'
required_css_class = 'required'
users = User.objects.all().exclude(profile=None).order_by("first_name") users = User.objects.all().exclude(profile=None).order_by("first_name")
submitter = UserModelChoiceField(queryset=users, label=_("Submitter")) submitter = UserModelChoiceField(queryset=users, label=_("Submitter"))
supporter = UserModelMultipleChoiceField(queryset=users, required=False, label=_("Supporters")) supporter = UserModelMultipleChoiceField(queryset=users, required=False, label=_("Supporters"))
@ -55,8 +51,5 @@ class ApplicationManagerForm(ModelForm):
model = Application model = Application
exclude = ('number', 'status', 'permitted', 'log') exclude = ('number', 'status', 'permitted', 'log')
class ApplicationImportForm(Form): class ApplicationImportForm(Form, CssClassMixin):
error_css_class = 'error'
required_css_class = 'required'
csvfile = FileField(widget=FileInput(attrs={'size':'50'}), label=_("CSV File")) 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.forms import ModelForm, Form, ModelChoiceField, Select
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from utils.forms import CssClassMixin
from participant.models import Profile from participant.models import Profile
from assignment.models import Assignment from assignment.models import Assignment
class AssignmentForm(ModelForm): class AssignmentForm(ModelForm, CssClassMixin):
error_css_class = 'error'
required_css_class = 'required'
class Meta: class Meta:
model = Assignment model = Assignment
exclude = ('status', 'profile', 'elected') exclude = ('status', 'profile', 'elected')
class AssignmentRunForm(Form): class AssignmentRunForm(Form, CssClassMixin):
error_css_class = 'error'
candidate = ModelChoiceField( candidate = ModelChoiceField(
widget=Select(attrs={'class': 'medium-input'}), \ widget=Select(attrs={'class': 'medium-input'}),
queryset=Profile.objects.all().order_by('user__first_name'), \ queryset=Profile.objects.all().order_by('user__first_name'),
label=_("Nominate a participant")) 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.contrib.auth.forms import AdminPasswordChangeForm
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from utils.forms import CssClassMixin
# required for USER_VISIBLE_PERMISSIONS # required for USER_VISIBLE_PERMISSIONS
from agenda.models import Item from agenda.models import Item
from application.models import Application from application.models import Application
@ -30,10 +32,8 @@ USER_VISIBLE_PERMISSIONS = reduce(list.__add__, [
[p[0] for p in ConfigStore._meta.permissions] [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")) first_name = CharField(label=_("First name"))
last_name = CharField(label=_("Last name")) last_name = CharField(label=_("Last name"))
@ -41,10 +41,8 @@ class UserNewForm(ModelForm):
model = User model = User
exclude = ('username', 'password', 'is_staff', 'last_login', 'date_joined', 'user_permissions') 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")) first_name = CharField(label=_("First name"))
last_name = CharField(label=_("Last name")) last_name = CharField(label=_("Last name"))
@ -52,24 +50,17 @@ class UserEditForm(ModelForm):
model = User model = User
exclude = ('password', 'is_staff', 'last_login', 'date_joined', 'user_permissions') 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: class Meta:
model = User model = User
exclude = ('first_name', 'last_name', 'email', 'is_active','is_superuser', 'groups', 'password', 'is_staff', 'last_login', 'date_joined', 'user_permissions') exclude = ('first_name', 'last_name', 'email', 'is_active','is_superuser', 'groups', 'password', 'is_staff', 'last_login', 'date_joined', 'user_permissions')
class ProfileForm(ModelForm): class ProfileForm(ModelForm, CssClassMixin):
error_css_class = 'error'
required_css_class = 'required'
class Meta: class Meta:
model = Profile model = Profile
class GroupForm(ModelForm): class GroupForm(ModelForm, CssClassMixin):
error_css_class = 'error'
required_css_class = 'required'
permissions = ModelMultipleChoiceField(queryset=Permission.objects.filter(codename__in=USER_VISIBLE_PERMISSIONS)) permissions = ModelMultipleChoiceField(queryset=Permission.objects.filter(codename__in=USER_VISIBLE_PERMISSIONS))
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -81,13 +72,10 @@ class GroupForm(ModelForm):
model = Group model = Group
exclude = ('permissions',) exclude = ('permissions',)
class UsersettingsForm(UserEditForm): class UsersettingsForm(UserEditForm, CssClassMixin):
class Meta: class Meta:
model = User model = User
fields = ('username', 'first_name', 'last_name', 'email') fields = ('username', 'first_name', 'last_name', 'email')
class UserImportForm(Form): class UserImportForm(Form, CssClassMixin):
error_css_class = 'error'
required_css_class = 'required'
csvfile = FileField(widget=FileInput(attrs={'size':'50'}), label=_("CSV File")) csvfile = FileField(widget=FileInput(attrs={'size':'50'}), label=_("CSV File"))

View File

@ -1,8 +1,10 @@
from django import forms from django import forms
from django.utils.translation import ugettext as _ 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): def __init__(self, *args, **kwargs):
extra = kwargs.pop('extra') extra = kwargs.pop('extra')
formid = kwargs.pop('formid') formid = kwargs.pop('formid')

View File

@ -12,37 +12,29 @@
from django.forms import Form, CharField, TextInput, BooleanField, IntegerField, ChoiceField, Textarea, Select from django.forms import Form, CharField, TextInput, BooleanField, IntegerField, ChoiceField, Textarea, Select
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from utils.forms import CssClassMixin
from system import config 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_url = CharField(widget=TextInput(), required=False, label=_("System URL"))
system_welcometext = CharField(widget=Textarea(), required=False, label=_("Welcome text (for password PDF)")) 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")) 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_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_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_date = CharField(widget=TextInput(), required=False, label=_("Event date"))
event_location = CharField(widget=TextInput(), required=False, label=_("Event location")) event_location = CharField(widget=TextInput(), required=False, label=_("Event location"))
event_organizer = CharField(widget=TextInput(), required=False, label=_("Event organizer")) 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) agenda_countdown_time = IntegerField(widget=TextInput(attrs={'class':'small-input'}),label=_("Countdown (in seconds)"),initial=60, min_value=0)
class ApplicationConfigForm(Form): class ApplicationConfigForm(Form, CssClassMixin):
error_css_class = 'error'
required_css_class = 'required'
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_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_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"))]) 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_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)")) application_pdf_preamble = CharField(widget=Textarea(), required=False, label=_("Preamble text for PDF document (all applications)"))
class AssignmentConfigForm(Form): class AssignmentConfigForm(Form, CssClassMixin):
error_css_class = 'error'
required_css_class = 'required'
assignment_publish_winner_results_only = BooleanField(required=False, label=_("Only publish voting results for selected winners (Projector view only)")) 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_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")) assignment_pdf_ballot_papers_number = IntegerField(widget=TextInput(attrs={'class':'small-input'}), required=False, min_value=1, label=_("Custom number of ballot papers"))