2013-02-20 23:50:34 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2013-05-27 22:24:16 +02:00
|
|
|
from datetime import datetime
|
|
|
|
|
2013-09-25 10:01:01 +02:00
|
|
|
from django import forms
|
2013-09-07 00:18:13 +02:00
|
|
|
from django.contrib.contenttypes.models import ContentType
|
2013-09-25 10:01:01 +02:00
|
|
|
from django.core.exceptions import ValidationError
|
2013-09-07 00:18:13 +02:00
|
|
|
from django.db.models.signals import pre_delete
|
2013-02-20 23:50:34 +01:00
|
|
|
from django.dispatch import receiver
|
2013-03-18 12:34:47 +01:00
|
|
|
from django.template.loader import render_to_string
|
2013-09-25 10:01:01 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
from django.utils.translation import ugettext_lazy, ugettext_noop
|
2013-02-20 23:50:34 +01:00
|
|
|
|
2013-12-02 19:33:43 +01:00
|
|
|
from openslides.config.api import config, ConfigCollection, ConfigVariable
|
2013-03-01 17:13:12 +01:00
|
|
|
from openslides.config.signals import config_signal
|
2013-11-24 17:19:14 +01:00
|
|
|
from openslides.projector.api import get_active_slide, get_active_object
|
2013-09-25 10:01:01 +02:00
|
|
|
from openslides.projector.projector import Overlay
|
|
|
|
from openslides.projector.signals import projector_overlays
|
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:
|
|
|
|
raise ValidationError(_('Invalid input.'))
|
|
|
|
|
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
# TODO: Reinsert the datepicker scripts in the template
|
|
|
|
|
2013-12-02 19:33:43 +01:00
|
|
|
@receiver(config_signal, dispatch_uid='setup_agenda_config')
|
|
|
|
def setup_agenda_config(sender, **kwargs):
|
2013-03-01 17:13:12 +01:00
|
|
|
"""
|
|
|
|
Agenda config variables.
|
|
|
|
"""
|
|
|
|
# TODO: Insert validator for the format or use other field carefully.
|
|
|
|
agenda_start_event_date_time = ConfigVariable(
|
|
|
|
name='agenda_start_event_date_time',
|
|
|
|
default_value='',
|
|
|
|
form_field=forms.CharField(
|
2013-05-27 22:24:16 +02:00
|
|
|
validators=[validate_start_time, ],
|
2013-03-01 17:13:12 +01:00
|
|
|
widget=forms.DateTimeInput(format='%d.%m.%Y %H:%M'),
|
|
|
|
required=False,
|
2013-06-03 16:01:16 +02:00
|
|
|
label=ugettext_lazy('Begin of event'),
|
|
|
|
help_text=ugettext_lazy('Input format: DD.MM.YYYY HH:MM')))
|
2013-04-27 10:16:32 +02:00
|
|
|
|
|
|
|
agenda_show_last_speakers = ConfigVariable(
|
|
|
|
name='agenda_show_last_speakers',
|
2013-04-29 20:03:50 +02:00
|
|
|
default_value=1,
|
2013-04-27 10:16:32 +02:00
|
|
|
form_field=forms.IntegerField(
|
|
|
|
min_value=0,
|
2013-06-03 16:01:16 +02:00
|
|
|
label=ugettext_lazy('Number of last speakers to be shown on the projector')))
|
2013-03-01 17:13:12 +01:00
|
|
|
|
2013-10-07 08:52:18 +02:00
|
|
|
agenda_couple_countdown_and_speakers = ConfigVariable(
|
|
|
|
name='agenda_couple_countdown_and_speakers',
|
|
|
|
default_value=False,
|
|
|
|
form_field=forms.BooleanField(
|
|
|
|
label=ugettext_lazy('Couple countdown with the list of speakers'),
|
|
|
|
help_text=ugettext_lazy('[Begin speach] starts the countdown, [End speach] stops the countdown.'),
|
|
|
|
required=False))
|
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
extra_stylefiles = ['styles/timepicker.css', 'styles/jquery-ui/jquery-ui.custom.min.css']
|
|
|
|
extra_javascript = ['javascript/jquery-ui.custom.min.js',
|
|
|
|
'javascript/jquery-ui-timepicker-addon.min.js',
|
2013-04-03 14:51:19 +02:00
|
|
|
'javascript/jquery-ui-sliderAccess.min.js',
|
|
|
|
'javascript/agenda-config-datepicker.js']
|
2013-03-01 17:13:12 +01:00
|
|
|
|
2013-12-02 19:33:43 +01:00
|
|
|
return ConfigCollection(title=ugettext_noop('Agenda'),
|
|
|
|
url='agenda',
|
|
|
|
required_permission='config.can_manage',
|
|
|
|
weight=20,
|
|
|
|
variables=(agenda_start_event_date_time,
|
|
|
|
agenda_show_last_speakers,
|
|
|
|
agenda_couple_countdown_and_speakers),
|
|
|
|
extra_context={'extra_stylefiles': extra_stylefiles,
|
|
|
|
'extra_javascript': extra_javascript})
|
2013-03-18 12:34:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
@receiver(projector_overlays, dispatch_uid="agenda_list_of_speakers")
|
|
|
|
def agenda_list_of_speakers(sender, **kwargs):
|
|
|
|
"""
|
|
|
|
Receiver for the list of speaker overlay.
|
|
|
|
"""
|
|
|
|
name = 'agenda_speaker'
|
|
|
|
|
|
|
|
def get_widget_html():
|
|
|
|
"""
|
|
|
|
Returns the the html-code to show in the overly-widget.
|
|
|
|
"""
|
|
|
|
return render_to_string('agenda/overlay_speaker_widget.html')
|
|
|
|
|
|
|
|
def get_projector_html():
|
|
|
|
"""
|
|
|
|
Returns an html-code to show on the projector.
|
2013-08-04 12:59:11 +02:00
|
|
|
|
|
|
|
The overlay is only shown on agenda-items and not on the
|
|
|
|
list-of-speakers slide.
|
2013-03-18 12:34:47 +01:00
|
|
|
"""
|
2013-11-24 17:19:14 +01:00
|
|
|
slide = get_active_object()
|
|
|
|
if isinstance(slide, Item):
|
|
|
|
item = slide
|
|
|
|
else:
|
|
|
|
# TODO: If there are more the one items, use the first one in the
|
|
|
|
# mptt tree that is not closed
|
|
|
|
try:
|
|
|
|
item = Item.objects.filter(
|
|
|
|
content_type=ContentType.objects.get_for_model(slide),
|
|
|
|
object_id=slide.pk)[0]
|
|
|
|
except IndexError:
|
|
|
|
item = None
|
|
|
|
|
|
|
|
if item and get_active_slide().get('type', None) != 'list_of_speakers':
|
2013-08-04 12:59:11 +02:00
|
|
|
list_of_speakers = item.get_list_of_speakers(
|
|
|
|
old_speakers_count=config['agenda_show_last_speakers'],
|
|
|
|
coming_speakers_count=5)
|
2013-11-24 17:19:14 +01:00
|
|
|
|
|
|
|
value = render_to_string('agenda/overlay_speaker_projector.html', {
|
2013-08-04 12:59:11 +02:00
|
|
|
'list_of_speakers': list_of_speakers,
|
2013-11-24 17:19:14 +01:00
|
|
|
'closed': item.speaker_list_closed})
|
2013-08-04 12:59:11 +02:00
|
|
|
else:
|
2013-11-24 17:19:14 +01:00
|
|
|
value = None
|
|
|
|
return value
|
2013-03-18 12:34:47 +01:00
|
|
|
|
|
|
|
return Overlay(name, get_widget_html, get_projector_html)
|
2013-09-07 00:18:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
@receiver(pre_delete)
|
|
|
|
def listen_to_related_object_delete_signal(sender, instance, **kwargs):
|
|
|
|
"""
|
|
|
|
Receiver to listen whether a related item has been deleted.
|
|
|
|
"""
|
|
|
|
if hasattr(instance, 'get_agenda_title'):
|
|
|
|
for item in Item.objects.filter(content_type=ContentType.objects.get_for_model(sender), object_id=instance.pk):
|
|
|
|
item.title = '< Item for deleted slide (%s) >' % instance.get_agenda_title()
|
|
|
|
item.content_type = None
|
|
|
|
item.object_id = None
|
|
|
|
item.save()
|