rewrote projector-widget system

This commit is contained in:
Oskar Hahn 2012-06-11 13:43:48 +02:00
parent 960543b64e
commit 239f328372
16 changed files with 184 additions and 135 deletions

View File

@ -155,4 +155,3 @@ def default_config(sender, key, **kwargs):
return {
'agenda_countdown_time': 60,
}.get(key)

View File

@ -1,18 +0,0 @@
{% load staticfiles %}
{% load i18n %}
<ul style="line-height: 180%">
{% for slide in slides.get_items %}
<li class="{% if slide.active %}activeline{% endif %}">
<a href="{% url projector_activate_slide slide.sid %}" class="activate_link {% if slide.active %}active{% endif %}">
<div></div>
</a>
<a href="{% url projctor_preview_slide slide.sid %}" title="{% trans 'Preview' %}" class="icon preview right"><span></span></a>
{% for p in slide.get_ancestors %}
<span class="indentation">&nbsp;</span>
{% endfor %}
<a href="{% url item_edit slide.id %}">{{ slide }}</a>
</li>
{% endfor %}
</ul>

View File

@ -0,0 +1,33 @@
{% load staticfiles %}
{% load i18n %}
{% load tags %}
<ul style="line-height: 180%">
<li class="{% if agenda.active %}activeline{% endif %}">
<a href="{% url projector_activate_slide agenda.key %}" class="activate_link {% if agenda.active %}active{% endif %}">
<div></div>
</a>
<a href="{% url projctor_preview_slide agenda.key %}" title="{% trans 'Preview' %}" class="icon preview right">
<span></span>
</a>
{{ agenda.name }}
</li>
</ul>
<hr>
<ul style="line-height: 180%">
{% for item in items %}
<li class="{% if item.active %}activeline{% endif %}">
<a href="{% url projector_activate_slide item.sid %}" class="activate_link {% if item.active %}active{% endif %}">
<div></div>
</a>
<a href="{% url projctor_preview_slide item.sid %}" title="{% trans 'Preview' %}" class="icon preview right">
<span></span>
</a>
{% for p in item.get_ancestors %}
<span class="indentation">&nbsp;</span>
{% endfor %}
<a href="{% model_url item 'edit' %}">{{ item }}</a>
</li>
{% endfor %}
</ul>

View File

@ -26,6 +26,7 @@ from utils.template import Tab
from config.models import config
from projector.api import get_active_slide, set_active_slide
from projector.projector import Widget, SLIDE
from agenda.models import Item
from agenda.forms import ItemOrderForm, ItemForm, ConfigForm
@ -205,3 +206,16 @@ def register_tab(request):
permission=request.user.has_perm('agenda.can_see_agenda') or request.user.has_perm('agenda.can_manage_agenda'),
selected=selected,
)
def get_widgets(request):
return [
Widget(
name='agenda',
template='agenda/widget.html',
context={
'agenda': SLIDE['agenda'],
'items': Item.objects.all(),
}
),
]

View File

@ -21,6 +21,10 @@ try:
except ImportError: # python <= 2.5
from cgi import parse_qs
from reportlab.lib import colors
from reportlab.lib.units import cm
from reportlab.platypus import SimpleDocTemplate, PageBreak, Paragraph, Spacer, Table, TableStyle
from django.shortcuts import redirect
from django.contrib import messages
from django.contrib.auth.decorators import login_required
@ -31,14 +35,20 @@ from django.utils.translation import ugettext as _
from django.utils.translation import ungettext
from django.db import transaction
from reportlab.lib import colors
from reportlab.lib.units import cm
from reportlab.platypus import SimpleDocTemplate, PageBreak, Paragraph, Spacer, Table, TableStyle
from config.models import config
from settings import SITE_ROOT
from utils.pdf import stylesheet
from utils.views import PDFView, RedirectView, DeleteView
from utils.views import PDFView, RedirectView, DeleteView, FormView
from utils.utils import template, permission_required, \
render_to_forbitten, del_confirm_form, gen_confirm_form
from utils.template import Tab
from projector.api import get_model_widget
from poll.views import PollFormView
from agenda.models import Item
@ -51,14 +61,6 @@ from application.forms import (
)
from participant.models import Profile
from poll.views import PollFormView
from utils.utils import template, permission_required, \
render_to_forbitten, del_confirm_form, gen_confirm_form
from utils.views import FormView
from utils.template import Tab
from participant.api import gen_username, gen_password
@ -890,3 +892,7 @@ def register_tab(request):
permission=request.user.has_perm('application.can_see_application') or request.user.has_perm('application.can_support_application') or request.user.has_perm('application.can_support_application') or request.user.has_perm('application.can_manage_application'),
selected=selected,
)
def get_widgets(request):
return [get_model_widget(name='applications', model=Application)]

