From 3ec55daaf93588155e7a3f4cdf7dfa220a0a8e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Sun, 11 Jan 2015 18:43:05 +0100 Subject: [PATCH] Fixed bug. Projector was not updated when an object was deleted. Fixex #1394. --- openslides/projector/models.py | 9 +++++++-- tests/projector/models.py | 11 +++++++++++ tests/projector/test_models.py | 17 +++++++++++++++++ tests/settings.py | 1 + 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 tests/projector/models.py create mode 100644 tests/projector/test_models.py diff --git a/openslides/projector/models.py b/openslides/projector/models.py index a9de923c8..7eca7acea 100644 --- a/openslides/projector/models.py +++ b/openslides/projector/models.py @@ -61,11 +61,16 @@ class SlideMixin(object): def delete(self, *args, **kwargs): """ - Updates the projector, if the object is on the projector and is deleted. + Updates the projector if the object is on the projector and is deleted. """ from openslides.projector.api import update_projector + # Checking active slide has to be done before calling super().delete() + # because super().delete() deletes the object and than we have no + # access to the former existing primary key any more. But updating + # projector has to be done after deleting the object of course. + update_required = self.is_active_slide() value = super(SlideMixin, self).delete(*args, **kwargs) - if self.is_active_slide(): + if update_required: update_projector() return value diff --git a/tests/projector/models.py b/tests/projector/models.py new file mode 100644 index 000000000..6bfd3576d --- /dev/null +++ b/tests/projector/models.py @@ -0,0 +1,11 @@ +from django.db import models + +from openslides.projector.models import SlideMixin + + +class DummySlideMixinModel(SlideMixin, models.Model): + """ + Dummy model to test the SlideMixin. + """ + slide_callback_name = 'dummy_slides_mixin_model_geu3AiceeG9eo6ohChoD' + title = models.CharField(max_length=255) diff --git a/tests/projector/test_models.py b/tests/projector/test_models.py new file mode 100644 index 000000000..3a0618517 --- /dev/null +++ b/tests/projector/test_models.py @@ -0,0 +1,17 @@ +from mock import patch + +from openslides.config.api import config +from openslides.utils.test import TestCase + +from .models import DummySlideMixinModel + + +class TestSlideMixin(TestCase): + @patch('openslides.projector.api.update_projector') + def test_delete(self, mock_update_projector): + obj = DummySlideMixinModel.objects.create(title='title_cah4AhZai3einoh9koo3') + config['projector_active_slide'] = { + 'callback': 'dummy_slides_mixin_model_geu3AiceeG9eo6ohChoD', + 'pk': '1'} + obj.delete() + mock_update_projector.assert_called_with() diff --git a/tests/settings.py b/tests/settings.py index d913376e7..d7a181ead 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -29,6 +29,7 @@ DATABASES = { # Add OpenSlides plugins to this list INSTALLED_PLUGINS = ( 'tests.person_api', + 'tests.projector', 'tests.utils', )