OpenSlides/openslides/agenda/forms.py

56 lines
1.3 KiB
Python
Raw Normal View History

2011-07-31 10:46:29 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
openslides.agenda.forms
~~~~~~~~~~~~~~~~~~~~~~~
Forms for the agenda app.
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-04 12:50:33 +02:00
from django import forms
2012-07-10 01:33:03 +02:00
from django.utils.translation import ugettext_lazy as _
from mptt.forms import TreeNodeChoiceField
from utils.forms import CssClassMixin
from agenda.models import Item
2011-07-31 10:46:29 +02:00
2012-02-09 02:29:38 +01:00
2012-07-04 12:50:33 +02:00
class ItemForm(forms.ModelForm, CssClassMixin):
"""
Form to create of update an item.
"""
parent = TreeNodeChoiceField(queryset=Item.objects.all(),
label=_("Parent item"), required=False)
2011-07-31 10:46:29 +02:00
class Meta:
2012-02-06 22:22:16 +01:00
model = Item
2012-07-04 11:00:58 +02:00
exclude = ('closed', 'weight', 'related_sid')
2011-07-31 10:46:29 +02:00
2012-07-04 12:50:33 +02:00
def gen_weight_choices():
"""
Creates a list of tuples (n, n) for n from -49 to 50.
"""
return zip(*(range(-50, 51), range(-50, 51)))
class ItemOrderForm(forms.Form, CssClassMixin):
"""
Form to change the order of the items.
"""
weight = forms.ChoiceField(
choices=gen_weight_choices(),
widget=forms.Select(attrs={'class': 'menu-weight'}),
)
self = forms.IntegerField(
widget=forms.HiddenInput(attrs={'class': 'menu-mlid'}),
)
parent = forms.IntegerField(
widget=forms.HiddenInput(attrs={'class': 'menu-plid'}),
)