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.
|
|
|
|
"""
|
|
|
|
|
2013-02-16 10:41:22 +01:00
|
|
|
import re
|
|
|
|
|
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 _
|
2012-02-20 00:14:54 +01:00
|
|
|
from mptt.forms import TreeNodeChoiceField
|
|
|
|
|
2012-07-10 13:19:12 +02:00
|
|
|
from openslides.utils.forms import CssClassMixin
|
2013-02-18 18:56:37 +01:00
|
|
|
from .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.
|
|
|
|
"""
|
2012-11-24 14:01:21 +01:00
|
|
|
parent = TreeNodeChoiceField(
|
|
|
|
queryset=Item.objects.all(), label=_("Parent item"), required=False)
|
2012-07-04 12:50:33 +02:00
|
|
|
|
2013-02-05 16:36:57 +01:00
|
|
|
duration = forms.RegexField(
|
|
|
|
regex=re.compile('[0-99]:[0-5][0-9]'),
|
|
|
|
error_message=_("Invalid format. Hours from 0 to 99 and minutes from 00 to 59"),
|
|
|
|
max_length=5,
|
2013-01-30 17:39:53 +01:00
|
|
|
required=False,
|
2013-02-18 18:56:37 +01:00
|
|
|
label=_("Duration (hh:mm)"))
|
2013-01-29 14:28:42 +01:00
|
|
|
|
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(),
|
2013-02-18 18:56:37 +01:00
|
|
|
widget=forms.Select(attrs={'class': 'menu-weight'}))
|
2012-07-04 12:50:33 +02:00
|
|
|
self = forms.IntegerField(
|
2013-02-18 18:56:37 +01:00
|
|
|
widget=forms.HiddenInput(attrs={'class': 'menu-mlid'}))
|
2012-07-04 12:50:33 +02:00
|
|
|
parent = forms.IntegerField(
|
2013-02-18 18:56:37 +01:00
|
|
|
widget=forms.HiddenInput(attrs={'class': 'menu-plid'}))
|
2013-01-30 17:39:53 +01:00
|
|
|
|
2013-02-16 10:41:22 +01:00
|
|
|
|
2013-02-01 14:47:51 +01:00
|
|
|
class ConfigForm(CssClassMixin, forms.Form):
|
2013-02-05 16:36:57 +01:00
|
|
|
agenda_start_event_date_time = forms.CharField(
|
|
|
|
widget=forms.DateTimeInput(format='%d.%m.%Y %H:%M'),
|
2013-01-30 17:39:53 +01:00
|
|
|
required=False,
|
2013-02-18 18:56:37 +01:00
|
|
|
label=_("Begin of event"))
|