OpenSlides/openslides/agenda/projector.py

127 lines
5.1 KiB
Python
Raw Normal View History

from ..core.config import config
from ..core.exceptions import ProjectorException
2016-10-05 18:25:50 +02:00
from ..core.models import Projector
from ..utils.collection import CollectionElement
from ..utils.projector import ProjectorElement
2015-06-24 23:36:36 +02:00
from .models import Item
class ItemListSlide(ProjectorElement):
"""
Slide definitions for Item model.
This is only for item list slides.
Set 'id' to None to get a list slide of all root items. Set 'id' to an
integer to get a list slide of the children of the metioned item.
Additionally set 'tree' to True to get also children of children.
2015-06-24 23:36:36 +02:00
"""
name = 'agenda/item-list'
def check_data(self):
pk = self.config_entry.get('id')
2015-09-08 14:14:11 +02:00
if pk is not None:
# Children slide.
if not Item.objects.filter(pk=pk).exists():
raise ProjectorException('Item does not exist.')
2015-06-24 23:36:36 +02:00
def get_requirements(self, config_entry):
yield from Item.objects.all()
2015-06-24 23:36:36 +02:00
class ListOfSpeakersSlide(ProjectorElement):
2015-06-24 23:36:36 +02:00
"""
Slide definitions for Item model.
This is only for list of speakers slide. You have to set 'id'.
2015-06-24 23:36:36 +02:00
"""
name = 'agenda/list-of-speakers'
2015-06-24 23:36:36 +02:00
def check_data(self):
if not Item.objects.filter(pk=self.config_entry.get('id')).exists():
raise ProjectorException('Item does not exist.')
2015-06-24 23:36:36 +02:00
def get_requirements(self, config_entry):
pk = config_entry.get('id')
if pk is not None:
# List of speakers slide.
2015-06-24 23:36:36 +02:00
try:
item = Item.objects.get(pk=pk)
except Item.DoesNotExist:
# Item does not exist. Just do nothing.
pass
else:
yield item
for speaker in item.speakers.filter(end_time=None):
# Yield current speaker and next speakers
yield speaker.user
query = (item.speakers.exclude(end_time=None)
.order_by('-end_time')[:config['agenda_show_last_speakers']])
for speaker in query:
# Yield last speakers
yield speaker.user
def get_collection_elements_required_for_this(self, collection_element, config_entry):
2016-10-01 01:30:55 +02:00
output = super().get_collection_elements_required_for_this(collection_element, config_entry)
# Full update if item changes because then we may have new
# candidates and therefor need new users.
if collection_element.collection_string == Item.get_collection_string() and collection_element.id == config_entry.get('id'):
output.extend(self.get_requirements_as_collection_elements(config_entry))
return output
2016-09-12 11:05:34 +02:00
2016-10-05 18:25:50 +02:00
def update_data(self):
return {'agenda_item_id': self.config_entry.get('id')}
2016-09-12 11:05:34 +02:00
class CurrentListOfSpeakersSlide(ProjectorElement):
2016-09-12 11:05:34 +02:00
"""
Slide for the current list of speakers.
2016-10-05 18:25:50 +02:00
"""
name = 'agenda/current-list-of-speakers'
2016-10-05 18:25:50 +02:00
def get_requirements(self, config_entry):
# The query mechanism on client needs the referenced projector.
reference_projector = Projector.objects.get(
pk=config['projector_currentListOfSpeakers_reference'])
yield reference_projector
items = self.get_agenda_items(reference_projector)
2016-10-05 18:25:50 +02:00
for item in items:
yield item
for speaker in item.speakers.filter(end_time=None):
yield speaker.user
query = (item.speakers.exclude(end_time=None)
.order_by('-end_time')[:config['agenda_show_last_speakers']])
for speaker in query:
# Yield last speakers
yield speaker.user
def get_agenda_items(self, projector):
2016-10-05 18:25:50 +02:00
for element in projector.elements.values():
agenda_item_id = element.get('agenda_item_id')
if agenda_item_id is not None:
yield Item.objects.get(pk=agenda_item_id)
def get_collection_elements_required_for_this(self, collection_element, config_entry):
output = super().get_collection_elements_required_for_this(collection_element, config_entry)
# Full update if agenda_item or referenced projector changes because
# then we may have new candidates and therefor need new users.
reference_projector = Projector.objects.get(
pk=config['projector_currentListOfSpeakers_reference'])
is_reference_projector = collection_element == CollectionElement.from_values(
reference_projector.get_collection_string(),
reference_projector.pk)
is_config = (
collection_element.collection_string == 'core/config' and
collection_element.information.get('changed_config') == 'projector_currentListOfSpeakers_reference')
if is_reference_projector or is_config:
output.extend(self.get_requirements_as_collection_elements(config_entry))
else:
items = self.get_agenda_items(reference_projector)
for item in items:
if collection_element == CollectionElement.from_values(item.get_collection_string(), item.pk):
output.extend(self.get_requirements_as_collection_elements(config_entry))
break
2016-10-05 18:25:50 +02:00
return output