View File

@ -11,6 +11,7 @@
"""
from django.db import models
from django.core.urlresolvers import reverse
from config.models import config
@ -141,12 +142,13 @@ class Assignment(models.Model, SlideMixin):
data['template'] = 'projector/Assignment.html'
return data
@models.permalink
def get_absolute_url(self, link='view'):
if link == 'view':
return ('assignment_view', [str(self.id)])
return reverse('assignment_view', [str(self.id)])
if link == 'edit':
return reverse('assignment_edit', args=[str(self.id)])
if link == 'delete':
return ('assignment_delete', [str(self.id)])
return reverse('assignment_delete', [str(self.id)])
def __unicode__(self):
return self.name

View File

@ -11,6 +11,11 @@
"""
import os
from reportlab.lib import colors
from reportlab.lib.units import cm
from reportlab.platypus import SimpleDocTemplate, PageBreak, Paragraph, Spacer, Table, TableStyle
from django.shortcuts import redirect
from django.core.urlresolvers import reverse
from django.contrib import messages
@ -18,17 +23,16 @@ from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.utils.translation import ungettext, ugettext as _
from reportlab.lib import colors
from reportlab.lib.units import cm
from reportlab.platypus import SimpleDocTemplate, PageBreak, Paragraph, Spacer, Table, TableStyle
from config.models import config
from settings import SITE_ROOT
from utils.utils import template, permission_required, gen_confirm_form, del_confirm_form, ajax_request
from utils.pdf import stylesheet
from utils.views import FormView, DeleteView, PDFView
from utils.template import Tab
from projector.api import get_model_widget
from poll.views import PollFormView
from assignment.models import Assignment, AssignmentPoll, AssignmentOption
@ -36,7 +40,6 @@ from assignment.forms import AssignmentForm, AssignmentRunForm, ConfigForm
from participant.models import Profile
from settings import SITE_ROOT
@permission_required('assignment.can_see_assignment')
@template('assignment/overview.html')
@ -597,3 +600,7 @@ def register_tab(request):
permission=request.user.has_perm('assignment.can_see_assignment') or request.user.has_perm('assignment.can_nominate_other') or request.user.has_perm('assignment.can_nominate_self') or request.user.has_perm('assignment.can_manage_assignment'),
selected=selected,
)
def get_widgets(request):
return [get_model_widget(name='assignments', model=Assignment)]

View File

@ -10,10 +10,11 @@
:license: GNU GPL, see LICENSE for more details.
"""
from config.models import config
from projector import SLIDE, Slide
from django.template.loader import render_to_string
from config.models import config
from projector import SLIDE, Slide, Widget
def split_sid(sid):
try:
@ -121,3 +122,13 @@ def projector_message_set(message, sid=None):
def projector_message_delete():
config['projector_message'] = ''
def get_model_widget(name, model):
return Widget(
name=name,
template='projector/model_widget.html',
context={
'slides': model.objects.all(),
}
)

View File

@ -13,6 +13,7 @@
from time import time
from django.dispatch import receiver
from django.template.loader import render_to_string
from config.models import config
@ -22,6 +23,9 @@ from openslides.projector.signals import projector_overlays
SLIDE = {}
class SlideMixin(object):
"""
A Mixin for a Django-Model, for making the model a slide.
"""
def slide(self):
"""
@ -91,6 +95,24 @@ class Slide(object):
return 'No Model'
class Widget(object):
def __init__(self, name, html=None, template=None, context={}):
self.name = name
if html is not None:
self.html = html
elif template is not None:
self.html = render_to_string(template, context)
def get_name(self):
return self.name
def get_html(self):
return self.html
def get_title(self):
return self.name.capitalize()
@receiver(projector_overlays, dispatch_uid="projector_countdown")
def countdown(sender, **kwargs):
name = 'Countdown'

