From 3419855a1ead8dce8475159aebd966331d16c1a1 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 17 May 2014 14:21:57 +0200 Subject: [PATCH] Fix link to list of speaker item on related items fix #1242 --- openslides/agenda/views.py | 20 +++++++++++++------- tests/agenda/test_list_of_speakers.py | 18 +++++++++++++++++- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/openslides/agenda/views.py b/openslides/agenda/views.py index c0db84ec9..5133755d0 100644 --- a/openslides/agenda/views.py +++ b/openslides/agenda/views.py @@ -575,14 +575,20 @@ class CurrentListOfSpeakersView(RedirectView): """ Returns the current Item, or None, if the current Slide is not an Agenda Item. """ - active_slide = get_active_slide() - if active_slide['callback'] == 'agenda': - try: - return Item.objects.get(pk=active_slide.get('pk', None)) - except Item.DoesNotExist: - return None + slide = get_active_object() + if slide is None or isinstance(slide, Item): + # No Slide or an agenda item is active + item = slide else: - return None + # A related Item is active + try: + item = Item.objects.filter( + content_type=ContentType.objects.get_for_model(slide), + object_id=slide.pk)[0] + except IndexError: + item = None + + return item def get_redirect_url(self): """ diff --git a/tests/agenda/test_list_of_speakers.py b/tests/agenda/test_list_of_speakers.py index 84a3bc47f..b9dac9960 100644 --- a/tests/agenda/test_list_of_speakers.py +++ b/tests/agenda/test_list_of_speakers.py @@ -8,10 +8,12 @@ from openslides.agenda.models import Item, Speaker from openslides.agenda.signals import agenda_list_of_speakers from openslides.config.api import config from openslides.participant.models import Group, User -from openslides.projector.api import set_active_slide +from openslides.projector.api import set_active_slide, register_slide_model from openslides.utils.exceptions import OpenSlidesError from openslides.utils.test import TestCase +from .models import RelatedItem + class ListOfSpeakerModelTests(TestCase): def setUp(self): @@ -264,6 +266,20 @@ class GlobalListOfSpeakersLinks(SpeakerViewTestCase): response = self.speaker2_client.get('/agenda/list_of_speakers/add/') self.assertMessage(response, 'You were successfully added to the list of speakers.') + def test_next_speaker_on_related_item(self): + """ + Test to add a speaker on a related item. + """ + register_slide_model(RelatedItem, 'some/template.html') + related_item = RelatedItem.objects.create() + agenda_item = Item.objects.create(content_object=related_item) + config['projector_active_slide'] = {'callback': 'test_related_item', 'pk': 1} + response = self.speaker1_client.get('/agenda/list_of_speakers/add/') + + self.assertRedirects(response, '/agenda/%d/' % agenda_item.pk) + self.assertEqual(Speaker.objects.get(item__pk=agenda_item.pk).person, self.speaker1) + self.assertMessage(response, 'You were successfully added to the list of speakers.') + def test_global_next_speaker_url(self): response = self.admin_client.get('/agenda/list_of_speakers/next/') self.assertRedirects(response, '/dashboard/')