Added motion and assignment detail slide.

This commit is contained in:
Norman Jäckel 2015-06-24 22:11:54 +02:00
parent 6187ec450d
commit 6b5ce5ae2f
6 changed files with 138 additions and 8 deletions

View File

@ -6,6 +6,10 @@ class AssignmentAppConfig(AppConfig):
verbose_name = 'OpenSlides Assignments' verbose_name = 'OpenSlides Assignments'
def ready(self): def ready(self):
# Load projector elements.
# Do this by just importing all from these files.
from . import projector # noqa
# Import all required stuff. # Import all required stuff.
from openslides.config.signals import config_signal from openslides.config.signals import config_signal
from openslides.utils.rest_api import router from openslides.utils.rest_api import router

View File

@ -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))

View File

@ -7,6 +7,10 @@ class MotionAppConfig(AppConfig):
verbose_name = 'OpenSlides Motion' verbose_name = 'OpenSlides Motion'
def ready(self): def ready(self):
# Load projector elements.
# Do this by just importing all from these files.
from . import projector # noqa
# Import all required stuff. # Import all required stuff.
from openslides.config.signals import config_signal from openslides.config.signals import config_signal
from openslides.utils.rest_api import router from openslides.utils.rest_api import router

View File

@ -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))

View File

@ -202,3 +202,11 @@ class User(RESTModelMixin, SlideMixin, PermissionsMixin, AbstractBaseUser):
if password is None: if password is None:
password = self.default_password password = self.default_password
self.set_password(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

View File

@ -22,13 +22,18 @@ class UserSlide(ProjectorElement):
def get_requirements(self, config_entry): def get_requirements(self, config_entry):
pk = config_entry.get('id') pk = config_entry.get('id')
if pk is not None: if pk is not None:
yield ProjectorRequirement( try:
view_class=UserViewSet, user = User.objects.get(pk=pk)
view_action='retrieve', except User.DoesNotExist:
pk=str(pk)) # User does not exist. Just do nothing.
pass
for group in User.objects.get(pk=pk).groups.all(): else:
yield ProjectorRequirement( yield ProjectorRequirement(
view_class=GroupViewSet, view_class=UserViewSet,
view_action='retrieve', 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))