diff --git a/openslides/agenda/models.py b/openslides/agenda/models.py index 3c68bb330..8d47b0434 100644 --- a/openslides/agenda/models.py +++ b/openslides/agenda/models.py @@ -155,4 +155,3 @@ def default_config(sender, key, **kwargs): return { 'agenda_countdown_time': 60, }.get(key) - diff --git a/openslides/agenda/templates/agenda/control_item.html b/openslides/agenda/templates/agenda/control_item.html deleted file mode 100644 index a638a3d0c..000000000 --- a/openslides/agenda/templates/agenda/control_item.html +++ /dev/null @@ -1,18 +0,0 @@ -{% load staticfiles %} -{% load i18n %} - - - diff --git a/openslides/agenda/templates/agenda/widget.html b/openslides/agenda/templates/agenda/widget.html new file mode 100644 index 000000000..23cf8a393 --- /dev/null +++ b/openslides/agenda/templates/agenda/widget.html @@ -0,0 +1,33 @@ +{% load staticfiles %} +{% load i18n %} +{% load tags %} + + +
+ + diff --git a/openslides/agenda/views.py b/openslides/agenda/views.py index 8f88dad1c..387352cd6 100644 --- a/openslides/agenda/views.py +++ b/openslides/agenda/views.py @@ -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(), + } + ), + ] diff --git a/openslides/application/views.py b/openslides/application/views.py index 94e32a1a2..a1cb499d1 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -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)] diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index 64c91125f..6d4e971d2 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -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 diff --git a/openslides/assignment/views.py b/openslides/assignment/views.py index 812b92ce4..7340340aa 100644 --- a/openslides/assignment/views.py +++ b/openslides/assignment/views.py @@ -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)] diff --git a/openslides/projector/api.py b/openslides/projector/api.py index b8d7557b1..295a4b370 100644 --- a/openslides/projector/api.py +++ b/openslides/projector/api.py @@ -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(), + } + ) diff --git a/openslides/projector/projector.py b/openslides/projector/projector.py index 1db43c82b..3274b069f 100644 --- a/openslides/projector/projector.py +++ b/openslides/projector/projector.py @@ -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' diff --git a/openslides/projector/templates/projector/control.html b/openslides/projector/templates/projector/control.html index 512efb59d..71bd22801 100644 --- a/openslides/projector/templates/projector/control.html +++ b/openslides/projector/templates/projector/control.html @@ -148,24 +148,15 @@
- {% for category, group in categories.items %} - {% if category != 'projector' %} -
- {% with category_big=category|capfirst %} -
{% trans category_big %}
- {% endwith %} -
- {% for slides in group %} - {% if slides.control_template %} - {% include slides.control_template %} - {% endif %} - {% if not forloop.last %} -
- {% endif %} - {% endfor %} + {% for name, widget in widgets.items %} + {% if name != 'projector' %} +
+
{% trans widget.get_title %}
+
+ {{ widget.html }} +
-
- {% endif %} + {% endif %} {% endfor %}
@@ -243,27 +234,13 @@
- {% for category, group in categories.items %} - {% if category == 'projector' %} + {% with widget=widgets.projector %}
{% trans "Custom slides" %}
- {% for slides in group %} - {% if slides.control_template %} - {% include slides.control_template %} - {% endif %} - {% if not forloop.last %} -
- {% endif %} - {% endfor %} - - - + {{ widget.html }}
- {% endif %} - {% endfor %} + {% endwith %} {% endblock %} diff --git a/openslides/projector/templates/projector/default_control_slidefunc.html b/openslides/projector/templates/projector/default_control_slidefunc.html deleted file mode 100644 index e99658583..000000000 --- a/openslides/projector/templates/projector/default_control_slidefunc.html +++ /dev/null @@ -1,13 +0,0 @@ -{% load staticfiles %} -{% load i18n %} - - - diff --git a/openslides/projector/templates/projector/default_control_slidemodel.html b/openslides/projector/templates/projector/model_widget.html similarity index 66% rename from openslides/projector/templates/projector/default_control_slidemodel.html rename to openslides/projector/templates/projector/model_widget.html index 915f98b09..f889fe37b 100644 --- a/openslides/projector/templates/projector/default_control_slidemodel.html +++ b/openslides/projector/templates/projector/model_widget.html @@ -1,14 +1,17 @@ {% load staticfiles %} {% load i18n %} +{% load tags %} diff --git a/openslides/projector/templates/projector/control_customslide.html b/openslides/projector/templates/projector/widget.html similarity index 53% rename from openslides/projector/templates/projector/control_customslide.html rename to openslides/projector/templates/projector/widget.html index 8b5c4bb74..67a21db1b 100644 --- a/openslides/projector/templates/projector/control_customslide.html +++ b/openslides/projector/templates/projector/widget.html @@ -1,19 +1,28 @@ {% load staticfiles %} {% load i18n %} +{% load tags %} +
+ + + + diff --git a/openslides/projector/views.py b/openslides/projector/views.py index 83609547b..bfc815c75 100644 --- a/openslides/projector/views.py +++ b/openslides/projector/views.py @@ -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(), + } + ), + ] diff --git a/openslides/utils/templatetags/tags.py b/openslides/utils/templatetags/tags.py index 1437f872e..d35f190b3 100644 --- a/openslides/utils/templatetags/tags.py +++ b/openslides/utils/templatetags/tags.py @@ -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) diff --git a/openslides/utils/utils.py b/openslides/utils/utils.py index 84a02e2e6..b0abc20b0 100644 --- a/openslides/utils/utils.py +++ b/openslides/utils/utils.py @@ -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