2012-02-03 20:49:16 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-04-25 22:29:19 +02:00
|
|
|
|
2012-05-18 23:07:09 +02:00
|
|
|
from django.contrib import messages
|
2012-02-03 20:49:16 +01:00
|
|
|
from django.core.urlresolvers import reverse
|
2012-11-08 20:08:09 +01:00
|
|
|
from django.shortcuts import redirect
|
2013-04-22 19:59:05 +02:00
|
|
|
from django.utils.translation import ugettext as _
|
2012-02-03 20:49:16 +01:00
|
|
|
|
2013-03-01 17:13:12 +01:00
|
|
|
from openslides.config.api import config
|
2013-11-14 01:16:14 +01:00
|
|
|
from openslides.mediafile.models import Mediafile
|
2013-10-04 11:38:39 +02:00
|
|
|
from openslides.utils.tornado_webserver import ProjectorSocketHandler
|
2013-09-25 10:01:01 +02:00
|
|
|
from openslides.utils.template import Tab
|
|
|
|
from openslides.utils.views import (AjaxMixin, CreateView, DeleteView,
|
|
|
|
RedirectView, TemplateView, UpdateView)
|
2013-11-14 01:16:14 +01:00
|
|
|
from openslides.utils.widgets import Widget
|
2013-09-25 10:01:01 +02:00
|
|
|
|
2013-11-14 01:16:14 +01:00
|
|
|
from .api import (call_on_projector, get_active_slide,
|
2013-10-17 15:32:54 +02:00
|
|
|
get_overlays, get_projector_content, get_projector_overlays,
|
2013-10-18 22:28:38 +02:00
|
|
|
get_projector_overlays_js, reset_countdown, set_active_slide,
|
|
|
|
start_countdown, stop_countdown, update_projector_overlay)
|
2012-11-24 14:01:21 +01:00
|
|
|
from .forms import SelectWidgetsForm
|
2013-04-15 10:40:47 +02:00
|
|
|
from .models import ProjectorSlide
|
2012-03-03 09:11:56 +01:00
|
|
|
|
|
|
|
|
2013-08-04 12:59:11 +02:00
|
|
|
class DashboardView(AjaxMixin, TemplateView):
|
2012-07-07 14:01:40 +02:00
|
|
|
"""
|
2013-11-14 01:16:14 +01:00
|
|
|
Overview over all possible slides, the overlays and a live view.
|
2012-07-07 14:01:40 +02:00
|
|
|
"""
|
2012-08-15 10:58:29 +02:00
|
|
|
template_name = 'projector/dashboard.html'
|
|
|
|
permission_required = 'projector.can_see_dashboard'
|
2012-03-03 09:11:56 +01:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2012-08-15 10:58:29 +02:00
|
|
|
context = super(DashboardView, self).get_context_data(**kwargs)
|
2013-11-14 01:16:14 +01:00
|
|
|
widgets = []
|
|
|
|
for widget in Widget.get_all(self.request):
|
|
|
|
if widget.is_active():
|
|
|
|
widgets.append(widget)
|
|
|
|
context['extra_stylefiles'].extend(widget.get_stylesheets())
|
|
|
|
context['extra_javascript'].extend(widget.get_javascript_files())
|
|
|
|
context['widgets'] = widgets
|
2012-03-03 09:11:56 +01:00
|
|
|
return context
|
|
|
|
|
|
|
|
|
2013-10-29 18:28:05 +01:00
|
|
|
class ProjectorView(TemplateView):
|
2012-07-07 14:01:40 +02:00
|
|
|
"""
|
|
|
|
The Projector-Page.
|
|
|
|
"""
|
2012-07-01 15:35:05 +02:00
|
|
|
permission_required = 'projector.can_see_projector'
|
2013-08-04 12:59:11 +02:00
|
|
|
template_name = 'projector.html'
|
2012-07-01 15:35:05 +02:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2013-08-04 12:59:11 +02:00
|
|
|
callback = self.kwargs.get('callback', None)
|
|
|
|
|
2013-10-29 18:28:05 +01:00
|
|
|
if callback is None:
|
2013-08-04 12:59:11 +02:00
|
|
|
kwargs.update({
|
|
|
|
'content': get_projector_content(),
|
|
|
|
'overlays': get_projector_overlays(),
|
2013-11-06 14:42:14 +01:00
|
|
|
'overlay_js': get_projector_overlays_js(as_json=True),
|
2013-10-17 15:32:54 +02:00
|
|
|
'reload': True,
|
|
|
|
'calls': config['projector_js_cache']})
|
2013-08-04 12:59:11 +02:00
|
|
|
# For the Preview
|
|
|
|
else:
|
2013-10-29 18:28:05 +01:00
|
|
|
slide_dict = dict(self.request.GET.items())
|
|
|
|
slide_dict['callback'] = callback
|
2013-08-04 12:59:11 +02:00
|
|
|
kwargs.update({
|
2013-10-29 18:28:05 +01:00
|
|
|
'content': get_projector_content(slide_dict),
|
2013-08-04 12:59:11 +02:00
|
|
|
'reload': False})
|
2012-07-01 15:35:05 +02:00
|
|
|
|
2013-10-29 18:28:05 +01:00
|
|
|
return super(ProjectorView, self).get_context_data(**kwargs)
|
2012-07-01 15:35:05 +02:00
|
|
|
|
2012-02-03 20:49:16 +01:00
|
|
|
|
2012-07-07 14:01:40 +02:00
|
|
|
class ActivateView(RedirectView):
|
|
|
|
"""
|
|
|
|
Activate a Slide.
|
|
|
|
"""
|
|
|
|
permission_required = 'projector.can_manage_projector'
|
2013-02-02 00:26:08 +01:00
|
|
|
url_name = '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.
|
2013-10-04 11:38:39 +02:00
|
|
|
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:
|
2013-11-22 18:18:06 +01:00
|
|
|
set_active_slide(kwargs['callback'], **dict(request.GET.items()))
|
2013-10-17 15:32:54 +02:00
|
|
|
config['projector_scroll'] = config.get_default('projector_scroll')
|
|
|
|
config['projector_scale'] = config.get_default('projector_scale')
|
2013-11-06 17:39:12 +01:00
|
|
|
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
|
|
|
|
2012-08-15 13:42:25 +02:00
|
|
|
class SelectWidgetsView(TemplateView):
|
|
|
|
"""
|
|
|
|
Show a Form to Select the widgets.
|
|
|
|
"""
|
|
|
|
permission_required = 'projector.can_see_dashboard'
|
|
|
|
template_name = 'projector/select_widgets.html'
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2013-10-31 11:55:55 +01:00
|
|
|
context = super(SelectWidgetsView, self).get_context_data(**kwargs)
|
2013-11-14 01:16:14 +01:00
|
|
|
|
|
|
|
widgets = Widget.get_all(self.request)
|
|
|
|
for widget in widgets:
|
|
|
|
initial = {'widget': widget.is_active()}
|
|
|
|
prefix = widget.name
|
2012-08-15 13:42:25 +02:00
|
|
|
if self.request.method == 'POST':
|
2013-11-14 01:16:14 +01:00
|
|
|
widget.form = SelectWidgetsForm(self.request.POST, prefix=prefix,
|
2012-08-15 13:42:25 +02:00
|
|
|
initial=initial)
|
|
|
|
else:
|
2013-11-14 01:16:14 +01:00
|
|
|
widget.form = SelectWidgetsForm(prefix=prefix, initial=initial)
|
2012-08-15 13:42:25 +02:00
|
|
|
context['widgets'] = widgets
|
|
|
|
return context
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
2013-09-25 10:01:01 +02:00
|
|
|
"""
|
|
|
|
Activates or deactivates the widgets in a post request.
|
|
|
|
"""
|
2012-08-15 13:42:25 +02:00
|
|
|
context = self.get_context_data(**kwargs)
|
2013-11-14 01:16:14 +01:00
|
|
|
session_widgets = self.request.session.get('widgets', {})
|
|
|
|
for widget in context['widgets']:
|
2012-08-15 13:42:25 +02:00
|
|
|
if widget.form.is_valid():
|
2013-11-14 01:16:14 +01:00
|
|
|
session_widgets[widget.name] = widget.form.cleaned_data['widget']
|
2012-08-15 13:42:25 +02:00
|
|
|
else:
|
2013-10-31 11:55:55 +01:00
|
|
|
messages.error(request, _('Errors in the form.'))
|
2012-08-15 13:42:25 +02:00
|
|
|
break
|
|
|
|
else:
|
2013-11-14 01:16:14 +01:00
|
|
|
self.request.session['widgets'] = session_widgets
|
2012-11-08 20:08:09 +01:00
|
|
|
return redirect(reverse('dashboard'))
|
2012-08-15 13:42:25 +02:00
|
|
|
|
|
|
|
|
2013-10-17 15:32:54 +02:00
|
|
|
class ProjectorControllView(RedirectView):
|
2012-07-07 14:01:40 +02:00
|
|
|
"""
|
|
|
|
Scale or scroll the projector.
|
|
|
|
"""
|
2012-07-01 10:52:08 +02:00
|
|
|
permission_required = 'projector.can_manage_projector'
|
2013-02-02 00:26:08 +01:00
|
|
|
url_name = 'dashboard'
|
2012-07-01 10:52:08 +02:00
|
|
|
allow_ajax = True
|
2012-02-03 20:49:16 +01:00
|
|
|
|
2012-07-01 10:52:08 +02:00
|
|
|
def pre_redirect(self, request, *args, **kwargs):
|
|
|
|
direction = kwargs['direction']
|
|
|
|
if direction == 'bigger':
|
2013-10-23 17:08:08 +02:00
|
|
|
config['projector_scale'] = int(config['projector_scale']) + 1
|
2012-07-01 10:52:08 +02:00
|
|
|
elif direction == 'smaller':
|
2013-10-23 17:08:08 +02:00
|
|
|
config['projector_scale'] = int(config['projector_scale']) - 1
|
2012-07-01 10:52:08 +02:00
|
|
|
elif direction == 'down':
|
2013-10-23 17:08:08 +02:00
|
|
|
config['projector_scroll'] = int(config['projector_scroll']) + 1
|
2013-04-15 22:04:59 +02:00
|
|
|
elif direction == 'up':
|
2013-10-23 17:08:08 +02:00
|
|
|
if config['projector_scroll'] > 0:
|
|
|
|
config['projector_scroll'] = int(config['projector_scroll']) - 1
|
|
|
|
elif direction == 'clean_scale':
|
2013-10-17 15:32:54 +02:00
|
|
|
config['projector_scale'] = config.get_default('projector_scale')
|
2013-10-23 17:08:08 +02:00
|
|
|
elif direction == 'clean_scroll':
|
|
|
|
config['projector_scroll'] = config.get_default('projector_scroll')
|
2013-10-17 15:32:54 +02:00
|
|
|
|
|
|
|
call_on_projector({'scroll': config['projector_scroll'],
|
2013-11-06 17:39:12 +01:00
|
|
|
'scale': config['projector_scale']})
|
2012-02-03 20:49:16 +01:00
|
|
|
|
2013-10-23 17:08:08 +02: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
|
|
|
|
2013-10-17 15:32:54 +02:00
|
|
|
class CountdownControllView(RedirectView):
|
2012-07-07 14:01:40 +02:00
|
|
|
"""
|
|
|
|
Start, stop or reset the countdown.
|
|
|
|
"""
|
2012-07-01 10:44:41 +02:00
|
|
|
permission_required = 'projector.can_manage_projector'
|
2013-02-02 00:26:08 +01:00
|
|
|
url_name = 'dashboard'
|
2012-07-01 10:44:41 +02:00
|
|
|
allow_ajax = True
|
|
|
|
|
|
|
|
def pre_redirect(self, request, *args, **kwargs):
|
2012-07-01 10:52:08 +02:00
|
|
|
command = kwargs['command']
|
2012-04-25 17:17:24 +02:00
|
|
|
if command == 'reset':
|
2013-10-07 08:52:18 +02:00
|
|
|
reset_countdown()
|
2012-07-01 10:44:41 +02:00
|
|
|
elif command == 'start':
|
2013-10-07 08:52:18 +02:00
|
|
|
start_countdown()
|
2012-07-01 10:44:41 +02:00
|
|
|
elif command == 'stop':
|
2013-10-07 08:52:18 +02:00
|
|
|
stop_countdown()
|
2012-07-01 10:44:41 +02:00
|
|
|
elif command == 'set-default':
|
|
|
|
try:
|
2012-07-07 14:01:40 +02:00
|
|
|
config['countdown_time'] = \
|
|
|
|
int(self.request.GET['countdown_time'])
|
2013-11-22 18:18:06 +01:00
|
|
|
except (ValueError, AttributeError):
|
2012-07-01 10:44:41 +02:00
|
|
|
pass
|
2013-11-22 18:18:06 +01:00
|
|
|
else:
|
|
|
|
reset_countdown()
|
2013-08-04 12:59:11 +02:00
|
|
|
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
|
|
|
|
"""
|
2013-02-02 00:26:08 +01:00
|
|
|
url_name = 'dashboard'
|
2012-08-15 18:00:22 +02:00
|
|
|
allow_ajax = True
|
|
|
|
permission_required = 'projector.can_manage_projector'
|
|
|
|
|
|
|
|
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'] = ''
|
2013-08-04 12:59:11 +02:00
|
|
|
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.
|
|
|
|
"""
|
2013-02-02 00:26:08 +01:00
|
|
|
url_name = 'dashboard'
|
2012-07-07 14:01:40 +02:00
|
|
|
allow_ajax = True
|
|
|
|
permission_required = 'projector.can_manage_projector'
|
|
|
|
|
|
|
|
def pre_redirect(self, request, *args, **kwargs):
|
2013-08-04 12:59:11 +02:00
|
|
|
overlay = get_overlays()[kwargs['name']]
|
|
|
|
self.name = overlay.name
|
2012-07-07 14:01:40 +02:00
|
|
|
if kwargs['activate']:
|
2013-08-04 12:59:11 +02:00
|
|
|
if not overlay.is_active():
|
|
|
|
overlay.set_active(True)
|
|
|
|
update_projector_overlay(overlay)
|
2013-04-15 10:40:47 +02:00
|
|
|
self.active = True
|
2013-08-04 12:59:11 +02:00
|
|
|
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}
|
2012-07-07 14:01:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CustomSlideCreateView(CreateView):
|
|
|
|
"""
|
|
|
|
Create a custom slide.
|
|
|
|
"""
|
|
|
|
permission_required = 'agenda.can_manage_agenda'
|
|
|
|
template_name = 'projector/new.html'
|
|
|
|
model = ProjectorSlide
|
|
|
|
context_object_name = 'customslide'
|
2013-02-03 19:43:36 +01:00
|
|
|
success_url_name = 'dashboard'
|
2013-10-21 19:03:07 +02:00
|
|
|
url_name_args = []
|
2012-07-07 14:01:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CustomSlideUpdateView(UpdateView):
|
|
|
|
"""
|
|
|
|
Update a custom slide.
|
|
|
|
"""
|
|
|
|
permission_required = 'projector.can_manage_projector'
|
|
|
|
template_name = 'projector/new.html'
|
|
|
|
model = ProjectorSlide
|
|
|
|
context_object_name = 'customslide'
|
2013-02-03 19:43:36 +01:00
|
|
|
success_url_name = 'dashboard'
|
2013-10-21 19:03:07 +02:00
|
|
|
url_name_args = []
|
2012-07-07 14:01:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CustomSlideDeleteView(DeleteView):
|
|
|
|
"""
|
|
|
|
Delete a custom slide.
|
|
|
|
"""
|
|
|
|
permission_required = 'projector.can_manage_projector'
|
|
|
|
model = ProjectorSlide
|
2013-02-03 19:43:36 +01:00
|
|
|
success_url_name = 'dashboard'
|
2012-07-07 14:01:40 +02:00
|
|
|
|
|
|
|
|
2012-03-18 17:11:58 +01:00
|
|
|
def register_tab(request):
|
2012-07-07 14:01:40 +02:00
|
|
|
"""
|
|
|
|
Register the projector tab.
|
|
|
|
"""
|
2012-11-24 14:01:21 +01:00
|
|
|
selected = request.path.startswith('/projector/')
|
2012-03-18 17:11:58 +01:00
|
|
|
return Tab(
|
2012-08-15 10:58:29 +02:00
|
|
|
title=_('Dashboard'),
|
2012-09-05 00:20:28 +02:00
|
|
|
app='dashboard',
|
2012-08-15 10:58:29 +02:00
|
|
|
url=reverse('dashboard'),
|
2012-11-24 14:01:21 +01:00
|
|
|
permission=request.user.has_perm('projector.can_see_dashboard'),
|
2012-03-18 17:11:58 +01:00
|
|
|
selected=selected,
|
|
|
|
)
|