View File

@ -148,24 +148,15 @@
</div>
<div class="column" id="col1">
{% for category, group in categories.items %}
{% if category != 'projector' %}
<div class="portlet" id="portlet_{{category}}">
{% with category_big=category|capfirst %}
<div class="portlet-header">{% trans category_big %}</div>
{% endwith %}
<div class="portlet-content">
{% for slides in group %}
{% if slides.control_template %}
{% include slides.control_template %}
{% endif %}
{% if not forloop.last %}
<hr>
{% endif %}
{% endfor %}
{% for name, widget in widgets.items %}
{% if name != 'projector' %}
<div class="portlet" id="portlet_{{ widget.get_name }}">
<div class="portlet-header">{% trans widget.get_title %}</div>
<div class="portlet-content">
{{ widget.html }}
</div>
</div>
</div> <!-- end portlet-->
{% endif %}
{% endif %}
{% endfor %}
</div> <!-- end column-->
@ -243,27 +234,13 @@
</div> <!-- end portlet-->
<!-- Custom slides -->
{% for category, group in categories.items %}
{% if category == 'projector' %}
{% with widget=widgets.projector %}
<div class="portlet" id="portlet_customslides">
<div class="portlet-header">{% trans "Custom slides" %}</div>
<div class="portlet-content">
{% for slides in group %}
{% if slides.control_template %}
{% include slides.control_template %}
{% endif %}
{% if not forloop.last %}
<hr>
{% endif %}
{% endfor %}
<a href='{% url customslide_new %}'>
<button class="button" type="button" onclick="window.location='{% url customslide_new %}'">
<span class="icon add">{%trans 'New slide' %}</span>
</button>
</a>
{{ widget.html }}
</div>
</div> <!-- end portlet-->
{% endif %}
{% endfor %}
{% endwith %}
</div> <!-- end column -->
{% endblock %}

View File

@ -1,13 +0,0 @@
{% load staticfiles %}
{% load i18n %}
<ul style="line-height: 180%">
<li class="{% if slides.active %}activeline{% endif %}">
<a href="{% url projector_activate_slide slides.key %}" class="activate_link {% if slides.active %}active{% endif %}">
<div></div>
</a>
<a href="{% url projctor_preview_slide slides.key %}" title="{% trans 'Preview' %}" class="icon preview right"><span></span></a>
{{ slides.name }}
</li>
</ul>

View File

@ -1,14 +1,17 @@
{% load staticfiles %}
{% load i18n %}
{% load tags %}
<ul style="line-height: 180%">
{% for slide in slides.get_items %}
{% for slide in slides %}
<li class="{% if slide.active %}activeline{% endif %}">
<a href="{% url projector_activate_slide slide.sid %}" class="activate_link {% if slide.active %}active{% endif %}">
<div></div>
</a>
<a href="{% url projctor_preview_slide slide.sid %}" title="{% trans 'Preview' %}" class="icon preview right"><span></span></a>
<a href="{{ slide.get_absolute_url }}">{{ slide }}</a>
<a href="{% url projctor_preview_slide slide.sid %}" title="{% trans 'Preview' %}" class="icon preview right">
<span></span>
</a>
<a href="{% model_url slide 'edit' %}">{{ slide }}</a>
</li>
{% endfor %}
</ul>

View File

@ -1,19 +1,28 @@
{% load staticfiles %}
{% load i18n %}
{% load tags %}
<ul style="line-height: 180%">
{% for slide in slides.get_items %}
{% for slide in slides %}
<li class="{% if slide.active %}activeline{% endif %}">
<a href="{% url projector_activate_slide slide.sid %}" class="activate_link {% if slide.active %}active{% endif %}">
<div></div>
</a>
<a href="{% url customslide_delete slide.id %}" title="{% trans 'Delete slide' %}" class="icon delete right"><span></span></a>
<a href="{% url projctor_preview_slide slide.sid %}" title="{% trans 'Preview' %}" class="icon preview right"><span></span></a>
{% for p in slide.get_ancestors %}
<span class="indentation">&nbsp;</span>
{% endfor %}
<a href="{% url customslide_delete slide.id %}" title="{% trans 'Delete slide' %}" class="icon delete right">
<span></span>
</a>
<a href="{% url projctor_preview_slide slide.sid %}" title="{% trans 'Preview' %}" class="icon preview right">
<span></span>
</a>
<a href="{% url customslide_edit slide.id %}">{{ slide }}</a>
</li>
{% endfor %}
</ul>
<hr>
<a href='{% url customslide_new %}'>
<button class="button" type="button" onclick="window.location='{% url customslide_new %}'">
<span class="icon add">{%trans 'New slide' %}</span>
</button>
</a>

