2017-08-30 00:07:54 +02:00
|
|
|
from typing import Generator, Type
|
|
|
|
|
2016-09-17 22:26:23 +02:00
|
|
|
from ..core.exceptions import ProjectorException
|
|
|
|
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
|
|
|
"""
|
2019-01-06 16:22:33 +01:00
|
|
|
|
|
|
|
name = "assignments/assignment"
|
2015-06-24 22:11:54 +02:00
|
|
|
|
2016-02-27 20:25:06 +01:00
|
|
|
def check_data(self):
|
2019-01-06 16:22:33 +01:00
|
|
|
if not Assignment.objects.filter(pk=self.config_entry.get("id")).exists():
|
|
|
|
raise ProjectorException("Election does not exist.")
|
|
|
|
poll_id = self.config_entry.get("poll")
|
2016-09-23 22:09:06 +02:00
|
|
|
if poll_id:
|
|
|
|
# Poll slide.
|
|
|
|
try:
|
|
|
|
poll = AssignmentPoll.objects.get(pk=poll_id)
|
|
|
|
except AssignmentPoll.DoesNotExist:
|
2019-01-06 16:22:33 +01:00
|
|
|
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
|
|
|
|
2016-10-05 18:25:50 +02:00
|
|
|
def update_data(self):
|
|
|
|
data = None
|
|
|
|
try:
|
2019-01-06 16:22:33 +01:00
|
|
|
assignment = Assignment.objects.get(pk=self.config_entry.get("id"))
|
2016-10-05 18:25:50 +02:00
|
|
|
except Assignment.DoesNotExist:
|
|
|
|
# Assignment does not exist, so just do nothing.
|
|
|
|
pass
|
|
|
|
else:
|
2019-01-06 16:22:33 +01:00
|
|
|
data = {"agenda_item_id": assignment.agenda_item_id}
|
2016-10-05 18:25:50 +02:00
|
|
|
return data
|
2017-08-30 00:07:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
def get_projector_elements() -> Generator[Type[ProjectorElement], None, None]:
|
|
|
|
yield AssignmentSlide
|