2015-06-24 22:11:54 +02:00
|
|
|
from openslides.core.exceptions import ProjectorException
|
|
|
|
from openslides.core.views import TagViewSet
|
|
|
|
from openslides.utils.projector import ProjectorElement, ProjectorRequirement
|
|
|
|
|
2016-02-09 17:33:07 +01:00
|
|
|
from .models import Assignment, AssignmentPoll
|
2015-06-24 22:11:54 +02:00
|
|
|
from .views import AssignmentViewSet
|
|
|
|
|
|
|
|
|
2015-06-25 20:36:46 +02:00
|
|
|
class AssignmentSlide(ProjectorElement):
|
2015-06-24 22:11:54 +02:00
|
|
|
"""
|
2015-06-25 20:36:46 +02:00
|
|
|
Slide definitions for Assignment model.
|
|
|
|
|
|
|
|
Set 'id' to get a detail slide. Omit it to get a list slide.
|
2015-06-24 22:11:54 +02:00
|
|
|
"""
|
|
|
|
name = 'assignments/assignment'
|
|
|
|
|
2016-02-27 20:25:06 +01:00
|
|
|
def check_data(self):
|
2015-06-24 22:11:54 +02:00
|
|
|
pk = self.config_entry.get('id')
|
2015-09-08 14:14:11 +02:00
|
|
|
if pk is not None:
|
2015-06-25 20:36:46 +02:00
|
|
|
# Detail slide.
|
|
|
|
if not Assignment.objects.filter(pk=pk).exists():
|
2015-11-21 00:00:31 +01:00
|
|
|
raise ProjectorException('Election does not exist.')
|
2016-02-09 17:33:07 +01:00
|
|
|
poll_id = self.config_entry.get('poll')
|
|
|
|
if poll_id is not None:
|
|
|
|
# Poll slide.
|
|
|
|
if not AssignmentPoll.objects.filter(pk=poll_id).exists():
|
|
|
|
raise ProjectorException('Poll does not exist.')
|
2015-06-24 22:11:54 +02:00
|
|
|
|
|
|
|
def get_requirements(self, config_entry):
|
|
|
|
pk = config_entry.get('id')
|
2015-06-25 20:36:46 +02:00
|
|
|
if pk is None:
|
|
|
|
# List slide. Related objects like users and tags are not unlocked.
|
|
|
|
yield ProjectorRequirement(
|
|
|
|
view_class=AssignmentViewSet,
|
|
|
|
view_action='list')
|
|
|
|
else:
|
|
|
|
# Detail slide.
|
2015-06-24 22:11:54 +02:00
|
|
|
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))
|
2015-11-25 21:31:08 +01:00
|
|
|
for poll in assignment.polls.all().prefetch_related('options'):
|
|
|
|
for option in poll.options.all():
|
2015-06-24 22:11:54 +02:00
|
|
|
yield ProjectorRequirement(
|
|
|
|
view_class=option.candidate.get_view_class(),
|
|
|
|
view_action='retrieve',
|
2015-06-24 23:36:36 +02:00
|
|
|
pk=str(option.candidate_id))
|
2015-06-24 22:11:54 +02:00
|
|
|
for tag in assignment.tags.all():
|
|
|
|
yield ProjectorRequirement(
|
|
|
|
view_class=TagViewSet,
|
|
|
|
view_action='retrieve',
|
|
|
|
pk=str(tag.pk))
|