diff --git a/openslides/agenda/slides.py b/openslides/agenda/slides.py index a0da4f60c..ce0c3219a 100644 --- a/openslides/agenda/slides.py +++ b/openslides/agenda/slides.py @@ -3,7 +3,8 @@ from django.template.loader import render_to_string 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 @@ -28,7 +29,7 @@ def agenda_slide(**kwargs): try: item = Item.objects.get(pk=item_pk) except Item.DoesNotExist: - item = None + raise SlideError if slide_type == 'summary' or item is None: context = {} @@ -38,7 +39,7 @@ def agenda_slide(**kwargs): items = item.get_children().filter(type__exact=Item.AGENDA_ITEM) context['title'] = item.get_title() 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': list_of_speakers = item.get_list_of_speakers( @@ -46,17 +47,18 @@ def agenda_slide(**kwargs): context = {'title': item.get_title(), 'item': item, '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: slide_dict = { 'callback': item.content_object.slide_callback_name, 'pk': item.content_object.pk} - return get_projector_content(slide_dict) + slide = get_projector_content(slide_dict) else: 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) diff --git a/openslides/mediafile/slides.py b/openslides/mediafile/slides.py index 61ce6c1c9..ba8f7ff51 100644 --- a/openslides/mediafile/slides.py +++ b/openslides/mediafile/slides.py @@ -4,7 +4,7 @@ from django.template.loader import render_to_string 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 @@ -24,8 +24,7 @@ def mediafile_presentation_as_slide(**kwargs): filetype__in=Mediafile.PRESENTABLE_FILE_TYPES, is_presentable=True) except Mediafile.DoesNotExist: - # TODO what doing, if a wrong pk is given? - pdf = None + raise SlideError context = {'pdf': pdf, 'page_num': page_num, 'fullscreen': config['pdf_fullscreen']} return render_to_string('mediafile/presentation_slide.html', context) diff --git a/openslides/projector/api.py b/openslides/projector/api.py index 2ab8ea176..f091815cc 100644 --- a/openslides/projector/api.py +++ b/openslides/projector/api.py @@ -10,6 +10,7 @@ from django.utils.importlib import import_module from openslides.config.api import config from openslides.utils.tornado_webserver import ProjectorSocketHandler +from openslides.utils.exceptions import OpenSlidesError 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(): """ Sends the data to the clients, who listen to the projector. @@ -82,7 +87,7 @@ def get_projector_content(slide_dict=None): try: slide_content = slide_callback[callback](**slide_dict) - except KeyError: + except (KeyError, SlideError): slide_content = default_slide() return slide_content @@ -158,8 +163,7 @@ def register_slide_model(SlideModel, template): try: slide = SlideModel.objects.get(pk=slide_pk) except SlideModel.DoesNotExist: - slide = None - context = {'slide': None} + raise SlideError else: context = slide.get_slide_context() diff --git a/tests/projector/test_api.py b/tests/projector/test_api.py index 75bc04236..253ee9501 100644 --- a/tests/projector/test_api.py +++ b/tests/projector/test_api.py @@ -77,6 +77,10 @@ class ApiFunctions(TestCase): value = projector_api.get_projector_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') def test_default_slide(self, mock_render_to_string): projector_api.default_slide() @@ -159,8 +163,7 @@ class ApiFunctions(TestCase): # Test with non existing object mock_SlideModel.objects.get.side_effect = Exception - used_args[1](pk=1) - mock_render_to_string.assert_called_with('some template', {'slide': None}) + self.assertRaises(projector_api.SlideError, used_args[1], pk=1) @patch('openslides.projector.api.update_projector_overlay') @patch('openslides.projector.api.update_projector')