2012-02-03 20:49:16 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2012-02-06 22:08:08 +01:00
|
|
|
openslides.projector.views
|
2012-02-03 20:49:16 +01:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2012-02-06 22:08:08 +01:00
|
|
|
Views for the projector app.
|
2012-02-03 20:49:16 +01:00
|
|
|
|
|
|
|
:copyright: 2011 by the OpenSlides team, see AUTHORS.
|
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
from datetime import datetime
|
2012-04-14 09:47:34 +02:00
|
|
|
from time import time
|
2012-02-03 20:49:16 +01:00
|
|
|
|
|
|
|
from django.shortcuts import render_to_response, redirect
|
|
|
|
from django.template import RequestContext
|
|
|
|
from django.core.urlresolvers import reverse
|
|
|
|
from django.contrib import messages
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
|
|
|
|
2012-03-03 09:11:56 +01:00
|
|
|
from utils.views import TemplateView, RedirectView
|
2012-02-03 20:49:16 +01:00
|
|
|
from utils.utils import template, permission_required, \
|
|
|
|
del_confirm_form, ajax_request
|
|
|
|
from utils.template import render_block_to_string
|
2012-03-18 17:11:58 +01:00
|
|
|
from utils.template import Tab
|
2012-02-03 20:49:16 +01:00
|
|
|
|
2012-02-15 12:04:11 +01:00
|
|
|
from system import config
|
2012-02-03 20:49:16 +01:00
|
|
|
|
2012-03-12 18:22:18 +01:00
|
|
|
from api import get_active_slide, set_active_slide
|
|
|
|
from projector import SLIDE
|
2012-04-14 09:47:34 +02:00
|
|
|
from models import ProjectorMessage
|
2012-03-16 12:28:42 +01:00
|
|
|
from openslides.projector.signals import projector_messages
|
2012-03-03 09:11:56 +01:00
|
|
|
|
|
|
|
|
2012-03-06 19:55:19 +01:00
|
|
|
class ControlView(TemplateView):
|
2012-03-06 08:19:49 +01:00
|
|
|
template_name = 'projector/control.html'
|
2012-03-18 14:35:01 +01:00
|
|
|
permission_required = 'projector.can_manage_projector'
|
2012-03-03 09:11:56 +01:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2012-03-06 19:55:19 +01:00
|
|
|
context = super(ControlView, self).get_context_data(**kwargs)
|
2012-03-03 10:47:32 +01:00
|
|
|
categories = {}
|
|
|
|
for slide in SLIDE.values():
|
|
|
|
if not categories.has_key(slide.category):
|
|
|
|
categories[slide.category] = []
|
|
|
|
categories[slide.category].append(slide)
|
2012-03-03 09:11:56 +01:00
|
|
|
context.update({
|
2012-03-03 10:47:32 +01:00
|
|
|
'categories': categories,
|
2012-03-06 08:19:49 +01:00
|
|
|
'countdown_visible': config['countdown_visible'],
|
|
|
|
'countdown_time': config['agenda_countdown_time'],
|
2012-03-03 09:11:56 +01:00
|
|
|
})
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
|
|
|
class ActivateView(RedirectView):
|
2012-03-06 08:19:49 +01:00
|
|
|
url = 'projector_control'
|
2012-03-03 09:11:56 +01:00
|
|
|
allow_ajax = True
|
|
|
|
|
|
|
|
def pre_redirect(self, request, *args, **kwargs):
|
|
|
|
set_active_slide(kwargs['sid'])
|
|
|
|
|
|
|
|
def get_ajax_context(self, **kwargs):
|
|
|
|
context = super(ActivateView, self).get_ajax_context()
|
|
|
|
return context
|
2012-02-03 20:57:08 +01:00
|
|
|
|
2012-02-03 20:49:16 +01:00
|
|
|
|
2012-03-12 18:22:18 +01:00
|
|
|
@permission_required('projector.can_see_projector')
|
2012-02-06 22:08:08 +01:00
|
|
|
def active_slide(request):
|
2012-02-03 20:49:16 +01:00
|
|
|
"""
|
2012-02-03 20:57:08 +01:00
|
|
|
Shows the active Slide.
|
2012-02-03 20:49:16 +01:00
|
|
|
"""
|
|
|
|
try:
|
2012-02-09 01:46:58 +01:00
|
|
|
data = get_active_slide()
|
|
|
|
except AttributeError: #TODO: It has to be an Slide.DoesNotExist
|
2012-03-03 09:11:56 +01:00
|
|
|
data = None
|
|
|
|
|
|
|
|
if data is None:
|
2012-02-09 01:46:58 +01:00
|
|
|
data = {
|
2012-02-15 12:04:11 +01:00
|
|
|
'title': config['event_name'],
|
2012-02-09 01:46:58 +01:00
|
|
|
'template': 'projector/default.html',
|
|
|
|
}
|
2012-02-03 23:12:28 +01:00
|
|
|
|
|
|
|
data['ajax'] = 'on'
|
2012-03-16 12:28:42 +01:00
|
|
|
data['messages'] = []
|
2012-04-14 09:47:34 +02:00
|
|
|
active_defs = ProjectorMessage.objects.filter(active=True).values_list('def_name', flat=True)
|
|
|
|
for receiver, response in projector_messages.send(sender='active_slide', register=False, call=active_defs):
|
2012-03-16 12:28:42 +01:00
|
|
|
if response is not None:
|
|
|
|
data['messages'].append(response)
|
|
|
|
|
2012-02-03 23:12:28 +01:00
|
|
|
|
2012-02-03 20:49:16 +01:00
|
|
|
if request.is_ajax():
|
2012-02-03 23:12:28 +01:00
|
|
|
content = render_block_to_string(data['template'], 'content', data)
|
|
|
|
jsondata = {
|
|
|
|
'content': content,
|
2012-04-14 09:47:34 +02:00
|
|
|
'messages': data['messages'],
|
2012-02-03 23:12:28 +01:00
|
|
|
'title': data['title'],
|
|
|
|
'time': datetime.now().strftime('%H:%M'),
|
2012-02-15 12:04:11 +01:00
|
|
|
'bigger': config['bigger'],
|
|
|
|
'up': config['up'],
|
|
|
|
'countdown_visible': config['countdown_visible'],
|
|
|
|
'countdown_time': config['agenda_countdown_time'],
|
|
|
|
'countdown_control': config['countdown_control'],
|
2012-02-03 23:12:28 +01:00
|
|
|
}
|
2012-02-03 20:49:16 +01:00
|
|
|
return ajax_request(jsondata)
|
|
|
|
else:
|
2012-02-03 23:12:28 +01:00
|
|
|
return render_to_response(
|
|
|
|
data['template'],
|
|
|
|
data,
|
|
|
|
context_instance=RequestContext(request)
|
|
|
|
)
|
2012-02-03 20:49:16 +01:00
|
|
|
|
|
|
|
|
2012-04-14 09:47:34 +02:00
|
|
|
class MessagesView(TemplateView):
|
|
|
|
permission_required = 'projector.can_manage_projector'
|
|
|
|
template_name = 'projector/messages.html'
|
|
|
|
|
|
|
|
def get_projector_messages(self):
|
|
|
|
messages = []
|
|
|
|
for receiver, name in projector_messages.send(sender='registerer', register=True):
|
|
|
|
if name is not None:
|
|
|
|
try:
|
|
|
|
projector_message = ProjectorMessage.objects.get(def_name=name)
|
|
|
|
except ProjectorMessage.DoesNotExist:
|
|
|
|
projector_message = ProjectorMessage(def_name=name, active=False)
|
|
|
|
projector_message.save()
|
|
|
|
messages.append(projector_message)
|
|
|
|
return messages
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
|
for message in self.get_projector_messages():
|
|
|
|
if message.def_name in request.POST:
|
|
|
|
message.active = True
|
|
|
|
else:
|
|
|
|
message.active = False
|
|
|
|
message.save()
|
|
|
|
|
|
|
|
return self.get(request, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(MessagesView, self).get_context_data(**kwargs)
|
|
|
|
context['projector_messages'] = self.get_projector_messages()
|
|
|
|
return context
|
|
|
|
|
|
|
|
|
2012-02-03 20:49:16 +01:00
|
|
|
@permission_required('agenda.can_manage_agenda')
|
2012-02-06 22:08:08 +01:00
|
|
|
def projector_edit(request, direction):
|
2012-02-03 20:49:16 +01:00
|
|
|
if direction == 'bigger':
|
2012-02-15 12:04:11 +01:00
|
|
|
config['bigger'] = int(config['bigger']) + 10
|
2012-02-03 20:49:16 +01:00
|
|
|
elif direction == 'smaller':
|
2012-02-15 12:04:11 +01:00
|
|
|
config['bigger'] = int(config['bigger']) - 10
|
2012-02-03 20:49:16 +01:00
|
|
|
elif direction == 'up':
|
2012-02-15 12:04:11 +01:00
|
|
|
config['up'] = int(config['up']) - 10
|
2012-02-03 20:49:16 +01:00
|
|
|
elif direction == 'down':
|
2012-02-15 12:04:11 +01:00
|
|
|
config['up'] = int(config['up']) + 10
|
2012-02-03 20:49:16 +01:00
|
|
|
elif direction == 'clean':
|
2012-02-15 12:04:11 +01:00
|
|
|
config['up'] = 0
|
|
|
|
config['bigger'] = 100
|
2012-02-03 20:49:16 +01:00
|
|
|
|
|
|
|
if request.is_ajax():
|
|
|
|
return ajax_request({})
|
2012-03-06 08:19:49 +01:00
|
|
|
return redirect(reverse('projector_control'))
|
2012-02-03 20:49:16 +01:00
|
|
|
|
|
|
|
|
2012-03-16 12:28:42 +01:00
|
|
|
@permission_required('projector.can_manage_projector')
|
2012-04-14 09:47:34 +02:00
|
|
|
def projector_countdown(request, command):
|
2012-03-16 12:28:42 +01:00
|
|
|
#todo: why is there the time argument?
|
2012-02-03 20:49:16 +01:00
|
|
|
if command == 'show':
|
2012-02-15 12:04:11 +01:00
|
|
|
config['countdown_visible'] = True
|
2012-02-03 20:49:16 +01:00
|
|
|
elif command == 'hide':
|
2012-02-15 12:04:11 +01:00
|
|
|
config['countdown_visible'] = False
|
2012-02-03 20:49:16 +01:00
|
|
|
elif command == 'reset':
|
2012-04-14 09:47:34 +02:00
|
|
|
config['countdown_start'] = time()
|
2012-02-03 20:49:16 +01:00
|
|
|
elif command == 'start':
|
2012-03-16 12:28:42 +01:00
|
|
|
config['countdown_run'] = True
|
2012-02-03 20:49:16 +01:00
|
|
|
elif command == 'stop':
|
2012-03-16 12:28:42 +01:00
|
|
|
config['countdown_run'] = False
|
2012-02-03 20:49:16 +01:00
|
|
|
|
|
|
|
if request.is_ajax():
|
|
|
|
if command == "show":
|
|
|
|
link = reverse('countdown_close')
|
|
|
|
else:
|
|
|
|
link = reverse('countdown_open')
|
2012-02-15 12:04:11 +01:00
|
|
|
return ajax_request({'countdown_visible': config['countdown_visible'],
|
2012-02-03 20:49:16 +01:00
|
|
|
'link': link})
|
2012-03-06 08:19:49 +01:00
|
|
|
return redirect(reverse('projector_control'))
|
2012-03-18 17:11:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
def register_tab(request):
|
|
|
|
selected = True if request.path.startswith('/projector/') else False
|
|
|
|
return Tab(
|
|
|
|
title=_('Projector'),
|
|
|
|
url=reverse('projector_control'),
|
|
|
|
permission=request.user.has_perm('projector.can_manag_projector'),
|
|
|
|
selected=selected,
|
|
|
|
)
|
|
|
|
|