OpenSlides/openslides/projector/views.py

181 lines
6.3 KiB
Python
Raw Normal View History

2012-02-03 20:49:16 +01:00
# -*- coding: utf-8 -*-
2012-04-25 22:29:19 +02:00
from openslides.config.api import config
from openslides.mediafile.models import Mediafile
from openslides.utils.tornado_webserver import ProjectorSocketHandler
from openslides.utils.views import RedirectView, TemplateView
from .api import (call_on_projector, get_active_slide,
2014-04-10 14:23:08 +02:00
get_overlays, get_projector_content,
get_projector_overlays_js, reset_countdown, set_active_slide,
start_countdown, stop_countdown, update_projector_overlay)
2012-03-03 09:11:56 +01:00
2013-10-29 18:28:05 +01:00
class ProjectorView(TemplateView):
2012-07-07 14:01:40 +02:00
"""
The Projector-Page.
"""
permission_required = 'core.can_see_projector'
template_name = 'projector.html'
def get_context_data(self, **kwargs):
callback = self.kwargs.get('callback', None)
2013-10-29 18:28:05 +01:00
if callback is None:
kwargs.update({
'content': get_projector_content(),
2014-04-10 14:23:08 +02:00
'overlays': get_overlays(only_active=True),
2013-11-06 14:42:14 +01:00
'overlay_js': get_projector_overlays_js(as_json=True),
'reload': True,
'calls': config['projector_js_cache']})
# For the Preview
else:
2013-10-29 18:28:05 +01:00
slide_dict = dict(self.request.GET.items())
slide_dict['callback'] = callback
kwargs.update({
2013-10-29 18:28:05 +01:00
'content': get_projector_content(slide_dict),
'reload': False})
2013-10-29 18:28:05 +01:00
return super(ProjectorView, self).get_context_data(**kwargs)
2012-02-03 20:49:16 +01:00
2012-07-07 14:01:40 +02:00
class ActivateView(RedirectView):
"""
Activate a Slide.
"""
permission_required = 'core.can_manage_projector'
url_name = 'core_dashboard'
2012-07-07 14:01:40 +02:00
allow_ajax = True
def pre_redirect(self, request, *args, **kwargs):
2013-10-29 18:28:05 +01:00
if (kwargs['callback'] == 'mediafile' and
get_active_slide()['callback'] == 'mediafile'):
# If the current slide is a pdf and the new page is also a slide,
# we dont have to use set_active_slide, because is causes a content
# reload.
kwargs.update({'page_num': 1, 'pk': request.GET.get('pk')})
url = Mediafile.objects.get(pk=kwargs['pk'], is_presentable=True).mediafile.url
config['projector_active_slide'] = kwargs
ProjectorSocketHandler.send_updates(
{'calls': {'load_pdf': {'url': url, 'page_num': kwargs['page_num']}}})
else:
set_active_slide(kwargs['callback'], **dict(request.GET.items()))
config['projector_scroll'] = config.get_default('projector_scroll')
config['projector_scale'] = config.get_default('projector_scale')
call_on_projector({'scroll': config['projector_scroll'],
'scale': config['projector_scale']})
2012-07-07 14:01:40 +02:00
2012-02-03 20:49:16 +01:00
class ProjectorControllView(RedirectView):
2012-07-07 14:01:40 +02:00
"""
Scale or scroll the projector.
"""
permission_required = 'core.can_manage_projector'
url_name = 'core_dashboard'
allow_ajax = True
2012-02-03 20:49:16 +01:00
def pre_redirect(self, request, *args, **kwargs):
direction = kwargs['direction']
if direction == 'bigger':
config['projector_scale'] = int(config['projector_scale']) + 1
elif direction == 'smaller':
config['projector_scale'] = int(config['projector_scale']) - 1
elif direction == 'down':
config['projector_scroll'] = int(config['projector_scroll']) + 1
elif direction == 'up':
if config['projector_scroll'] > 0:
config['projector_scroll'] = int(config['projector_scroll']) - 1
elif direction == 'clean_scale':
config['projector_scale'] = config.get_default('projector_scale')
elif direction == 'clean_scroll':
config['projector_scroll'] = config.get_default('projector_scroll')
call_on_projector({'scroll': config['projector_scroll'],
'scale': config['projector_scale']})
2012-02-03 20:49:16 +01:00
def get_ajax_context(self, **kwargs):
return {
'scale_level': config['projector_scale'],
'scroll_level': config['projector_scroll'],
}
2012-02-03 20:49:16 +01:00
class CountdownControllView(RedirectView):
2012-07-07 14:01:40 +02:00
"""
Start, stop or reset the countdown.
"""
permission_required = 'core.can_manage_projector'
url_name = 'core_dashboard'
allow_ajax = True
def pre_redirect(self, request, *args, **kwargs):
command = kwargs['command']
if command == 'reset':
reset_countdown()
elif command == 'start':
start_countdown()
elif command == 'stop':
stop_countdown()
elif command == 'set-default':
try:
2012-07-07 14:01:40 +02:00
config['countdown_time'] = \
int(self.request.GET['countdown_time'])
except (ValueError, AttributeError):
pass
else:
reset_countdown()
update_projector_overlay('projector_countdown')
2012-03-18 17:11:58 +01:00
2012-07-04 02:43:26 +02:00
def get_ajax_context(self, **kwargs):
return {
'state': config['countdown_state'],
'countdown_time': config['countdown_time'],
}
2012-03-18 17:11:58 +01:00
2012-08-15 18:00:22 +02:00
class OverlayMessageView(RedirectView):
"""
Sets or clears the overlay message
"""
url_name = 'core_dashboard'
2012-08-15 18:00:22 +02:00
allow_ajax = True
permission_required = 'core.can_manage_projector'
2012-08-15 18:00:22 +02:00
def pre_post_redirect(self, request, *args, **kwargs):
if 'message' in request.POST:
2013-04-15 10:40:47 +02:00
config['projector_message'] = request.POST['message_text']
2012-08-15 18:00:22 +02:00
elif 'message-clean' in request.POST:
2013-04-15 10:40:47 +02:00
config['projector_message'] = ''
update_projector_overlay('projector_message')
2012-08-15 18:00:22 +02:00
def get_ajax_context(self, **kwargs):
return {
'overlay_message': config['projector_message'],
}
2012-07-07 14:01:40 +02:00
class ActivateOverlay(RedirectView):
"""
Activate or deactivate an overlay.
"""
url_name = 'core_dashboard'
2012-07-07 14:01:40 +02:00
allow_ajax = True
permission_required = 'core.can_manage_projector'
2012-07-07 14:01:40 +02:00
def pre_redirect(self, request, *args, **kwargs):
overlay = get_overlays()[kwargs['name']]
self.name = overlay.name
2012-07-07 14:01:40 +02:00
if kwargs['activate']:
if not overlay.is_active():
overlay.set_active(True)
update_projector_overlay(overlay)
2013-04-15 10:40:47 +02:00
self.active = True
else:
if overlay.is_active():
overlay.set_active(False)
update_projector_overlay(overlay)
2013-04-15 10:40:47 +02:00
self.active = False
2012-07-07 14:01:40 +02:00
def get_ajax_context(self, **kwargs):
2013-04-15 10:40:47 +02:00
return {'active': self.active, 'name': self.name}