2016-09-17 22:26:23 +02:00
|
|
|
from ..core.exceptions import ProjectorException
|
2016-09-30 23:39:42 +02:00
|
|
|
from ..utils.collection import CollectionElement
|
2016-09-17 22:26:23 +02:00
|
|
|
from ..utils.projector import ProjectorElement
|
2016-09-23 22:09:06 +02:00
|
|
|
from .models import Assignment, AssignmentPoll
|
2015-06-24 22:11:54 +02:00
|
|
|
|
|
|
|
|
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.
|
2016-09-23 22:09:06 +02:00
|
|
|
|
|
|
|
You can send a poll id to get a poll slide.
|
2015-06-24 22:11:54 +02:00
|
|
|
"""
|
|
|
|
name = 'assignments/assignment'
|
|
|
|
|
2016-02-27 20:25:06 +01:00
|
|
|
def check_data(self):
|
2016-09-17 22:26:23 +02:00
|
|
|
if not Assignment.objects.filter(pk=self.config_entry.get('id')).exists():
|
|
|
|
raise ProjectorException('Election does not exist.')
|
2016-09-23 22:09:06 +02:00
|
|
|
poll_id = self.config_entry.get('poll')
|
|
|
|
if poll_id:
|
|
|
|
# Poll slide.
|
|
|
|
try:
|
|
|
|
poll = AssignmentPoll.objects.get(pk=poll_id)
|
|
|
|
except AssignmentPoll.DoesNotExist:
|
|
|
|
raise ProjectorException('Poll does not exist.')
|
|
|
|
if poll.assignment_id != self.config_entry.get('id'):
|
|
|
|
raise ProjectorException('Assignment id and poll do not belong together.')
|
2015-06-24 22:11:54 +02:00
|
|
|
|
|
|
|
def get_requirements(self, config_entry):
|
2016-09-17 22:26:23 +02:00
|
|
|
try:
|
|
|
|
assignment = Assignment.objects.get(pk=config_entry.get('id'))
|
|
|
|
except Assignment.DoesNotExist:
|
|
|
|
# Assignment does not exist. Just do nothing.
|
|
|
|
pass
|
2015-06-25 20:36:46 +02:00
|
|
|
else:
|
2016-09-17 22:26:23 +02:00
|
|
|
yield assignment
|
|
|
|
yield assignment.agenda_item
|
2016-09-23 22:09:06 +02:00
|
|
|
if not config_entry.get('poll'):
|
|
|
|
# Assignment detail slide. Yield user instances of current
|
|
|
|
# candidates (i. e. future poll participants) and elected
|
|
|
|
# persons (i. e. former poll participants).
|
|
|
|
for user in assignment.related_users.all():
|
|
|
|
yield user
|
|
|
|
else:
|
|
|
|
# Assignment poll slide. Yield user instances of the
|
|
|
|
# participants of all polls.
|
|
|
|
for poll in assignment.polls.all().prefetch_related('options'):
|
|
|
|
for option in poll.options.all():
|
|
|
|
yield option.candidate
|
2016-09-23 13:12:02 +02:00
|
|
|
|
2016-09-30 23:39:42 +02:00
|
|
|
def get_collection_elements_required_for_this(self, collection_element, config_entry):
|
|
|
|
output = super().get_collection_elements_required_for_this(collection_element, config_entry)
|
2016-09-23 13:12:02 +02:00
|
|
|
# Full update if assignment changes because then we may have new
|
|
|
|
# candidates and therefor need new users.
|
2016-09-30 23:39:42 +02:00
|
|
|
if collection_element == CollectionElement.from_values(Assignment.get_collection_string(), config_entry.get('id')):
|
|
|
|
output.extend(self.get_requirements_as_collection_elements(config_entry))
|
|
|
|
return output
|
2016-10-05 18:25:50 +02:00
|
|
|
|
|
|
|
def update_data(self):
|
|
|
|
data = None
|
|
|
|
try:
|
|
|
|
assignment = Assignment.objects.get(pk=self.config_entry.get('id'))
|
|
|
|
except Assignment.DoesNotExist:
|
|
|
|
# Assignment does not exist, so just do nothing.
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
data = {'agenda_item_id': assignment.agenda_item_id}
|
|
|
|
return data
|