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-12-19 10:40:55 +01:00
|
|
|
from .models import Motion, MotionBlock, MotionChangeRecommendation
|
2015-06-24 22:11:54 +02:00
|
|
|
|
|
|
|
|
2015-06-25 20:36:46 +02:00
|
|
|
class MotionSlide(ProjectorElement):
|
2015-06-24 22:11:54 +02:00
|
|
|
"""
|
2015-06-25 20:36:46 +02:00
|
|
|
Slide definitions for Motion model.
|
2015-06-24 22:11:54 +02:00
|
|
|
"""
|
|
|
|
name = 'motions/motion'
|
|
|
|
|
2016-02-27 20:25:06 +01:00
|
|
|
def check_data(self):
|
2016-09-17 22:26:23 +02:00
|
|
|
if not Motion.objects.filter(pk=self.config_entry.get('id')).exists():
|
|
|
|
raise ProjectorException('Motion does not exist.')
|
2015-06-24 22:11:54 +02:00
|
|
|
|
|
|
|
def get_requirements(self, config_entry):
|
2016-09-17 22:26:23 +02:00
|
|
|
try:
|
|
|
|
motion = Motion.objects.get(pk=config_entry.get('id'))
|
|
|
|
except Motion.DoesNotExist:
|
|
|
|
# Motion 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 motion
|
|
|
|
yield motion.agenda_item
|
|
|
|
yield motion.state.workflow
|
|
|
|
yield from motion.submitters.all()
|
|
|
|
yield from motion.supporters.all()
|
2016-12-19 10:40:55 +01:00
|
|
|
yield from MotionChangeRecommendation.objects.filter(motion_version=motion.get_active_version().id)
|
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 motion changes because then we may have new
|
|
|
|
# submitters or supporters and therefor need new users.
|
|
|
|
#
|
|
|
|
# Add some logic here if we support live changing of workflows later.
|
|
|
|
#
|
2016-09-30 23:39:42 +02:00
|
|
|
if collection_element == CollectionElement.from_values(Motion.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:
|
|
|
|
motion = Motion.objects.get(pk=self.config_entry.get('id'))
|
|
|
|
except Motion.DoesNotExist:
|
|
|
|
# Motion does not exist, so just do nothing.
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
data = {'agenda_item_id': motion.agenda_item_id}
|
|
|
|
return data
|
2016-10-01 20:42:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
class MotionBlockSlide(ProjectorElement):
|
|
|
|
"""
|
|
|
|
Slide definitions for a block of motions (MotionBlock model).
|
|
|
|
"""
|
|
|
|
name = 'motions/motion-block'
|
|
|
|
|
|
|
|
def check_data(self):
|
|
|
|
if not MotionBlock.objects.filter(pk=self.config_entry.get('id')).exists():
|
|
|
|
raise ProjectorException('MotionBlock does not exist.')
|
|
|
|
|
|
|
|
def get_requirements(self, config_entry):
|
|
|
|
try:
|
|
|
|
motion_block = MotionBlock.objects.get(pk=config_entry.get('id'))
|
|
|
|
except MotionBlock.DoesNotExist:
|
|
|
|
# MotionBlock does not exist. Just do nothing.
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
yield motion_block
|
|
|
|
yield motion_block.agenda_item
|
|
|
|
yield from motion_block.motion_set.all()
|
|
|
|
|
|
|
|
def get_collection_elements_required_for_this(self, collection_element, config_entry):
|
|
|
|
output = super().get_collection_elements_required_for_this(collection_element, config_entry)
|
2017-02-17 13:21:11 +01:00
|
|
|
# Send all changed motions to the projector, because it may be appended
|
2016-10-01 20:42:44 +02:00
|
|
|
# or removed from the block.
|
|
|
|
if collection_element.collection_string == Motion.get_collection_string():
|
2017-02-17 13:21:11 +01:00
|
|
|
output.append(collection_element)
|
2016-10-01 20:42:44 +02:00
|
|
|
return output
|
|
|
|
|
|
|
|
def update_data(self):
|
|
|
|
data = None
|
|
|
|
try:
|
|
|
|
motion_block = MotionBlock.objects.get(pk=self.config_entry.get('id'))
|
|
|
|
except MotionBlock.DoesNotExist:
|
|
|
|
# MotionBlock does not exist, so just do nothing.
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
data = {'agenda_item_id': motion_block.agenda_item_id}
|
|
|
|
return data
|