parent
e92af391c3
commit
2a7a50a817
@ -3,7 +3,8 @@
|
|||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
|
|
||||||
from openslides.config.api import config
|
from openslides.config.api import config
|
||||||
from openslides.projector.api import get_projector_content, register_slide
|
from openslides.projector.api import (
|
||||||
|
get_projector_content, register_slide, SlideError)
|
||||||
|
|
||||||
from .models import Item
|
from .models import Item
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ def agenda_slide(**kwargs):
|
|||||||
try:
|
try:
|
||||||
item = Item.objects.get(pk=item_pk)
|
item = Item.objects.get(pk=item_pk)
|
||||||
except Item.DoesNotExist:
|
except Item.DoesNotExist:
|
||||||
item = None
|
raise SlideError
|
||||||
|
|
||||||
if slide_type == 'summary' or item is None:
|
if slide_type == 'summary' or item is None:
|
||||||
context = {}
|
context = {}
|
||||||
@ -38,7 +39,7 @@ def agenda_slide(**kwargs):
|
|||||||
items = item.get_children().filter(type__exact=Item.AGENDA_ITEM)
|
items = item.get_children().filter(type__exact=Item.AGENDA_ITEM)
|
||||||
context['title'] = item.get_title()
|
context['title'] = item.get_title()
|
||||||
context['items'] = items
|
context['items'] = items
|
||||||
return render_to_string('agenda/item_slide_summary.html', context)
|
slide = render_to_string('agenda/item_slide_summary.html', context)
|
||||||
|
|
||||||
elif slide_type == 'list_of_speakers':
|
elif slide_type == 'list_of_speakers':
|
||||||
list_of_speakers = item.get_list_of_speakers(
|
list_of_speakers = item.get_list_of_speakers(
|
||||||
@ -46,17 +47,18 @@ def agenda_slide(**kwargs):
|
|||||||
context = {'title': item.get_title(),
|
context = {'title': item.get_title(),
|
||||||
'item': item,
|
'item': item,
|
||||||
'list_of_speakers': list_of_speakers}
|
'list_of_speakers': list_of_speakers}
|
||||||
return render_to_string('agenda/item_slide_list_of_speaker.html', context)
|
slide = render_to_string('agenda/item_slide_list_of_speaker.html', context)
|
||||||
|
|
||||||
elif item.content_object:
|
elif item.content_object:
|
||||||
slide_dict = {
|
slide_dict = {
|
||||||
'callback': item.content_object.slide_callback_name,
|
'callback': item.content_object.slide_callback_name,
|
||||||
'pk': item.content_object.pk}
|
'pk': item.content_object.pk}
|
||||||
return get_projector_content(slide_dict)
|
slide = get_projector_content(slide_dict)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
context = {'item': item}
|
context = {'item': item}
|
||||||
return render_to_string('agenda/item_slide.html', context)
|
slide = render_to_string('agenda/item_slide.html', context)
|
||||||
|
return slide
|
||||||
|
|
||||||
|
|
||||||
register_slide('agenda', agenda_slide)
|
register_slide('agenda', agenda_slide)
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
|
|
||||||
from openslides.config.api import config
|
from openslides.config.api import config
|
||||||
from openslides.projector.api import register_slide
|
from openslides.projector.api import register_slide, SlideError
|
||||||
|
|
||||||
from .models import Mediafile
|
from .models import Mediafile
|
||||||
|
|
||||||
@ -24,8 +24,7 @@ def mediafile_presentation_as_slide(**kwargs):
|
|||||||
filetype__in=Mediafile.PRESENTABLE_FILE_TYPES,
|
filetype__in=Mediafile.PRESENTABLE_FILE_TYPES,
|
||||||
is_presentable=True)
|
is_presentable=True)
|
||||||
except Mediafile.DoesNotExist:
|
except Mediafile.DoesNotExist:
|
||||||
# TODO what doing, if a wrong pk is given?
|
raise SlideError
|
||||||
pdf = None
|
|
||||||
context = {'pdf': pdf, 'page_num': page_num,
|
context = {'pdf': pdf, 'page_num': page_num,
|
||||||
'fullscreen': config['pdf_fullscreen']}
|
'fullscreen': config['pdf_fullscreen']}
|
||||||
return render_to_string('mediafile/presentation_slide.html', context)
|
return render_to_string('mediafile/presentation_slide.html', context)
|
||||||
|
@ -10,6 +10,7 @@ from django.utils.importlib import import_module
|
|||||||
|
|
||||||
from openslides.config.api import config
|
from openslides.config.api import config
|
||||||
from openslides.utils.tornado_webserver import ProjectorSocketHandler
|
from openslides.utils.tornado_webserver import ProjectorSocketHandler
|
||||||
|
from openslides.utils.exceptions import OpenSlidesError
|
||||||
|
|
||||||
from .signals import projector_overlays
|
from .signals import projector_overlays
|
||||||
|
|
||||||
@ -20,6 +21,10 @@ callable object which returns the html code for a slide.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class SlideError(OpenSlidesError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def update_projector():
|
def update_projector():
|
||||||
"""
|
"""
|
||||||
Sends the data to the clients, who listen to the projector.
|
Sends the data to the clients, who listen to the projector.
|
||||||
@ -82,7 +87,7 @@ def get_projector_content(slide_dict=None):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
slide_content = slide_callback[callback](**slide_dict)
|
slide_content = slide_callback[callback](**slide_dict)
|
||||||
except KeyError:
|
except (KeyError, SlideError):
|
||||||
slide_content = default_slide()
|
slide_content = default_slide()
|
||||||
return slide_content
|
return slide_content
|
||||||
|
|
||||||
@ -158,8 +163,7 @@ def register_slide_model(SlideModel, template):
|
|||||||
try:
|
try:
|
||||||
slide = SlideModel.objects.get(pk=slide_pk)
|
slide = SlideModel.objects.get(pk=slide_pk)
|
||||||
except SlideModel.DoesNotExist:
|
except SlideModel.DoesNotExist:
|
||||||
slide = None
|
raise SlideError
|
||||||
context = {'slide': None}
|
|
||||||
else:
|
else:
|
||||||
context = slide.get_slide_context()
|
context = slide.get_slide_context()
|
||||||
|
|
||||||
|
@ -77,6 +77,10 @@ class ApiFunctions(TestCase):
|
|||||||
value = projector_api.get_projector_content()
|
value = projector_api.get_projector_content()
|
||||||
self.assertEqual(value, 'slide content')
|
self.assertEqual(value, 'slide content')
|
||||||
|
|
||||||
|
mock_slide.side_effect = projector_api.SlideError
|
||||||
|
projector_api.get_projector_content({'callback': 'mock_slide'})
|
||||||
|
self.assertTrue(mock_default_slide.called)
|
||||||
|
|
||||||
@patch('openslides.projector.api.render_to_string')
|
@patch('openslides.projector.api.render_to_string')
|
||||||
def test_default_slide(self, mock_render_to_string):
|
def test_default_slide(self, mock_render_to_string):
|
||||||
projector_api.default_slide()
|
projector_api.default_slide()
|
||||||
@ -159,8 +163,7 @@ class ApiFunctions(TestCase):
|
|||||||
|
|
||||||
# Test with non existing object
|
# Test with non existing object
|
||||||
mock_SlideModel.objects.get.side_effect = Exception
|
mock_SlideModel.objects.get.side_effect = Exception
|
||||||
used_args[1](pk=1)
|
self.assertRaises(projector_api.SlideError, used_args[1], pk=1)
|
||||||
mock_render_to_string.assert_called_with('some template', {'slide': None})
|
|
||||||
|
|
||||||
@patch('openslides.projector.api.update_projector_overlay')
|
@patch('openslides.projector.api.update_projector_overlay')
|
||||||
@patch('openslides.projector.api.update_projector')
|
@patch('openslides.projector.api.update_projector')
|
||||||
|
Loading…
Reference in New Issue
Block a user