Fixed bug. Projector was not updated when an object was deleted. Fixex #1394.

This commit is contained in:
Norman Jäckel 2015-01-11 18:43:05 +01:00
parent adefb49457
commit 3ec55daaf9
4 changed files with 36 additions and 2 deletions

View File

@ -61,11 +61,16 @@ class SlideMixin(object):
def delete(self, *args, **kwargs): 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 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) value = super(SlideMixin, self).delete(*args, **kwargs)
if self.is_active_slide(): if update_required:
update_projector() update_projector()
return value return value

11
tests/projector/models.py Normal file
View File

@ -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)

View File

@ -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()

View File

@ -29,6 +29,7 @@ DATABASES = {
# Add OpenSlides plugins to this list # Add OpenSlides plugins to this list
INSTALLED_PLUGINS = ( INSTALLED_PLUGINS = (
'tests.person_api', 'tests.person_api',
'tests.projector',
'tests.utils', 'tests.utils',
) )