added select widgets view

This commit is contained in:
Oskar Hahn 2012-08-15 13:42:25 +02:00
parent 6b7ea558fc
commit 416f3f6ff3
7 changed files with 136 additions and 28 deletions

View File

@ -10,7 +10,10 @@
:license: GNU GPL, see LICENSE for more details. :license: GNU GPL, see LICENSE for more details.
""" """
from django.conf import settings
from django.template.loader import render_to_string from django.template.loader import render_to_string
from django.utils.datastructures import SortedDict
from django.utils.importlib import import_module
from openslides.config.models import config from openslides.config.models import config
from openslides.projector.projector import SLIDE, Slide, Widget from openslides.projector.projector import SLIDE, Slide, Widget
@ -145,3 +148,26 @@ def projector_message_delete():
Delete the overlay-message. Delete the overlay-message.
""" """
config['projector_message'] = '' config['projector_message'] = ''
def get_all_widgets(request, session=False):
widgets = SortedDict()
session_widgets = request.session.get('widgets', {})
for app in settings.INSTALLED_APPS:
try:
mod = import_module(app + '.views')
except ImportError:
continue
appname = mod.__name__.split('.')[0]
try:
modul_widgets = mod.get_widgets(request)
except AttributeError:
continue
for widget in modul_widgets:
print widget, session_widgets.get(widget, True)
if (widget.permission_required is None or
request.user.has_perm(widget.permission_required)):
if not session or session_widgets.get(widget.get_name(), True):
widgets[widget.get_name()] = widget
return widgets

View File

