Merge pull request #734 from normanjaeckel/WidgetRework

Add request to all widgets, fixed #653
This commit is contained in:
Oskar Hahn 2013-06-13 15:51:51 -07:00
commit 431e8cc6a0
10 changed files with 56 additions and 15 deletions

View File

@ -66,6 +66,7 @@ def get_personal_info_widget(request):
if personal_info_context:
return Widget(
request,
name='personal_info',
display_name=_('My items, motions and elections'),
template='account/personal_info_widget.html',

View File

@ -18,7 +18,6 @@ from django.core.urlresolvers import reverse
from django.contrib import messages
from django.db import transaction
from django.db.models import Model
from django.template import RequestContext
from django.utils.translation import ugettext as _, ugettext_lazy
from django.views.generic.detail import SingleObjectMixin
@ -547,6 +546,7 @@ def get_widgets(request):
"""
return [
Widget(
request,
name='agenda',
display_name=_('Agenda'),
template='agenda/widget.html',
@ -558,8 +558,8 @@ def get_widgets(request):
permission_required='projector.can_manage_projector'),
Widget(
request,
name='append_to_list_of_speakers',
display_name=_('List of speakers'),
template='agenda/speaker_widget.html',
context=RequestContext(request, {}),
permission_required='agenda.can_be_speaker')]

View File

@ -641,6 +641,7 @@ def register_tab(request):
def get_widgets(request):
return [Widget(
request,
name='assignments',
display_name=_('Elections'),
template='assignment/widget.html',

View File

@ -760,6 +760,7 @@ def get_widgets(request):
There is only one widget. It shows all motions.
"""
return [Widget(
request,
name='motions',
display_name=_('Motions'),
template='motion/widget.html',

View File

@ -556,6 +556,7 @@ def get_user_widget(request):
user slides.
"""
return Widget(
request,
name='user',
display_name=_('Participants'),
template='participant/user_widget.html',
@ -570,6 +571,7 @@ def get_group_widget(request):
group slides.
"""
return Widget(
request,
name='group',
display_name=_('Groups'),
template='participant/group_widget.html',

View File

@ -121,6 +121,13 @@ def register_slidefunc(key, func, control_template=None, weight=0, name=''):
def get_all_widgets(request, session=False):
"""
Collects the widgets from all apps and returns the Widget objects as sorted
dictionary.
The session flag decides whether to return only the widgets which are
active, that means that they are mentioned in the session.
"""
widgets = SortedDict()
session_widgets = request.session.get('widgets', {})
for app in settings.INSTALLED_APPS:

View File

@ -16,6 +16,8 @@ from django.dispatch import receiver
from django.template.loader import render_to_string
from openslides.config.api import config
from django.template import RequestContext
from openslides.utils.exceptions import OpenSlidesError
SLIDE = {}
@ -113,7 +115,7 @@ class Widget(object):
"""
Class for a Widget for the Projector-Tab.
"""
def __init__(self, name, html=None, template=None, context={},
def __init__(self, request, name, html=None, template=None, context={},
permission_required=None, display_name=None, default_column=1):
self.name = name
if display_name is None:
@ -124,7 +126,12 @@ class Widget(object):
if html is not None:
self.html = html
elif template is not None:
self.html = render_to_string(template, context)
self.html = render_to_string(
template_name=template,
dictionary=context,
context_instance=RequestContext(request))
else:
raise OpenSlidesError('A Widget must have either a html or a template argument.')
self.permission_required = permission_required
self.default_column = default_column

View File

@ -375,34 +375,33 @@ def get_widgets(request):
"""
widgets = []
# welcome widget
context = {
'welcometext': config['welcome_text']}
# Welcome widget
widgets.append(Widget(
request,
name='welcome',
display_name=config['welcome_title'],
template='projector/welcome_widget.html',
context=context,
context={'welcometext': config['welcome_text']},
permission_required='projector.can_see_dashboard',
default_column=1))
# Projector live view widget
widgets.append(Widget(
request,
name='live_view',
display_name=_('Projector live view'),
template='projector/live_view_widget.html',
context=RequestContext(request, {}),
permission_required='projector.can_see_projector',
default_column=2))
# Overlay Widget
# Overlay widget
overlays = []
for receiver, overlay in projector_overlays.send(sender='overlay_widget', request=request):
overlays.append(overlay)
context = {'overlays': overlays}
context.update(csrf(request))
widgets.append(Widget(
request,
name='overlays',
display_name=_('Overlays'),
template='projector/overlay_widget.html',
@ -411,14 +410,14 @@ def get_widgets(request):
context=context))
# Custom slide widget
context = {
'slides': ProjectorSlide.objects.all().order_by('weight'),
'welcomepage_is_active': not bool(config["presentation"])}
widgets.append(Widget(
request,
name='custom_slide',
display_name=_('Custom Slides'),
template='projector/custom_slide_widget.html',
context=context,
context={
'slides': ProjectorSlide.objects.all().order_by('weight'),
'welcomepage_is_active': not bool(config["presentation"])},
permission_required='projector.can_manage_projector',
default_column=2))

View File

View File

@ -0,0 +1,23 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Tests for openslides widgets
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TODO: Move this test to the correct place when the projector app is cleaned up.
:copyright: 20112013 by OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details.
"""
from django.http import HttpRequest
from openslides.projector.projector import Widget
from openslides.utils.exceptions import OpenSlidesError
from openslides.utils.test import TestCase
class WidgetObject(TestCase):
def test_error(self):
with self.assertRaises(OpenSlidesError):
w = Widget(HttpRequest(), name='chahghuyeim8ie0Noong')