2011-07-31 10:46:29 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2013-02-16 10:41:22 +01:00
|
|
|
import re
|
2014-05-11 19:10:08 +02:00
|
|
|
from ckeditor.widgets import CKEditorWidget
|
2013-02-16 10:41:22 +01:00
|
|
|
|
2012-07-04 12:50:33 +02:00
|
|
|
from django import forms
|
2013-03-01 17:13:12 +01:00
|
|
|
from django.utils.translation import ugettext_lazy
|
2012-02-20 00:14:54 +01:00
|
|
|
from mptt.forms import TreeNodeChoiceField
|
|
|
|
|
2013-10-15 16:18:40 +02:00
|
|
|
from openslides.utils.forms import CssClassMixin, CleanHtmlFormMixin
|
2013-03-18 12:34:47 +01:00
|
|
|
from openslides.utils.person.forms import PersonFormField
|
2013-09-25 10:01:01 +02:00
|
|
|
|
2013-03-18 12:34:47 +01:00
|
|
|
from .models import Item, Speaker
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-02-09 02:29:38 +01:00
|
|
|
|
2013-10-15 16:18:40 +02:00
|
|
|
class ItemForm(CleanHtmlFormMixin, CssClassMixin, forms.ModelForm):
|
2012-07-04 12:50:33 +02:00
|
|
|
"""
|
|
|
|
Form to create of update an item.
|
|
|
|
"""
|
2013-10-15 16:18:40 +02:00
|
|
|
clean_html_fields = ('text', )
|
|
|
|
|
2012-11-24 14:01:21 +01:00
|
|
|
parent = TreeNodeChoiceField(
|
2013-03-01 17:13:12 +01:00
|
|
|
queryset=Item.objects.all(), label=ugettext_lazy("Parent item"), required=False)
|
2012-07-04 12:50:33 +02:00
|
|
|
|
2013-02-05 16:36:57 +01:00
|
|
|
duration = forms.RegexField(
|
2013-11-19 13:48:55 +01:00
|
|
|
regex=re.compile('^(?:[0-9]{1,2}:[0-5][0-9]|[0-9]+)$'),
|
2013-03-01 17:13:12 +01:00
|
|
|
error_message=ugettext_lazy("Invalid format. Hours from 0 to 99 and minutes from 00 to 59"),
|
2013-02-05 16:36:57 +01:00
|
|
|
max_length=5,
|
2013-01-30 17:39:53 +01:00
|
|
|
required=False,
|
2013-11-22 09:01:52 +01:00
|
|
|
label=ugettext_lazy("Duration"),
|
2013-11-22 10:16:15 +01:00
|
|
|
help_text=ugettext_lazy('Input format: HH:MM or M or MM or MMM'))
|
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
|
2014-12-26 13:45:13 +01:00
|
|
|
fields = ('item_number', 'title', 'text', 'comment', 'tags', 'type', 'duration', 'parent', 'speaker_list_closed')
|
2014-05-11 19:10:08 +02:00
|
|
|
widgets = {'text': CKEditorWidget(config_name='images')}
|
2011-07-31 10:46:29 +02:00
|
|
|
|
|
|
|
|
2013-06-14 09:00:37 +02:00
|
|
|
class RelatedItemForm(ItemForm):
|
|
|
|
"""
|
|
|
|
Form to update an related item.
|
|
|
|
"""
|
|
|
|
class Meta:
|
|
|
|
model = Item
|
2014-04-28 01:03:10 +02:00
|
|
|
fields = ('comment', 'duration', 'parent', 'speaker_list_closed')
|
2013-06-14 09:00:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ItemOrderForm(CssClassMixin, forms.Form):
|
2012-07-04 12:50:33 +02:00
|
|
|
"""
|
|
|
|
Form to change the order of the items.
|
|
|
|
"""
|
2013-03-16 17:02:14 +01:00
|
|
|
weight = forms.IntegerField(
|
|
|
|
widget=forms.HiddenInput(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-03-18 12:34:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
class AppendSpeakerForm(CssClassMixin, forms.Form):
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
Form to set an user to a list of speakers.
|
|
|
|
"""
|
2013-03-18 12:34:47 +01:00
|
|
|
speaker = PersonFormField(
|
|
|
|
widget=forms.Select(attrs={'class': 'medium-input'}),
|
2013-04-14 00:20:35 +02:00
|
|
|
label=ugettext_lazy("Add participant"))
|
2013-03-18 12:34:47 +01:00
|
|
|
|
|
|
|
def __init__(self, item, *args, **kwargs):
|
|
|
|
self.item = item
|
|
|
|
return super(AppendSpeakerForm, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def clean_speaker(self):
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
|
|
|
Checks, that the user is not already on the list.
|
|
|
|
"""
|
2013-03-18 12:34:47 +01:00
|
|
|
speaker = self.cleaned_data['speaker']
|
2013-04-25 16:18:16 +02:00
|
|
|
if Speaker.objects.filter(person=speaker, item=self.item, begin_time=None).exists():
|
2013-03-18 12:34:47 +01:00
|
|
|
raise forms.ValidationError(ugettext_lazy(
|
2013-04-14 00:20:35 +02:00
|
|
|
'%s is already on the list of speakers.'
|
|
|
|
% unicode(speaker)))
|
2013-03-18 12:34:47 +01:00
|
|
|
return speaker
|