View File

@ -19,6 +19,7 @@ from django.template import RequestContext
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
from django.utils.datastructures import SortedDict
from django.utils.importlib import import_module
from django.dispatch import receiver
from django.template.loader import render_to_string
from django.db.models import Q
@ -26,22 +27,18 @@ from django.db.models import Q
from utils.views import TemplateView, RedirectView, CreateView, UpdateView, DeleteView
from utils.utils import (template, permission_required, del_confirm_form,
ajax_request, load_models)
from utils.template import render_block_to_string
from utils.template import Tab
from config.models import config
from api import get_active_slide, set_active_slide, projector_message_set, projector_message_delete, get_slide_from_sid
from projector import SLIDE
from models import ProjectorOverlay, ProjectorSlide
from openslides.projector.signals import projector_overlays, projector_control_box
ajax_request)
from utils.template import render_block_to_string, Tab
from openslides.utils.signals import template_manipulation
from django.utils.importlib import import_module
from config.models import config
import settings
load_models()
from api import get_active_slide, set_active_slide, projector_message_set, projector_message_delete, get_slide_from_sid
from projector import SLIDE, Widget
from models import ProjectorOverlay, ProjectorSlide
from openslides.projector.signals import projector_overlays, projector_control_box
class ControlView(TemplateView):
template_name = 'projector/control.html'
@ -76,29 +73,28 @@ class ControlView(TemplateView):
def get_context_data(self, **kwargs):
context = super(ControlView, self).get_context_data(**kwargs)
categories = {}
for slide in SLIDE.values():
if not categories.has_key(slide.category):
categories[slide.category] = []
categories[slide.category].append(slide)
tmp_categories = categories
categories = SortedDict()
widgets = SortedDict()
for app in settings.INSTALLED_APPS:
if app in tmp_categories:
tmp_categories[app].sort(key=lambda slide: slide.weight)
categories[app] = tmp_categories[app]
try:
mod = import_module(app + '.views')
except ImportError:
continue
appname = mod.__name__.split('.')[0]
try:
modul_widgets = mod.get_widgets(self.request)
except AttributeError:
continue
for widget in modul_widgets:
widgets[widget.get_name()] = widget
## for receiver, response in projector_control_box.send(sender='ControllView'):
## if response is not None:
## categories[response[0]] = response[1]
context.update({
'categories': categories,
'countdown_time': config['agenda_countdown_time'],
'countdown_state' : config['countdown_state'],
'overlays': self.get_projector_overlays(),
'widgets': widgets,
})
return context
@ -294,6 +290,13 @@ def register_tab(request):
)
## @receiver(projector_control_box, dispatch_uid="openslides.projector.views.projector_box")
## def projector_box(sender, **kwargs):
## return ('header', 'text')
def get_widgets(request):
return [
Widget(
name='projector',
template='projector/widget.html',
context={
'slides': ProjectorSlide.objects.all(),
}
),
]

View File

@ -15,6 +15,7 @@ from config.models import config
register = template.Library()
@register.simple_tag
def get_min_supporters():
return config['application_min_supporters']
@ -31,6 +32,7 @@ def active(request, pattern):
return 'selected'
return ''
@register.simple_tag
def model_url(object, link='view'):
return object.get_absolute_url(link)

View File

@ -126,11 +126,3 @@ def encodedict(dict):
for key in dict:
newdict[key] = [unicode(dict[key][0].decode('utf-8'))]
return newdict
def load_models():
for app in settings.INSTALLED_APPS:
try:
mod = import_module(app + '.models')
except ImportError:
continue