From 6da0d41e50fdc758969f4f0ac5f697871d08e91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Wed, 24 Jun 2015 23:36:36 +0200 Subject: [PATCH] Added agenda slides. --- openslides/agenda/apps.py | 4 ++ openslides/agenda/projector.py | 60 +++++++++++++++++++++++++++++ openslides/assignments/projector.py | 2 +- 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 openslides/agenda/projector.py diff --git a/openslides/agenda/apps.py b/openslides/agenda/apps.py index 629075e07..8b6efe4fa 100644 --- a/openslides/agenda/apps.py +++ b/openslides/agenda/apps.py @@ -6,6 +6,10 @@ class AgendaAppConfig(AppConfig): verbose_name = 'OpenSlides Agenda' def ready(self): + # Load projector elements. + # Do this by just importing all from these files. + from . import projector # noqa + # Import all required stuff. from django.db.models.signals import pre_delete from openslides.config.signals import config_signal diff --git a/openslides/agenda/projector.py b/openslides/agenda/projector.py new file mode 100644 index 000000000..7e39a1687 --- /dev/null +++ b/openslides/agenda/projector.py @@ -0,0 +1,60 @@ +from django.utils.translation import ugettext as _ + +from openslides.core.exceptions import ProjectorException +from openslides.core.views import TagViewSet +from openslides.utils.projector import ProjectorElement, ProjectorRequirement + +from .models import Item +from .views import ItemViewSet + + +class ItemListSlide(ProjectorElement): + """ + Slide definitions for the agenda. + """ + name = 'agenda/agenda' + + def get_requirements(self, config_entry): + yield ProjectorRequirement( + view_class=ItemViewSet, + view_action='list') + + +class ItemDetailSlide(ProjectorElement): + """ + Slide definitions for Item model. + + To activate this slide as list of speakers slide, set 'list_of_speakers' + true. + """ + name = 'agenda/item' + + def get_context(self): + pk = self.config_entry.get('id') + if not Item.objects.filter(pk=pk).exists(): + raise ProjectorException(_('Item does not exist.')) + return {'id': pk, 'list_of_speakers': self.config_entry.get('list_of_speakers', False)} + + def get_requirements(self, config_entry): + pk = config_entry.get('id') + if pk is not None: + try: + item = Item.objects.get(pk=pk) + except Item.DoesNotExist: + # Item does not exist. Just do nothing. + pass + else: + yield ProjectorRequirement( + view_class=ItemViewSet, + view_action='retrieve', + pk=str(item.pk)) + for speaker in item.speaker_set.all(): + yield ProjectorRequirement( + view_class=speaker.user.get_view_class(), + view_action='retrieve', + pk=str(speaker.user_id)) + for tag in item.tags.all(): + yield ProjectorRequirement( + view_class=TagViewSet, + view_action='retrieve', + pk=str(tag.pk)) diff --git a/openslides/assignments/projector.py b/openslides/assignments/projector.py index 8cf2866bb..4035c7975 100644 --- a/openslides/assignments/projector.py +++ b/openslides/assignments/projector.py @@ -43,7 +43,7 @@ class AssignmentDetailSlide(ProjectorElement): yield ProjectorRequirement( view_class=option.candidate.get_view_class(), view_action='retrieve', - pk=str(option.candidate.pk)) + pk=str(option.candidate_id)) for tag in assignment.tags.all(): yield ProjectorRequirement( view_class=TagViewSet,