@ -0,0 +1,23 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
openslides.projector.forms
~~~~~~~~~~~~~~~~~~~~~~~~~~
Forms for the projector app.
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details.
"""
from django import forms
from django.utils.translation import ugettext_lazy as _
from openslides.utils.forms import CssClassMixin
class SelectWidgetsForm(forms.Form, CssClassMixin):
"""
Form to select the widgets.
"""
widget = forms.BooleanField(required=False)

View File

@ -131,7 +131,7 @@ class Widget(object):
return self.display_name return self.display_name
def __repr__(self): def __repr__(self):
return self.get_name() return unicode(self.display_name)
@receiver(projector_overlays, dispatch_uid="projector_countdown") @receiver(projector_overlays, dispatch_uid="projector_countdown")

View File

@ -8,13 +8,15 @@
{% block submenu %} {% block submenu %}
{% url dashboard as url_dashboard %} {% url dashboard as url_dashboard %}
{% url projector_select_widgets as url_select_widget %}
<h4 class="sectiontitle">{% trans "Projector" %}</h4> <h4 class="sectiontitle">{% trans "Projector" %}</h4>
<ul> <ul>
{% if perms.projector.can_manage_projector %} <li{% if request.path == url_dashboard %} class="selected"{% endif %}>
<li{% if request.path == url_dashboard %} class="selected"{% endif %}> <a href="{% url dashboard %}">{% trans 'Overview' %}</a>
<a href="{% url dashboard %}">{% trans 'Overview' %}</a> </li>
</li> <li{% if request.path == url_select_widget %} class="selected"{% endif %}>
{% endif %} <a href="{{ url_select_widget }}">{% trans 'Select widgets' %}</a>
</li>
{% if perms.projector.can_see_projector %} {% if perms.projector.can_see_projector %}
<li> <li>
<a href="{% url projector_show %}"><img src="{% static 'images/icons/projector.png' %}"> {% trans 'Projector view' %}</a> <a href="{% url projector_show %}"><img src="{% static 'images/icons/projector.png' %}"> {% trans 'Projector view' %}</a>

View File

@ -0,0 +1,26 @@
{% extends "projector/base_projector.html" %}
{% load i18n %}
{% block title %}{{ block.super }} {% trans 'Select widgets' %}{% endblock %}
{% block content %}
<h1>{% trans 'Select widgets' %}</h1>
<form action="" method="post">{% csrf_token %}
<ul>
{% for widget_name, widget in widgets.items %}
<li>
{{ widget.form.widget }} {{ widget }}
</li>
{% empty %}
<li>{% trans 'No widgets available' %}</li>
{% endfor %}
</ul>
<p>
<button class="button" type="submit">
<span class="icon ok">{% trans 'Save' %}</span>
</button>
</p>
</form>
{% endblock %}

View File

@ -14,7 +14,7 @@ from django.conf.urls.defaults import patterns, url
from openslides.projector.views import (DashboardView, ActivateView, from openslides.projector.views import (DashboardView, ActivateView,
CustomSlideCreateView, CustomSlideUpdateView, CustomSlideDeleteView, CustomSlideCreateView, CustomSlideUpdateView, CustomSlideDeleteView,
CountdownEdit, ProjectorEdit, Projector, ActivateOverlay) CountdownEdit, ProjectorEdit, Projector, ActivateOverlay, SelectWidgetsView)
urlpatterns = patterns('', urlpatterns = patterns('',
@ -56,6 +56,11 @@ urlpatterns = patterns('',
name='projector_activate_slide', name='projector_activate_slide',
), ),
url(r'^widgets/$',
SelectWidgetsView.as_view(),
name='projector_select_widgets',
),
url(r'^new/$', url(r'^new/$',
CustomSlideCreateView.as_view(), CustomSlideCreateView.as_view(),
name='customslide_new', name='customslide_new',

View File

@ -16,6 +16,7 @@ from time import time
from django.conf import settings from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db import transaction
from django.db.models import Q from django.db.models import Q
from django.dispatch import receiver from django.dispatch import receiver
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict
@ -30,7 +31,9 @@ from openslides.utils.views import (TemplateView, RedirectView, CreateView,
from openslides.config.models import config from openslides.config.models import config
from openslides.projector.api import (get_active_slide, set_active_slide, from openslides.projector.api import (get_active_slide, set_active_slide,
projector_message_set, projector_message_delete, get_slide_from_sid) projector_message_set, projector_message_delete, get_slide_from_sid,
get_all_widgets)
from openslides.projector.forms import SelectWidgetsForm
from openslides.projector.models import ProjectorOverlay, ProjectorSlide from openslides.projector.models import ProjectorOverlay, ProjectorSlide
from openslides.projector.projector import SLIDE, Widget from openslides.projector.projector import SLIDE, Widget
from openslides.projector.signals import projector_overlays from openslides.projector.signals import projector_overlays
@ -61,26 +64,7 @@ class DashboardView(TemplateView, AjaxMixin):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(DashboardView, self).get_context_data(**kwargs) context = super(DashboardView, self).get_context_data(**kwargs)
widgets = SortedDict() context['widgets'] = get_all_widgets(self.request, session=True)
for app in settings.INSTALLED_APPS:
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:
if (widget.permission_required is None or
self.request.user.has_perm(widget.permission_required)):
widgets[widget.get_name()] = widget
print widget, widget.permission_required
context['widgets'] = widgets
return context return context
@ -178,6 +162,48 @@ class ActivateView(RedirectView):
config['bigger'] = 100 config['bigger'] = 100
class SelectWidgetsView(TemplateView):
"""
Show a Form to Select the widgets.
"""
permission_required = 'projector.can_see_dashboard'
template_name = 'projector/select_widgets.html'
def get_context_data(self, **kwargs):
context = super(SelectWidgetsView, self). get_context_data(**kwargs)
widgets = get_all_widgets(self.request)
activated_widgets = self.request.session.get('widgets', {})
for name, widget in widgets.items():
initial = {'widget': activated_widgets.get(name, True)}
if self.request.method == 'POST':
widget.form = SelectWidgetsForm(self.request.POST, prefix=name,
initial=initial)
else:
widget.form = SelectWidgetsForm(prefix=name, initial=initial)
context['widgets'] = widgets
return context
@transaction.commit_manually
def post(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
activated_widgets = self.request.session.get('widgets', {})
transaction.commit()
for name, widget in context['widgets'].items():
if widget.form.is_valid():
activated_widgets[name] = widget.form.cleaned_data['widget']
else:
transaction.rollback()
messages.error(request, _('Errors in the form'))
break
else:
transaction.commit()
self.request.session['widgets'] = activated_widgets
return self.render_to_response(context)
class ProjectorEdit(RedirectView): class ProjectorEdit(RedirectView):
""" """
Scale or scroll the projector. Scale or scroll the projector.