From 0de82285379d01c83d9d6a7e918f46f0b7476bea Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 14 Apr 2012 09:47:34 +0200 Subject: [PATCH] rewrote message api and countdown --- openslides/projector/models.py | 9 ++++ openslides/projector/projector.py | 15 ++++--- openslides/projector/signals.py | 2 +- .../projector/templates/base-projector.html | 2 +- .../templates/projector/base_projector.html | 13 ++++-- .../templates/projector/messages.html | 24 +++++++++++ openslides/projector/urls.py | 7 ++- openslides/projector/views.py | 43 +++++++++++++++++-- openslides/system/models.py | 6 ++- 9 files changed, 104 insertions(+), 17 deletions(-) create mode 100644 openslides/projector/templates/projector/messages.html diff --git a/openslides/projector/models.py b/openslides/projector/models.py index 14cccf501..30e50bcaf 100644 --- a/openslides/projector/models.py +++ b/openslides/projector/models.py @@ -23,5 +23,14 @@ class ProjectorSlide(models.Model, SlideMixin): ('can_see_projector', "Can see projector"), ) + +class ProjectorMessage(models.Model): + active = models.BooleanField(verbose_name=_('Active')) + def_name = models.CharField(max_length=64) + + def __unicode__(self): + return self.def_name + + register_slidemodel(ProjectorSlide, category=_('Projector'), model_name=_('Projector Slide')) diff --git a/openslides/projector/projector.py b/openslides/projector/projector.py index a009c894d..2d7d9b3b8 100644 --- a/openslides/projector/projector.py +++ b/openslides/projector/projector.py @@ -1,6 +1,7 @@ -from datetime import datetime +from time import time from django.dispatch import receiver +from django.utils.translation import ugettext as _ from system import config @@ -69,11 +70,11 @@ class Slide(object): @receiver(projector_messages, dispatch_uid="projector_countdown") def countdown(sender, **kwargs): - if config['countdown_visible']: + name = _('Projector Countdown') + if kwargs['register']: + return name + if name in kwargs['call']: starttime = config['countdown_start'] - if type(starttime) != type(datetime.now()): - config['countdown_start'] = datetime.now() - starttime = config['countdown_start'] - #todo: return the time passt sinth starttime - return datetime.now() - starttime + seconds = max(0, int(starttime + config['agenda_countdown_time'] - time())) + return (name, seconds) return None diff --git a/openslides/projector/signals.py b/openslides/projector/signals.py index 5dbd32ef8..1bd2cd60b 100644 --- a/openslides/projector/signals.py +++ b/openslides/projector/signals.py @@ -12,4 +12,4 @@ from django.dispatch import Signal -projector_messages = Signal() +projector_messages = Signal(providing_args=['register', 'call']) diff --git a/openslides/projector/templates/base-projector.html b/openslides/projector/templates/base-projector.html index f2d909b9e..d263bc119 100644 --- a/openslides/projector/templates/base-projector.html +++ b/openslides/projector/templates/base-projector.html @@ -32,7 +32,7 @@
diff --git a/openslides/projector/templates/projector/base_projector.html b/openslides/projector/templates/projector/base_projector.html index b8169ef54..0cc9ff028 100644 --- a/openslides/projector/templates/projector/base_projector.html +++ b/openslides/projector/templates/projector/base_projector.html @@ -12,12 +12,19 @@ {% endblock %} diff --git a/openslides/projector/templates/projector/messages.html b/openslides/projector/templates/projector/messages.html new file mode 100644 index 000000000..bb02e0102 --- /dev/null +++ b/openslides/projector/templates/projector/messages.html @@ -0,0 +1,24 @@ +{% extends "projector/base_projector.html" %} + +{% load tags %} +{% load i18n %} + +{% block content %} +

{% trans 'Messages' %}

+
{% csrf_token %} + + + + +
+{% endblock %} diff --git a/openslides/projector/urls.py b/openslides/projector/urls.py index 0138ede2a..d08962745 100644 --- a/openslides/projector/urls.py +++ b/openslides/projector/urls.py @@ -14,7 +14,7 @@ from django.conf.urls.defaults import * from utils.views import CreateView -from views import ControlView, ActivateView +from views import ControlView, ActivateView, MessagesView from agenda.views import ItemUpdate from models import ProjectorSlide @@ -54,6 +54,11 @@ urlpatterns = patterns('projector.views', name='projector_new', ), + url(r'^messages/$', + MessagesView.as_view(), + name='projector_messages', + ), + url(r'^bigger/$', 'projector_edit', {'direction': 'bigger'}, name='projector_bigger'), diff --git a/openslides/projector/views.py b/openslides/projector/views.py index 065bc9a8e..e9bdd48d2 100644 --- a/openslides/projector/views.py +++ b/openslides/projector/views.py @@ -10,6 +10,7 @@ :license: GNU GPL, see LICENSE for more details. """ from datetime import datetime +from time import time from django.shortcuts import render_to_response, redirect from django.template import RequestContext @@ -28,6 +29,7 @@ from system import config from api import get_active_slide, set_active_slide from projector import SLIDE +from models import ProjectorMessage from openslides.projector.signals import projector_messages @@ -80,7 +82,8 @@ def active_slide(request): data['ajax'] = 'on' data['messages'] = [] - for receiver, response in projector_messages.send(sender='active_slide'): + 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): if response is not None: data['messages'].append(response) @@ -89,6 +92,7 @@ def active_slide(request): content = render_block_to_string(data['template'], 'content', data) jsondata = { 'content': content, + 'messages': data['messages'], 'title': data['title'], 'time': datetime.now().strftime('%H:%M'), 'bigger': config['bigger'], @@ -106,6 +110,39 @@ def active_slide(request): ) +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 + + @permission_required('agenda.can_manage_agenda') def projector_edit(request, direction): if direction == 'bigger': @@ -126,14 +163,14 @@ def projector_edit(request, direction): @permission_required('projector.can_manage_projector') -def projector_countdown(request, command, time=60): +def projector_countdown(request, command): #todo: why is there the time argument? if command == 'show': config['countdown_visible'] = True elif command == 'hide': config['countdown_visible'] = False elif command == 'reset': - config['countdown_start'] = datetime.now() + config['countdown_start'] = time() elif command == 'start': config['countdown_run'] = True elif command == 'stop': diff --git a/openslides/system/models.py b/openslides/system/models.py index d72d7559b..f9ccd34e1 100644 --- a/openslides/system/models.py +++ b/openslides/system/models.py @@ -73,7 +73,11 @@ class Config(object): c = ConfigStore(pk=key) c.value = base64.encodestring(dumps(value)) c.save() - self.config[key] = value + try: + self.config[key] = value + except AttributeError: + self.load_config() + self.config[key] = value from django.dispatch import receiver from django.core.urlresolvers import reverse