diff --git a/openslides/agenda/models.py b/openslides/agenda/models.py index f290714e5..09c62c53f 100644 --- a/openslides/agenda/models.py +++ b/openslides/agenda/models.py @@ -22,13 +22,13 @@ from mptt.models import MPTTModel, TreeForeignKey from system import config -from projector.models import Slide +from projector.models import SlideMixin from projector.api import register_slidemodel from agenda.api import is_summary -class Item(MPTTModel, Slide): +class Item(MPTTModel, SlideMixin): """ An Agenda Item @@ -55,7 +55,7 @@ class Item(MPTTModel, Slide): } if is_summary(): - data['items'] = self.children.filter(hidden=False) + data['items'] = self.children.all() data['template'] = 'projector/AgendaSummary.html' return data @@ -63,7 +63,7 @@ class Item(MPTTModel, Slide): """ Appoint this item as the active one. """ - Slide.set_active(self) + super(Item, self).set_active() if summary: config["agenda_summary"] = True else: @@ -135,7 +135,7 @@ class Item(MPTTModel, Slide): register_slidemodel(Item) -# TODO: put this in anouther file +# TODO: put this in another file from projector.api import register_slidefunc from agenda.slides import agenda_show diff --git a/openslides/agenda/views.py b/openslides/agenda/views.py index 032d272aa..f5e795f26 100644 --- a/openslides/agenda/views.py +++ b/openslides/agenda/views.py @@ -36,7 +36,7 @@ class View(TemplateView): def get_context_data(self, **kwargs): context = super(View, self).get_context_data(**kwargs) context.update({ - 'item': Item.objects.get(pk=kwargs['item_id']), + 'item': Item.objects.get(pk=kwargs['pk']), 'ajax': 'off', }) return context diff --git a/openslides/application/models.py b/openslides/application/models.py index 728ae393d..82caa16a5 100644 --- a/openslides/application/models.py +++ b/openslides/application/models.py @@ -18,7 +18,7 @@ from django.contrib.auth.models import User from django.utils.translation import ugettext as _ from projector.api import register_slidemodel -from projector.models import Slide +from projector.models import SlideMixin from participant.models import Profile from system import config @@ -27,7 +27,7 @@ from poll import ChoicePoll from poll.models import BaseOption, BasePoll, CountVotesCast, CountInvalid, Vote -class Application(models.Model, Slide): +class Application(models.Model, SlideMixin): prefix = "application" STATUS = ( ('pub', _('Published')), diff --git a/openslides/assignment/models.py b/openslides/assignment/models.py index 519d1395a..3066a1828 100644 --- a/openslides/assignment/models.py +++ b/openslides/assignment/models.py @@ -15,12 +15,12 @@ from django.utils.translation import ugettext as _ from participant.models import Profile -from projector.models import Slide +from projector.models import SlideMixin from projector.api import register_slidemodel from poll.models import BasePoll, CountInvalid, CountVotesCast, BaseOption -class Assignment(models.Model, Slide): +class Assignment(models.Model, SlideMixin): prefix = 'assignment' STATUS = ( ('sea', _('Searching for candidates')), diff --git a/openslides/poll/models.py b/openslides/poll/models.py index c97b71305..e8c7878cd 100644 --- a/openslides/poll/models.py +++ b/openslides/poll/models.py @@ -14,7 +14,7 @@ from django.db import models from django.utils.translation import ugettext as _ from projector.api import register_slidemodel -from projector.models import Slide +from projector.models import SlideMixin class BaseOption(models.Model): @@ -67,7 +67,7 @@ class CountInvalid(models.Model): abstract = True -class BasePoll(models.Model, Slide): +class BasePoll(models.Model, SlideMixin): #TODO: It would be nice if this class wouldn't be a subclass from models.Model. But it is needet aslong # BaseOption has a foreignKey on BasePoll prefix = 'BasePoll' diff --git a/openslides/projector/api.py b/openslides/projector/api.py index 54c0e23e9..51004d1c1 100644 --- a/openslides/projector/api.py +++ b/openslides/projector/api.py @@ -1,16 +1,16 @@ from system import config -from projector.models import SLIDE +from projector.models import SLIDE, Slide def get_slide_from_sid(sid): - data = sid.split() + data = sid.split('-') if len(data) == 2: model = data[0] id = data[1] - return SLIDE[model].objects.get(pk=id).slide() + return SLIDE[model].model.objects.get(pk=id).slide() if len(data) == 1: try: - return SLIDE[data[0]]() + return SLIDE[data[0]].func() except KeyError: return None return None @@ -35,11 +35,25 @@ def set_active_slide(sid): config["presentation"] = sid -def register_slidemodel(model): - SLIDE[model.prefix] = model +def register_slidemodel(model, category=None): + #TODO: Warn if there already is a slide with this prefix + SLIDE[model.prefix] = Slide( + model_slide=True, + model=model, + category=category, + key=model.prefix, + ) -def register_slidefunc(name, func): - if ' ' in name: - raise NameError('There can be no space in name') - SLIDE[name] = func +def register_slidefunc(key, func, category=None): + #TODO: Warn if there already is a slide with this prefix + SLIDE[key] = Slide( + model_slide=False, + func=func, + category=category, + key=key, + ) + + +#def get_possible_slides(): + diff --git a/openslides/projector/models.py b/openslides/projector/models.py index 7cb80ae58..b705b0473 100644 --- a/openslides/projector/models.py +++ b/openslides/projector/models.py @@ -4,7 +4,7 @@ from system import config SLIDE = {} -class Slide(object): +class SlideMixin(object): def slide(self): """ @@ -22,8 +22,8 @@ class Slide(object): Return the sid from this Slide """ for key, value in SLIDE.iteritems(): - if type(self) == value: - return "%s %d" % (key, self.id) + if type(self) == value.model: + return "%s-%d" % (key, self.id) return None @property @@ -38,4 +38,23 @@ class Slide(object): """ Appoint this item as the active one. """ - config["presentation"] = "%s %d" % (self.prefix, self.id) + config["presentation"] = "%s-%d" % (self.prefix, self.id) + + +class Slide(object): + def __init__(self, model_slide=False, func=None, model=None, category=None, key=None): + """ + model_slide: Boolean if the value is a Model. + func: The function to call. Only if modelslide is False. + model: The model. Only if modelslide is True. + category: The category to show this Slide. + key: the key in the slide object to find myself. + """ + self.model_slide = model_slide + self.func = func + self.model = model + self.category = category + self.key = key + + def get_items(self): + return self.model.objects.all() diff --git a/openslides/projector/urls.py b/openslides/projector/urls.py index 4ee2cf939..7bcd28505 100644 --- a/openslides/projector/urls.py +++ b/openslides/projector/urls.py @@ -12,10 +12,22 @@ from django.conf.urls.defaults import * +from projector.views import SettingView, ActivateView + urlpatterns = patterns('projector.views', url(r'^$', 'active_slide', name='projector_show'), + url(r'^settings$', + SettingView.as_view(), + name='projector_settings', + ), + + url(r'^activate/(?P[^/]*)/$', + ActivateView.as_view(), + name='projector_activate_slide', + ), + url(r'^bigger/$', 'projector_edit', {'direction': 'bigger'}, name='projector_bigger'), diff --git a/openslides/projector/views.py b/openslides/projector/views.py index 9c1a44331..44eb2a39f 100644 --- a/openslides/projector/views.py +++ b/openslides/projector/views.py @@ -18,13 +18,38 @@ from django.contrib import messages from django.utils.translation import ugettext as _ +from utils.views import TemplateView, RedirectView from utils.utils import template, permission_required, \ del_confirm_form, ajax_request from utils.template import render_block_to_string from system import config -from projector.api import get_active_slide +from projector.api import get_active_slide, set_active_slide +from projector.models import SLIDE + + +class SettingView(TemplateView): + template_name = 'projector/settings.html' + + def get_context_data(self, **kwargs): + context = super(SettingView, self).get_context_data(**kwargs) + context.update({ + 'slides': SLIDE.values(), + }) + return context + + +class ActivateView(RedirectView): + url = 'projector_settings' + allow_ajax = True + + def pre_redirect(self, request, *args, **kwargs): + set_active_slide(kwargs['sid']) + + def get_ajax_context(self, **kwargs): + context = super(ActivateView, self).get_ajax_context() + return context @permission_required('agenda.can_see_projector') @@ -35,6 +60,9 @@ def active_slide(request): try: data = get_active_slide() except AttributeError: #TODO: It has to be an Slide.DoesNotExist + data = None + + if data is None: data = { 'title': config['event_name'], 'template': 'projector/default.html', diff --git a/openslides/templates/base.html b/openslides/templates/base.html index 08e2fc969..9c0372d6b 100644 --- a/openslides/templates/base.html +++ b/openslides/templates/base.html @@ -22,7 +22,7 @@