Merge pull request #1568 from normanjaeckel/Slides
Added motion and assignment detail slide.
This commit is contained in:
commit
fe16afa1a7
@ -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
|
||||
|
51
openslides/assignments/projector.py
Normal file
51
openslides/assignments/projector.py
Normal 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))
|
@ -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
|
||||
|
58
openslides/motions/projector.py
Normal file
58
openslides/motions/projector.py
Normal 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))
|
@ -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
|
||||
|
@ -22,12 +22,17 @@ class UserSlide(ProjectorElement):
|
||||
def get_requirements(self, config_entry):
|
||||
pk = config_entry.get('id')
|
||||
if pk is not None:
|
||||
try:
|
||||
user = User.objects.get(pk=pk)
|
||||
except User.DoesNotExist:
|
||||
# User does not exist. Just do nothing.
|
||||
pass
|
||||
else:
|
||||
yield ProjectorRequirement(
|
||||
view_class=UserViewSet,
|
||||
view_action='retrieve',
|
||||
pk=str(pk))
|
||||
|
||||
for group in User.objects.get(pk=pk).groups.all():
|
||||
pk=str(user.pk))
|
||||
for group in user.groups.all():
|
||||
yield ProjectorRequirement(
|
||||
view_class=GroupViewSet,
|
||||
view_action='retrieve',
|
||||
|
Loading…
Reference in New Issue
Block a user