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 title %}{{ block.super }} - {{ item.title }}{% endblock %}
{% block content %} {% block content %}
<div id="sidebar"> <div id="sidebar">
<div class="box"> <div class="box">
<p><b>{%trans "Status" %}:</b><br> <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 from django.template.loader import render_to_string
def get_slide_from_sid(sid): def split_sid(sid):
data = sid.split('-') data = sid.split('-')
if len(data) == 2: if len(data) == 2:
model = data[0] model = data[0]
id = data[1] id = data[1]
return SLIDE[model].model.objects.get(pk=id).slide() return (model, id)
if len(data) == 1: if len(data) == 1:
try: try:
return SLIDE[data[0]].func() return (SLIDE[data[0]].func(), None)
except KeyError: except KeyError:
return None return None
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): def get_active_slide(only_sid=False):
""" """
Returns the active slide. If no slide is active, or it can not find an Item, 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, weight=weight,
name=name, 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.db import models
from django.dispatch import receiver
from openslides.config.signals import default_config_value
from api import register_slidemodel from api import register_slidemodel
from projector import SlideMixin 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')) active = models.BooleanField(verbose_name=_('Active'))
def_name = models.CharField(max_length=64) def_name = models.CharField(max_length=64)
sid = models.CharField(max_length=64, null=True, blank=True)
def __unicode__(self): def __unicode__(self):
if self.sid:
return "%s on %s" % (self.def_name, self.sid)
return self.def_name return self.def_name
register_slidemodel(ProjectorSlide, model_name=_('Projector Slide')) 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 config.models import config
from openslides.projector.signals import projector_messages from openslides.projector.signals import projector_overlays
SLIDE = {} SLIDE = {}
@ -75,9 +75,9 @@ class Slide(object):
return 'No Model' return 'No Model'
@receiver(projector_messages, dispatch_uid="projector_countdown") @receiver(projector_overlays, dispatch_uid="projector_countdown")
def countdown(sender, **kwargs): def countdown(sender, **kwargs):
name = _('Countdown') name = 'Countdown'
if kwargs['register']: if kwargs['register']:
return name return name
if name in kwargs['call']: if name in kwargs['call']:
@ -85,3 +85,15 @@ def countdown(sender, **kwargs):
seconds = max(0, int(starttime + config['agenda_countdown_time'] - time())) seconds = max(0, int(starttime + config['agenda_countdown_time'] - time()))
return (name, seconds) return (name, seconds)
return None 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 from django.dispatch import Signal
projector_messages = Signal(providing_args=['register', 'call']) projector_overlays = Signal(providing_args=['register', 'call'])
projector_control_box = Signal() projector_control_box = Signal()

View File

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

View File

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

View File

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

View File

