2012-03-16 12:28:42 +01:00
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
"""
|
|
|
|
|
openslides.projector.signals
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
|
Signals for the projector app.
|
2012-03-16 12:28:42 +01:00
|
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
|
:copyright: 2011–2013 by OpenSlides team, see AUTHORS.
|
2012-03-16 12:28:42 +01:00
|
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
|
"""
|
2013-10-26 12:59:39 +02:00
|
|
|
|
from time import time
|
|
|
|
|
|
2013-08-04 12:59:11 +02:00
|
|
|
|
from django.contrib.staticfiles.templatetags.staticfiles import static
|
2013-09-25 10:01:01 +02:00
|
|
|
|
from django.core.context_processors import csrf
|
|
|
|
|
from django.dispatch import receiver, Signal
|
|
|
|
|
from django.template.loader import render_to_string
|
2013-03-01 17:13:12 +01:00
|
|
|
|
|
2013-09-25 10:01:01 +02:00
|
|
|
|
from openslides.config.api import config, ConfigPage, ConfigVariable
|
2013-03-01 17:13:12 +01:00
|
|
|
|
from openslides.config.signals import config_signal
|
|
|
|
|
|
2013-04-15 10:40:47 +02:00
|
|
|
|
from .projector import Overlay
|
2012-03-16 12:28:42 +01:00
|
|
|
|
|
2013-04-15 10:40:47 +02:00
|
|
|
|
projector_overlays = Signal(providing_args=['request'])
|
2013-03-01 17:13:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@receiver(config_signal, dispatch_uid='setup_projector_config_variables')
|
2013-09-25 10:01:01 +02:00
|
|
|
|
def config_variables(sender, **kwargs):
|
2013-03-01 17:13:12 +01:00
|
|
|
|
"""
|
|
|
|
|
Projector config variables for OpenSlides. They are not shown on a
|
|
|
|
|
config page.
|
|
|
|
|
"""
|
|
|
|
|
|
2013-09-25 10:01:01 +02:00
|
|
|
|
# The active slide. The config-value is a dictonary with at least the entry
|
|
|
|
|
# 'callback'.
|
2013-08-04 12:59:11 +02:00
|
|
|
|
projector = ConfigVariable(
|
|
|
|
|
name='projector_active_slide',
|
|
|
|
|
default_value={'callback': None})
|
2013-03-01 17:13:12 +01:00
|
|
|
|
|
|
|
|
|
projector_message = ConfigVariable(
|
|
|
|
|
name='projector_message',
|
|
|
|
|
default_value='')
|
|
|
|
|
|
|
|
|
|
countdown_time = ConfigVariable(
|
|
|
|
|
name='countdown_time',
|
|
|
|
|
default_value=60)
|
|
|
|
|
|
|
|
|
|
countdown_start_stamp = ConfigVariable(
|
|
|
|
|
name='countdown_start_stamp',
|
|
|
|
|
default_value=0)
|
|
|
|
|
|
|
|
|
|
countdown_pause_stamp = ConfigVariable(
|
|
|
|
|
name='countdown_pause_stamp',
|
|
|
|
|
default_value=0)
|
|
|
|
|
|
|
|
|
|
countdown_state = ConfigVariable(
|
|
|
|
|
name='countdown_state',
|
|
|
|
|
default_value='inactive')
|
|
|
|
|
|
2013-10-17 15:32:54 +02:00
|
|
|
|
projector_scale = ConfigVariable(
|
|
|
|
|
name='projector_scale',
|
2013-10-23 17:08:08 +02:00
|
|
|
|
default_value=0)
|
2013-03-01 17:13:12 +01:00
|
|
|
|
|
2013-10-17 15:32:54 +02:00
|
|
|
|
projector_scroll = ConfigVariable(
|
|
|
|
|
name='projector_scroll',
|
2013-03-01 17:13:12 +01:00
|
|
|
|
default_value=0)
|
|
|
|
|
|
2013-10-17 15:32:54 +02:00
|
|
|
|
projector_js_cache = ConfigVariable(
|
|
|
|
|
name='projector_js_cache',
|
|
|
|
|
default_value={})
|
|
|
|
|
|
2013-04-15 10:40:47 +02:00
|
|
|
|
projector_active_overlays = ConfigVariable(
|
|
|
|
|
name='projector_active_overlays',
|
|
|
|
|
default_value=[])
|
|
|
|
|
|
|
|
|
|
return ConfigPage(
|
|
|
|
|
title='No title here', url='bar', required_permission=None, variables=(
|
2013-08-04 12:59:11 +02:00
|
|
|
|
projector, projector_message,
|
2013-04-15 10:40:47 +02:00
|
|
|
|
countdown_time, countdown_start_stamp, countdown_pause_stamp,
|
2013-10-17 15:32:54 +02:00
|
|
|
|
countdown_state, projector_scale, projector_scroll,
|
|
|
|
|
projector_active_overlays, projector_js_cache))
|
2013-04-15 10:40:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@receiver(projector_overlays, dispatch_uid="projector_countdown")
|
|
|
|
|
def countdown(sender, **kwargs):
|
|
|
|
|
"""
|
2013-03-18 12:34:47 +01:00
|
|
|
|
Receiver for the countdown.
|
2013-04-15 10:40:47 +02:00
|
|
|
|
"""
|
|
|
|
|
name = 'projector_countdown'
|
|
|
|
|
request = kwargs.get('request', None)
|
|
|
|
|
|
|
|
|
|
def get_widget_html():
|
|
|
|
|
"""
|
|
|
|
|
Returns the the html-code to show in the overly-widget.
|
|
|
|
|
"""
|
|
|
|
|
context = {
|
|
|
|
|
'countdown_time': config['countdown_time'],
|
|
|
|
|
'countdown_state': config['countdown_state']}
|
|
|
|
|
context.update(csrf(request))
|
2013-08-04 12:59:11 +02:00
|
|
|
|
return render_to_string('projector/overlay_countdown_widget.html',
|
|
|
|
|
context)
|
|
|
|
|
|
|
|
|
|
def get_projector_js():
|
|
|
|
|
"""
|
|
|
|
|
Returns JavaScript for the projector
|
|
|
|
|
"""
|
|
|
|
|
start = int(config['countdown_start_stamp'])
|
|
|
|
|
duration = int(config['countdown_time'])
|
|
|
|
|
pause = int(config['countdown_pause_stamp'])
|
|
|
|
|
state = config['countdown_state']
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
'load_file': static('javascript/countdown.js'),
|
|
|
|
|
'projector_countdown_start': start,
|
|
|
|
|
'projector_countdown_duration': duration,
|
|
|
|
|
'projector_countdown_pause': pause,
|
|
|
|
|
'projector_countdown_state': state}
|
2013-04-15 10:40:47 +02:00
|
|
|
|
|
|
|
|
|
def get_projector_html():
|
|
|
|
|
"""
|
|
|
|
|
Returns an html-code to show on the projector.
|
|
|
|
|
"""
|
2013-08-04 12:59:11 +02:00
|
|
|
|
return render_to_string('projector/overlay_countdown_projector.html')
|
2013-04-15 10:40:47 +02:00
|
|
|
|
|
2013-08-04 12:59:11 +02:00
|
|
|
|
return Overlay(name, get_widget_html, get_projector_html, get_projector_js)
|
2013-04-15 10:40:47 +02:00
|
|
|
|
|
|
|
|
|
|
2013-09-25 10:01:01 +02:00
|
|
|
|
@receiver(projector_overlays, dispatch_uid="projector_overlay_message")
|
|
|
|
|
def projector_overlay_message(sender, **kwargs):
|
2013-04-15 10:40:47 +02:00
|
|
|
|
"""
|
|
|
|
|
Receiver to show the overlay_message on the projector or the form in the
|
|
|
|
|
overlay-widget on the dashboard.
|
|
|
|
|
"""
|
|
|
|
|
name = 'projector_message'
|
|
|
|
|
request = kwargs.get('request', None)
|
|
|
|
|
|
|
|
|
|
def get_widget_html():
|
|
|
|
|
"""
|
|
|
|
|
Returns the the html-code to show in the overly-widget.
|
|
|
|
|
"""
|
|
|
|
|
return render_to_string('projector/overlay_message_widget.html', csrf(request))
|
|
|
|
|
|
|
|
|
|
def get_projector_html():
|
|
|
|
|
"""
|
|
|
|
|
Returns an html-code to show on the projector.
|
|
|
|
|
"""
|
|
|
|
|
if config['projector_message']:
|
|
|
|
|
return render_to_string('projector/overlay_message_projector.html',
|
|
|
|
|
{'message': config['projector_message']})
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
return Overlay(name, get_widget_html, get_projector_html)
|
2013-08-04 12:59:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@receiver(projector_overlays, dispatch_uid="projector_clock")
|
|
|
|
|
def projector_clock(sender, **kwargs):
|
|
|
|
|
"""
|
|
|
|
|
Receiver to show the clock on the projector.
|
|
|
|
|
"""
|
|
|
|
|
name = 'projector_clock'
|
|
|
|
|
|
|
|
|
|
def get_projector_html():
|
|
|
|
|
"""
|
|
|
|
|
Returns the html-code for the clock.
|
|
|
|
|
"""
|
|
|
|
|
return render_to_string('projector/overlay_clock_projector.html')
|
|
|
|
|
|
|
|
|
|
def get_projector_js():
|
|
|
|
|
"""
|
|
|
|
|
Returns JavaScript for the projector
|
|
|
|
|
"""
|
2013-10-26 12:59:39 +02:00
|
|
|
|
return {'load_file': static('javascript/clock.js'),
|
|
|
|
|
'server_time': int(time())}
|
2013-08-04 12:59:11 +02:00
|
|
|
|
|
|
|
|
|
return Overlay(name, None, get_projector_html, get_projector_js,
|
|
|
|
|
allways_active=True)
|