rewrote projector_messages system. Recalled it projector_overlay and added a special overlay for unique messages

This commit is contained in:
Oskar Hahn 2012-04-16 16:35:30 +02:00
parent 3bceca2359
commit 534a81c46c
11 changed files with 112 additions and 50 deletions

View File

@ -6,7 +6,6 @@
{% block title %}{{ block.super }} - {{ item.title }}{% endblock %}
{% block content %}
<div id="sidebar">
<div class="box">
<p><b>{%trans "Status" %}:</b><br>

View File

@ -3,20 +3,30 @@ from projector import SLIDE, Slide
from django.template.loader import render_to_string
def get_slide_from_sid(sid):
def split_sid(sid):
data = sid.split('-')
if len(data) == 2:
model = data[0]
id = data[1]
return SLIDE[model].model.objects.get(pk=id).slide()
return (model, id)
if len(data) == 1:
try:
return SLIDE[data[0]].func()
return (SLIDE[data[0]].func(), None)
except KeyError:
return None
return None
def get_slide_from_sid(sid):
key, id = split_sid(sid)
if id is not None:
return SLIDE[key].model.objects.get(pk=id).slide()
try:
return SLIDE[key].func()
except KeyError:
return None
def get_active_slide(only_sid=False):
"""
Returns the active slide. If no slide is active, or it can not find an Item,
@ -70,3 +80,19 @@ def register_slidefunc(key, func, control_template=None, weight=0, name=''):
weight=weight,
name=name,
)
def projector_message_set(message, sid=None):
from models import ProjectorOverlay
config['projector_message'] = message
try:
overlay = ProjectorOverlay.objects.get(def_name='Message')
except ProjectorOverlay.DoesNotExist:
overlay = ProjectorOverlay(def_name='Message', active=True)
print "hier mal ein ", sid
overlay.sid=sid
overlay.save()
def projector_message_delete():
config['projector_message'] = ''

View File

@ -1,4 +1,7 @@
from django.db import models
from django.dispatch import receiver
from openslides.config.signals import default_config_value
from api import register_slidemodel
from projector import SlideMixin
@ -31,13 +34,22 @@ class ProjectorSlide(models.Model, SlideMixin):
)
class ProjectorMessage(models.Model):
class ProjectorOverlay(models.Model):
active = models.BooleanField(verbose_name=_('Active'))
def_name = models.CharField(max_length=64)
sid = models.CharField(max_length=64, null=True, blank=True)
def __unicode__(self):
if self.sid:
return "%s on %s" % (self.def_name, self.sid)
return self.def_name
register_slidemodel(ProjectorSlide, model_name=_('Projector Slide'))
@receiver(default_config_value, dispatch_uid="config_default_config")
def default_config(sender, key, **kwargs):
return {
'projector_message': '',
}.get(key)

View File

@ -5,7 +5,7 @@ from django.utils.translation import ugettext as _
from config.models import config
from openslides.projector.signals import projector_messages
from openslides.projector.signals import projector_overlays
SLIDE = {}
@ -75,9 +75,9 @@ class Slide(object):
return 'No Model'
@receiver(projector_messages, dispatch_uid="projector_countdown")
@receiver(projector_overlays, dispatch_uid="projector_countdown")
def countdown(sender, **kwargs):
name = _('Countdown')
name = 'Countdown'
if kwargs['register']:
return name
if name in kwargs['call']:
@ -85,3 +85,15 @@ def countdown(sender, **kwargs):
seconds = max(0, int(starttime + config['agenda_countdown_time'] - time()))
return (name, seconds)
return None
@receiver(projector_overlays, dispatch_uid="projector_message")
def projector_message(sender, **kwargs):
name = 'Message'
if kwargs['register']:
return name
if name in kwargs['call']:
message = config['projector_message']
if message != '':
return (name, message)
return None

View File

@ -12,6 +12,6 @@
from django.dispatch import Signal
projector_messages = Signal(providing_args=['register', 'call'])
projector_overlays = Signal(providing_args=['register', 'call'])
projector_control_box = Signal()

View File

@ -15,9 +15,9 @@ function presentation_reload() {
$('#content li').css({'font-size': data.bigger + '%'}, 200);
$('#content #sidebar').css({'font-size': '16px'}, 0);
$('#content').animate({'margin-top': data.up + 'em'}, 200);
$('#messages li').remove();
$.each(data['messages'], function (index, value){
$('#messages ul').append('<li id="message_' + value[0] + '">' + value[1] + '</li>');
$('#overlays li').remove();
$.each(data['overlays'], function (index, value){
$('#overlays ul').append('<li id="overlay' + value[0] + '">' + value[1] + '</li>');
});
setTimeout("presentation_reload()", 500);
},

View File

@ -61,7 +61,7 @@ body{
border-bottom: 4px solid red;
}
#messages ul li {
#overlays ul li {
font-size: 4em;
font-weight: bold;
padding: 0 1em;

View File

@ -30,10 +30,10 @@
{% now "H:i" %}
</div>
<div id="messages">
<div id="overlays">
<ul>
{% for message in messages %}
<li id="message_{{ message.0 }}">{{ message.1 }}</li>
{% for overlay in overlays %}
<li id="overlay_{{ overlay.0 }}">{{ overlay.1 }}</li>
{% endfor %}
</ul>
</div>

View File

@ -39,6 +39,10 @@
{% block content %}
<h1>{% trans 'Projector' %}</h1>
<form action="" method="post">{% csrf_token %}
<input name='message_text' type='text' value="{% get_config 'projector_message' %}">
<button type="submit" class="button" name='message'><span class="icon ok">{% trans 'Save' %}</span></button>
</form>
<div style="text-align: right; padding: 0 10px 5px 0; margin-top:-20px;">
<!-- projector control -->
{% trans "Adjust projector view" %}:
@ -97,18 +101,18 @@
</div>
</div> <!-- end portlet-->
<!-- Messages (Countdown etc.)-->
<!-- Overlays (Countdown etc.)-->
<div class="portlet">
<div class="portlet-header">{% trans 'Messages' %}</div>
<div class="portlet-header">{% trans 'Overlays' %}</div>
<div class="portlet-content">
<ul style="line-height: 180%">
<form action="" method="post">{% csrf_token %}
<ul>
{% for message in projector_messages %}
{% for overlay in overlays %}
<li>
<input type="checkbox" name="{{ message }}" onchange="submit()"
{% if message.active %} checked="checked"{% endif %}> {{ message }}
{% if message.def_name == "Countdown" %}
<input type="checkbox" name="{{ overlay }}" onchange="submit()"
{% if overlay.active %} checked="checked"{% endif %}> {{ overlay }}
{% if overlay.def_name == "Countdown" %}
|
<a href="{% url config_agenda %}">{{countdown_time}}{% trans "sec" %}</a>
<a class="projector_countdown" href="{% url countdown_reset %}" title="{% trans 'Reset countdown' %}">

View File

@ -15,11 +15,11 @@ from time import time
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 _
from django.utils.datastructures import SortedDict
from django.dispatch import receiver
from django.template.loader import render_to_string
from django.db.models import Q
from utils.views import TemplateView, RedirectView
@ -30,10 +30,11 @@ from utils.template import Tab
from config.models import config
from api import get_active_slide, set_active_slide
from api import get_active_slide, set_active_slide, projector_message_set
from projector import SLIDE
from models import ProjectorMessage
from openslides.projector.signals import projector_messages, projector_control_box
from models import ProjectorOverlay
from openslides.projector.signals import projector_overlays, projector_control_box
from openslides.utils.signals import template_manipulation
from django.utils.importlib import import_module
import settings
@ -43,25 +44,28 @@ class ControlView(TemplateView):
template_name = 'projector/control.html'
permission_required = 'projector.can_manage_projector'
def get_projector_messages(self):
messages = []
for receiver, name in projector_messages.send(sender='registerer', register=True):
def get_projector_overlays(self):
overlays = []
for receiver, name in projector_overlays.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
projector_overlay = ProjectorOverlay.objects.get(def_name=name)
except ProjectorOverlay.DoesNotExist:
projector_overlay = ProjectorOverlay(def_name=name, active=False)
projector_overlay.save()
overlays.append(projector_overlay)
return overlays
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()
if 'message' in request.POST:
projector_message_set(request.POST['message_text'])
else:
for overlay in self.get_projector_overlays():
if overlay.def_name in request.POST:
overlay.active = True
else:
overlay.active = False
overlay.save()
return self.get(request, *args, **kwargs)
def get_context_data(self, **kwargs):
@ -88,7 +92,7 @@ class ControlView(TemplateView):
'categories': categories,
'countdown_visible': config['countdown_visible'],
'countdown_time': config['agenda_countdown_time'],
'projector_messages': self.get_projector_messages(),
'overlays': self.get_projector_overlays(),
})
return context
@ -122,20 +126,23 @@ def active_slide(request):
}
data['ajax'] = 'on'
data['messages'] = []
data['overlays'] = []
data['overlay'] = ''
# Projector Messages
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):
# Projector Overlays
sid = get_active_slide(True)
active_defs = ProjectorOverlay.objects.filter(active=True).filter(Q(sid=sid) | Q(sid=None)).values_list('def_name', flat=True)
for receiver, response in projector_overlays.send(sender=sid, register=False, call=active_defs):
if response is not None:
data['messages'].append(response)
data['overlays'].append(response)
template_manipulation.send(sender='projector', request=request, context=data)
if request.is_ajax():
content = render_block_to_string(data['template'], 'content', data)
jsondata = {
'content': content,
'messages': data['messages'],
'overlays': data['overlays'],
'title': data['title'],
'time': datetime.now().strftime('%H:%M'),
'bigger': config['bigger'],
@ -143,6 +150,7 @@ def active_slide(request):
'countdown_visible': config['countdown_visible'],
'countdown_time': config['agenda_countdown_time'],
'countdown_control': config['countdown_control'],
'overlay': data['overlay']
}
return ajax_request(jsondata)
else:
@ -153,7 +161,6 @@ def active_slide(request):
)
@permission_required('agenda.can_manage_agenda')
def projector_edit(request, direction):
if direction == 'bigger':

View File

@ -10,10 +10,12 @@ register = template.Library()
def get_min_supporters():
return config['application_min_supporters']
@register.simple_tag
def get_config(key):
return config[key]
@register.simple_tag
def active(request, pattern):
if request.path.startswith(pattern):