rewrote message api and countdown
This commit is contained in:
parent
d870b988e9
commit
0de8228537
@ -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'))
|
||||
|
||||
|
@ -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
|
||||
|
@ -12,4 +12,4 @@
|
||||
|
||||
from django.dispatch import Signal
|
||||
|
||||
projector_messages = Signal()
|
||||
projector_messages = Signal(providing_args=['register', 'call'])
|
||||
|
@ -32,7 +32,7 @@
|
||||
<div id="messages">
|
||||
<ul>
|
||||
{% for message in messages %}
|
||||
<li>{{ message }}</li>
|
||||
<li id="message_{{ message.0 }}">{{ message.1 }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -12,12 +12,19 @@
|
||||
<ul>
|
||||
{% if perms.projector.can_manage_projector %}
|
||||
<li class="{% if request.path == url_projectoroverview %}selected{% endif %}">
|
||||
<a href="{% url projector_control %}">{% trans 'Overview' %}</a></li>
|
||||
<a href="{% url projector_control %}">{% trans 'Overview' %}</a>
|
||||
</li>
|
||||
<li class="{% if request.path == projector_messages %}selected{% endif %}">
|
||||
<a href="{% url projector_messages %}">{% trans 'Messages' %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if perms.projector.can_see_projector %}
|
||||
<li class="{% if request.path == url_projectornew %}selected{% endif %}">
|
||||
<a href="{% url projector_new %}">{% trans 'New Slide' %}</a></li>
|
||||
<li><a href="{% url projector_show %}"><img src="/static/images/icons/video-projector.png"> {% trans 'Projector view' %}</a></li>
|
||||
<a href="{% url projector_new %}">{% trans 'New Slide' %}</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="{% url projector_show %}"><img src="/static/images/icons/video-projector.png"> {% trans 'Projector view' %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
24
openslides/projector/templates/projector/messages.html
Normal file
24
openslides/projector/templates/projector/messages.html
Normal file
@ -0,0 +1,24 @@
|
||||
{% extends "projector/base_projector.html" %}
|
||||
|
||||
{% load tags %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{% trans 'Messages' %}</h1>
|
||||
<form action="" method="post">{% csrf_token %}
|
||||
<ul>
|
||||
{% for message in projector_messages %}
|
||||
<li><input type="checkbox" name="{{ message }}"{% if message.active %} checked="checked"{% endif %}>{{ message }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<button class="button" type="submit">
|
||||
<span class="icon ok">{%trans 'Save' %}</span>
|
||||
</button>
|
||||
<button class="button" type="submit" name="apply">
|
||||
<span class="icon apply">{%trans 'Apply' %}</span>
|
||||
</button>
|
||||
<button class="button" type="button" onclick="window.location='{% url projector_messages %}'">
|
||||
<span class="icon cancel">{%trans 'Cancel' %}</span>
|
||||
</button>
|
||||
</form>
|
||||
{% endblock %}
|
@ -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'),
|
||||
|
||||
|
@ -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':
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user