2013-05-27 22:24:16 +02:00
|
|
|
from datetime import datetime
|
|
|
|
|
2013-09-07 00:18:13 +02:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2015-06-17 18:32:05 +02:00
|
|
|
from django.core.exceptions import ValidationError as DjangoValidationError
|
|
|
|
from django.core.validators import MaxLengthValidator, MinValueValidator
|
2013-09-25 10:01:01 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
2015-06-17 18:32:05 +02:00
|
|
|
from django.utils.translation import ugettext_lazy
|
2013-02-20 23:50:34 +01:00
|
|
|
|
2015-06-29 12:08:15 +02:00
|
|
|
from openslides.core.config import ConfigVariable
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2013-09-25 10:01:01 +02:00
|
|
|
from .models import Item
|
2013-03-18 12:34:47 +01:00
|
|
|
|
2013-02-20 23:50:34 +01:00
|
|
|
|
2013-05-27 22:24:16 +02:00
|
|
|
def validate_start_time(value):
|
|
|
|
try:
|
|
|
|
datetime.strptime(value, '%d.%m.%Y %H:%M')
|
|
|
|
except ValueError:
|
2015-06-17 18:32:05 +02:00
|
|
|
raise DjangoValidationError(_('Invalid input.'))
|
2013-05-27 22:24:16 +02:00
|
|
|
|
|
|
|
|
2013-12-02 19:33:43 +01:00
|
|
|
def setup_agenda_config(sender, **kwargs):
|
2013-03-01 17:13:12 +01:00
|
|
|
"""
|
2015-06-17 18:32:05 +02:00
|
|
|
Receiver function to setup all agenda config variables. They are not
|
|
|
|
grouped. This function connected to the signal
|
2015-06-29 12:08:15 +02:00
|
|
|
openslides.core.signals.config_signal during app loading.
|
2013-03-01 17:13:12 +01:00
|
|
|
"""
|
2015-06-17 18:32:05 +02:00
|
|
|
# TODO: Use an input type with generic datetime support.
|
|
|
|
yield ConfigVariable(
|
2013-03-01 17:13:12 +01:00
|
|
|
name='agenda_start_event_date_time',
|
|
|
|
default_value='',
|
2015-06-17 18:32:05 +02:00
|
|
|
label=ugettext_lazy('Begin of event'),
|
|
|
|
help_text=ugettext_lazy('Input format: DD.MM.YYYY HH:MM'),
|
|
|
|
weight=210,
|
|
|
|
group=ugettext_lazy('Agenda'),
|
|
|
|
validators=(validate_start_time,))
|
2013-04-27 10:16:32 +02:00
|
|
|
|
2015-06-17 18:32:05 +02:00
|
|
|
yield ConfigVariable(
|
2013-04-27 10:16:32 +02:00
|
|
|
name='agenda_show_last_speakers',
|
2013-04-29 20:03:50 +02:00
|
|
|
default_value=1,
|
2015-06-17 18:32:05 +02:00
|
|
|
input_type='integer',
|
|
|
|
label=ugettext_lazy('Number of last speakers to be shown on the projector'),
|
|
|
|
weight=220,
|
|
|
|
group=ugettext_lazy('Agenda'),
|
|
|
|
validators=(MinValueValidator(0),))
|
2013-03-01 17:13:12 +01:00
|
|
|
|
2015-06-17 18:32:05 +02:00
|
|
|
yield ConfigVariable(
|
2013-10-07 08:52:18 +02:00
|
|
|
name='agenda_couple_countdown_and_speakers',
|
|
|
|
default_value=False,
|
2015-06-17 18:32:05 +02:00
|
|
|
input_type='boolean',
|
|
|
|
label=ugettext_lazy('Couple countdown with the list of speakers'),
|
2015-09-04 18:24:41 +02:00
|
|
|
help_text=ugettext_lazy('[Begin speech] starts the countdown, [End speech] stops the countdown.'),
|
2015-06-17 18:32:05 +02:00
|
|
|
weight=230,
|
|
|
|
group=ugettext_lazy('Agenda'))
|
2013-10-07 08:52:18 +02:00
|
|
|
|
2015-06-17 18:32:05 +02:00
|
|
|
yield ConfigVariable(
|
2014-04-27 21:01:23 +02:00
|
|
|
name='agenda_number_prefix',
|
|
|
|
default_value='',
|
2015-06-17 18:32:05 +02:00
|
|
|
label=ugettext_lazy('Numbering prefix for agenda items'),
|
|
|
|
weight=240,
|
|
|
|
group=ugettext_lazy('Agenda'),
|
|
|
|
validators=(MaxLengthValidator(20),))
|
2014-04-27 21:01:23 +02:00
|
|
|
|
2015-06-17 18:32:05 +02:00
|
|
|
yield ConfigVariable(
|
2014-04-27 21:01:23 +02:00
|
|
|
name='agenda_numeral_system',
|
2014-04-28 01:03:10 +02:00
|
|
|
default_value='arabic',
|
2015-06-17 18:32:05 +02:00
|
|
|
input_type='choice',
|
|
|
|
label=ugettext_lazy('Numeral system for agenda items'),
|
|
|
|
choices=(
|
|
|
|
{'value': 'arabic', 'display_name': ugettext_lazy('Arabic')},
|
|
|
|
{'value': 'roman', 'display_name': ugettext_lazy('Roman')}),
|
|
|
|
weight=250,
|
|
|
|
group=ugettext_lazy('Agenda'))
|
2013-03-18 12:34:47 +01:00
|
|
|
|
|
|
|
|
2013-09-07 00:18:13 +02:00
|
|
|
def listen_to_related_object_delete_signal(sender, instance, **kwargs):
|
|
|
|
"""
|
2015-06-17 18:32:05 +02:00
|
|
|
Receiver function to change agenda items of a related item that is to
|
2014-11-13 22:23:16 +01:00
|
|
|
be deleted. It is connected to the signal
|
|
|
|
django.db.models.signals.pre_delete during app loading.
|
2013-09-07 00:18:13 +02:00
|
|
|
"""
|
|
|
|
if hasattr(instance, 'get_agenda_title'):
|
|
|
|
for item in Item.objects.filter(content_type=ContentType.objects.get_for_model(sender), object_id=instance.pk):
|
2015-06-17 18:32:05 +02:00
|
|
|
item.title = '< Item for deleted (%s) >' % instance.get_agenda_title()
|
2013-09-07 00:18:13 +02:00
|
|
|
item.content_type = None
|
|
|
|
item.object_id = None
|
|
|
|
item.save()
|