@ -39,6 +39,10 @@
{% block content %} {% block content %}
<h1>{% trans 'Projector' %}</h1> <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;"> <div style="text-align: right; padding: 0 10px 5px 0; margin-top:-20px;">
<!-- projector control --> <!-- projector control -->
{% trans "Adjust projector view" %}: {% trans "Adjust projector view" %}:
@ -97,18 +101,18 @@
</div> </div>
</div> <!-- end portlet--> </div> <!-- end portlet-->
<!-- Messages (Countdown etc.)--> <!-- Overlays (Countdown etc.)-->
<div class="portlet"> <div class="portlet">
<div class="portlet-header">{% trans 'Messages' %}</div> <div class="portlet-header">{% trans 'Overlays' %}</div>
<div class="portlet-content"> <div class="portlet-content">
<ul style="line-height: 180%"> <ul style="line-height: 180%">
<form action="" method="post">{% csrf_token %} <form action="" method="post">{% csrf_token %}
<ul> <ul>
{% for message in projector_messages %} {% for overlay in overlays %}
<li> <li>
<input type="checkbox" name="{{ message }}" onchange="submit()" <input type="checkbox" name="{{ overlay }}" onchange="submit()"
{% if message.active %} checked="checked"{% endif %}> {{ message }} {% if overlay.active %} checked="checked"{% endif %}> {{ overlay }}
{% if message.def_name == "Countdown" %} {% if overlay.def_name == "Countdown" %}
| |
<a href="{% url config_agenda %}">{{countdown_time}}{% trans "sec" %}</a> <a href="{% url config_agenda %}">{{countdown_time}}{% trans "sec" %}</a>
<a class="projector_countdown" href="{% url countdown_reset %}" title="{% trans 'Reset countdown' %}"> <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.shortcuts import render_to_response, redirect
from django.template import RequestContext from django.template import RequestContext
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib import messages
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict
from django.dispatch import receiver from django.dispatch import receiver
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.db.models import Q
from utils.views import TemplateView, RedirectView from utils.views import TemplateView, RedirectView
@ -30,10 +30,11 @@ from utils.template import Tab
from config.models import config 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 projector import SLIDE
from models import ProjectorMessage from models import ProjectorOverlay
from openslides.projector.signals import projector_messages, projector_control_box from openslides.projector.signals import projector_overlays, projector_control_box
from openslides.utils.signals import template_manipulation
from django.utils.importlib import import_module from django.utils.importlib import import_module
import settings import settings
@ -43,25 +44,28 @@ class ControlView(TemplateView):
template_name = 'projector/control.html' template_name = 'projector/control.html'
permission_required = 'projector.can_manage_projector' permission_required = 'projector.can_manage_projector'
def get_projector_messages(self): def get_projector_overlays(self):
messages = [] overlays = []
for receiver, name in projector_messages.send(sender='registerer', register=True): for receiver, name in projector_overlays.send(sender='registerer', register=True):
if name is not None: if name is not None:
try: try:
projector_message = ProjectorMessage.objects.get(def_name=name) projector_overlay = ProjectorOverlay.objects.get(def_name=name)
except ProjectorMessage.DoesNotExist: except ProjectorOverlay.DoesNotExist:
projector_message = ProjectorMessage(def_name=name, active=False) projector_overlay = ProjectorOverlay(def_name=name, active=False)
projector_message.save() projector_overlay.save()
messages.append(projector_message) overlays.append(projector_overlay)
return messages return overlays
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
for message in self.get_projector_messages(): if 'message' in request.POST:
if message.def_name in request.POST: projector_message_set(request.POST['message_text'])
message.active = True
else: else:
message.active = False for overlay in self.get_projector_overlays():
message.save() if overlay.def_name in request.POST:
overlay.active = True
else:
overlay.active = False
overlay.save()
return self.get(request, *args, **kwargs) return self.get(request, *args, **kwargs)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
@ -88,7 +92,7 @@ class ControlView(TemplateView):
'categories': categories, 'categories': categories,
'countdown_visible': config['countdown_visible'], 'countdown_visible': config['countdown_visible'],
'countdown_time': config['agenda_countdown_time'], 'countdown_time': config['agenda_countdown_time'],
'projector_messages': self.get_projector_messages(), 'overlays': self.get_projector_overlays(),
}) })
return context return context
@ -122,20 +126,23 @@ def active_slide(request):
} }
data['ajax'] = 'on' data['ajax'] = 'on'
data['messages'] = [] data['overlays'] = []
data['overlay'] = ''
# Projector Messages # Projector Overlays
active_defs = ProjectorMessage.objects.filter(active=True).values_list('def_name', flat=True) sid = get_active_slide(True)
for receiver, response in projector_messages.send(sender='active_slide', register=False, call=active_defs): 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: 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(): if request.is_ajax():
content = render_block_to_string(data['template'], 'content', data) content = render_block_to_string(data['template'], 'content', data)
jsondata = { jsondata = {
'content': content, 'content': content,
'messages': data['messages'], 'overlays': data['overlays'],
'title': data['title'], 'title': data['title'],
'time': datetime.now().strftime('%H:%M'), 'time': datetime.now().strftime('%H:%M'),
'bigger': config['bigger'], 'bigger': config['bigger'],
@ -143,6 +150,7 @@ def active_slide(request):
'countdown_visible': config['countdown_visible'], 'countdown_visible': config['countdown_visible'],
'countdown_time': config['agenda_countdown_time'], 'countdown_time': config['agenda_countdown_time'],
'countdown_control': config['countdown_control'], 'countdown_control': config['countdown_control'],
'overlay': data['overlay']
} }
return ajax_request(jsondata) return ajax_request(jsondata)
else: else:
@ -153,7 +161,6 @@ def active_slide(request):
) )
@permission_required('agenda.can_manage_agenda') @permission_required('agenda.can_manage_agenda')
def projector_edit(request, direction): def projector_edit(request, direction):
if direction == 'bigger': if direction == 'bigger':

View File

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