From 6b5ce5ae2f4f4cafadca8d9ce8c0d23b5a54bd04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Wed, 24 Jun 2015 22:11:54 +0200 Subject: [PATCH] Added motion and assignment detail slide. --- openslides/assignments/apps.py | 4 ++ openslides/assignments/projector.py | 51 +++++++++++++++++++++++++ openslides/motions/apps.py | 4 ++ openslides/motions/projector.py | 58 +++++++++++++++++++++++++++++ openslides/users/models.py | 8 ++++ openslides/users/projector.py | 21 +++++++---- 6 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 openslides/assignments/projector.py create mode 100644 openslides/motions/projector.py diff --git a/openslides/assignments/apps.py b/openslides/assignments/apps.py index 0aa89656c..2fb5d888b 100644 --- a/openslides/assignments/apps.py +++ b/openslides/assignments/apps.py @@ -6,6 +6,10 @@ class AssignmentAppConfig(AppConfig): verbose_name = 'OpenSlides Assignments' def ready(self): + # Load projector elements. + # Do this by just importing all from these files. + from . import projector # noqa + # Import all required stuff. from openslides.config.signals import config_signal from openslides.utils.rest_api import router diff --git a/openslides/assignments/projector.py b/openslides/assignments/projector.py new file mode 100644 index 000000000..8cf2866bb --- /dev/null +++ b/openslides/assignments/projector.py @@ -0,0 +1,51 @@ +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 Assignment +from .views import AssignmentViewSet + + +class AssignmentDetailSlide(ProjectorElement): + """ + Slide definitions for assignment model. + """ + name = 'assignments/assignment' + + def get_context(self): + pk = self.config_entry.get('id') + if not Assignment.objects.filter(pk=pk).exists(): + raise ProjectorException(_('Assignment does not exist.')) + return {'id': pk} + + def get_requirements(self, config_entry): + pk = config_entry.get('id') + if pk is not None: + try: + assignment = Assignment.objects.get(pk=pk) + except Assignment.DoesNotExist: + # Assignment does not exist. Just do nothing. + pass + else: + yield ProjectorRequirement( + view_class=AssignmentViewSet, + view_action='retrieve', + pk=str(assignment.pk)) + for user in assignment.related_users.all(): + yield ProjectorRequirement( + view_class=user.get_view_class(), + view_action='retrieve', + pk=str(user.pk)) + for poll in assignment.polls.all().prefetch_related('assignmentoption_set'): + for option in poll.assignmentoption_set.all(): + yield ProjectorRequirement( + view_class=option.candidate.get_view_class(), + view_action='retrieve', + pk=str(option.candidate.pk)) + for tag in assignment.tags.all(): + yield ProjectorRequirement( + view_class=TagViewSet, + view_action='retrieve', + pk=str(tag.pk)) diff --git a/openslides/motions/apps.py b/openslides/motions/apps.py index 3a84127e3..7771a8d14 100644 --- a/openslides/motions/apps.py +++ b/openslides/motions/apps.py @@ -7,6 +7,10 @@ class MotionAppConfig(AppConfig): verbose_name = 'OpenSlides Motion' def ready(self): + # Load projector elements. + # Do this by just importing all from these files. + from . import projector # noqa + # Import all required stuff. from openslides.config.signals import config_signal from openslides.utils.rest_api import router diff --git a/openslides/motions/projector.py b/openslides/motions/projector.py new file mode 100644 index 000000000..aaf7c81dd --- /dev/null +++ b/openslides/motions/projector.py @@ -0,0 +1,58 @@ +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 Motion +from .views import CategoryViewSet, MotionViewSet, WorkflowViewSet + + +class MotionDetailSlide(ProjectorElement): + """ + Slide definitions for motion model. + """ + name = 'motions/motion' + + def get_context(self): + pk = self.config_entry.get('id') + if not Motion.objects.filter(pk=pk).exists(): + raise ProjectorException(_('Motion does not exist.')) + return {'id': pk} + + def get_requirements(self, config_entry): + pk = config_entry.get('id') + if pk is not None: + try: + motion = Motion.objects.get(pk=pk) + except Motion.DoesNotExist: + # Motion does not exist. Just do nothing. + pass + else: + yield ProjectorRequirement( + view_class=MotionViewSet, + view_action='retrieve', + pk=str(motion.pk)) + yield ProjectorRequirement( + view_class=CategoryViewSet, + view_action='retrieve', + pk=str(motion.category.pk)) + yield ProjectorRequirement( + view_class=WorkflowViewSet, + view_action='retrieve', + pk=str(motion.workflow.pk)) + for submitter in motion.submitters.all(): + yield ProjectorRequirement( + view_class=submitter.get_view_class(), + view_action='retrieve', + pk=str(submitter.pk)) + for supporter in motion.supporters.all(): + yield ProjectorRequirement( + view_class=supporter.get_view_class(), + view_action='retrieve', + pk=str(supporter.pk)) + for tag in motion.tags.all(): + yield ProjectorRequirement( + view_class=TagViewSet, + view_action='retrieve', + pk=str(tag.pk)) diff --git a/openslides/users/models.py b/openslides/users/models.py index 5c68d8970..3d2f041a8 100644 --- a/openslides/users/models.py +++ b/openslides/users/models.py @@ -202,3 +202,11 @@ class User(RESTModelMixin, SlideMixin, PermissionsMixin, AbstractBaseUser): if password is None: password = self.default_password self.set_password(password) + + def get_view_class(self): + """ + Returns the main view class (viewset class) that should be unlocked + if the user (means its name) appears on a slide. + """ + from .views import UserViewSet + return UserViewSet diff --git a/openslides/users/projector.py b/openslides/users/projector.py index 8071e6084..5360dd469 100644 --- a/openslides/users/projector.py +++ b/openslides/users/projector.py @@ -22,13 +22,18 @@ class UserSlide(ProjectorElement): def get_requirements(self, config_entry): pk = config_entry.get('id') if pk is not None: - yield ProjectorRequirement( - view_class=UserViewSet, - view_action='retrieve', - pk=str(pk)) - - for group in User.objects.get(pk=pk).groups.all(): + try: + user = User.objects.get(pk=pk) + except User.DoesNotExist: + # User does not exist. Just do nothing. + pass + else: yield ProjectorRequirement( - view_class=GroupViewSet, + view_class=UserViewSet, view_action='retrieve', - pk=str(group.pk)) + pk=str(user.pk)) + for group in user.groups.all(): + yield ProjectorRequirement( + view_class=GroupViewSet, + view_action='retrieve', + pk=str(group.pk))