2012-04-25 22:29:19 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
openslides.projector.projector
|
2012-07-07 14:01:40 +02:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
2012-04-25 22:29:19 +02:00
|
|
|
|
|
|
|
Slide functions for the projector app.
|
|
|
|
|
|
|
|
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
|
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
|
2012-04-14 09:47:34 +02:00
|
|
|
from time import time
|
2012-03-16 12:28:42 +01:00
|
|
|
|
|
|
|
from django.dispatch import receiver
|
2012-06-11 13:43:48 +02:00
|
|
|
from django.template.loader import render_to_string
|
2012-03-16 12:28:42 +01:00
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
from openslides.config.api import config
|
2013-06-13 23:38:58 +02:00
|
|
|
from django.template import RequestContext
|
|
|
|
from openslides.utils.exceptions import OpenSlidesError
|
2012-03-16 12:28:42 +01:00
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
|
2012-06-11 13:43:48 +02:00
|
|
|
class Widget(object):
|
2012-07-07 14:01:40 +02:00
|
|
|
"""
|
|
|
|
Class for a Widget for the Projector-Tab.
|
|
|
|
"""
|
2013-06-13 23:38:58 +02:00
|
|
|
def __init__(self, request, name, html=None, template=None, context={},
|
2013-09-07 15:09:37 +02:00
|
|
|
permission_required=None, display_name=None, default_column=1,
|
|
|
|
default_weight=0):
|
2012-06-11 13:43:48 +02:00
|
|
|
self.name = name
|
2012-08-15 11:56:43 +02:00
|
|
|
if display_name is None:
|
|
|
|
self.display_name = name.capitalize()
|
|
|
|
else:
|
|
|
|
self.display_name = display_name
|
|
|
|
|
2012-06-11 13:43:48 +02:00
|
|
|
if html is not None:
|
|
|
|
self.html = html
|
|
|
|
elif template is not None:
|
2013-06-13 23:38:58 +02:00
|
|
|
self.html = render_to_string(
|
|
|
|
template_name=template,
|
|
|
|
dictionary=context,
|
|
|
|
context_instance=RequestContext(request))
|
|
|
|
else:
|
|
|
|
raise OpenSlidesError('A Widget must have either a html or a template argument.')
|
2012-08-15 10:58:29 +02:00
|
|
|
self.permission_required = permission_required
|
2012-08-15 11:56:43 +02:00
|
|
|
self.default_column = default_column
|
2013-09-07 15:09:37 +02:00
|
|
|
self.default_weight = default_weight
|
2012-06-11 13:43:48 +02:00
|
|
|
|
|
|
|
def get_name(self):
|
2012-06-24 21:55:46 +02:00
|
|
|
return self.name.lower()
|
2012-06-11 13:43:48 +02:00
|
|
|
|
|
|
|
def get_html(self):
|
|
|
|
return self.html
|
|
|
|
|
|
|
|
def get_title(self):
|
2012-08-15 11:56:43 +02:00
|
|
|
return self.display_name
|
|
|
|
|
|
|
|
def __repr__(self):
|
2013-09-07 15:19:03 +02:00
|
|
|
return repr(self.display_name)
|
2012-06-11 13:43:48 +02:00
|
|
|
|
2012-11-07 21:12:52 +01:00
|
|
|
def __unicode__(self):
|
|
|
|
return unicode(self.display_name)
|
|
|
|
|
2012-06-11 13:43:48 +02:00
|
|
|
|
2013-04-15 10:40:47 +02:00
|
|
|
class Overlay(object):
|
|
|
|
"""
|
|
|
|
Represents an overlay which can be seen on the projector.
|
|
|
|
"""
|
2012-04-25 17:17:24 +02:00
|
|
|
|
2013-08-04 12:59:11 +02:00
|
|
|
def __init__(self, name, get_widget_html, get_projector_html,
|
|
|
|
get_javascript=None, allways_active=False):
|
2013-04-15 10:40:47 +02:00
|
|
|
self.name = name
|
|
|
|
self.widget_html_callback = get_widget_html
|
|
|
|
self.projector_html_callback = get_projector_html
|
2013-08-04 12:59:11 +02:00
|
|
|
self.javascript_callback = get_javascript
|
|
|
|
self.allways_active = allways_active
|
2012-04-25 17:17:24 +02:00
|
|
|
|
2013-04-15 10:40:47 +02:00
|
|
|
def get_widget_html(self):
|
2013-08-04 12:59:11 +02:00
|
|
|
value = None
|
|
|
|
if self.widget_html_callback is not None:
|
|
|
|
value = self.widget_html_callback()
|
|
|
|
return value
|
2012-04-16 16:35:30 +02:00
|
|
|
|
2013-04-15 10:40:47 +02:00
|
|
|
def get_projector_html(self):
|
2013-08-04 12:59:11 +02:00
|
|
|
return self.get_html_wrapper(self.projector_html_callback())
|
|
|
|
|
|
|
|
def get_javascript(self):
|
|
|
|
if self.javascript_callback is None:
|
|
|
|
value = {}
|
|
|
|
else:
|
|
|
|
value = self.javascript_callback()
|
|
|
|
return value
|
|
|
|
|
|
|
|
def get_html_wrapper(self, inner_html):
|
|
|
|
full_html = ''
|
|
|
|
if inner_html is not None:
|
|
|
|
full_html = '<div id="overlay_%s">%s</div>' % (self.name, inner_html)
|
|
|
|
return full_html
|
2012-04-16 16:35:30 +02:00
|
|
|
|
2013-04-15 10:40:47 +02:00
|
|
|
def is_active(self):
|
2013-08-04 12:59:11 +02:00
|
|
|
return self.allways_active or self.name in config['projector_active_overlays']
|
|
|
|
|
|
|
|
def set_active(self, active):
|
|
|
|
"""
|
|
|
|
Publish or depublish the ovleray on the projector.
|
|
|
|
|
|
|
|
publish, if active is true,
|
|
|
|
depublish, if active is false.
|
|
|
|
"""
|
|
|
|
active_overlays = set(config['projector_active_overlays'])
|
|
|
|
if active:
|
|
|
|
active_overlays.add(self.name)
|
|
|
|
else:
|
|
|
|
active_overlays.discard(self.name)
|
|
|
|
config['projector_active_overlays'] = list(active_overlays)
|
2013-04-15 15:47:18 +02:00
|
|
|
|
|
|
|
def show_on_projector(self):
|
2013-03-18 12:34:47 +01:00
|
|
|
return self.is_active() and self.get_projector_html() is not None
|