Fix link to list of speaker item on related items

fix #1242
This commit is contained in:
Oskar Hahn 2014-05-17 14:21:57 +02:00
parent 77c168f337
commit 3419855a1e
2 changed files with 30 additions and 8 deletions

View File

@ -575,14 +575,20 @@ class CurrentListOfSpeakersView(RedirectView):
""" """
Returns the current Item, or None, if the current Slide is not an Agenda Item. Returns the current Item, or None, if the current Slide is not an Agenda Item.
""" """
active_slide = get_active_slide() slide = get_active_object()
if active_slide['callback'] == 'agenda': if slide is None or isinstance(slide, Item):
try: # No Slide or an agenda item is active
return Item.objects.get(pk=active_slide.get('pk', None)) item = slide
except Item.DoesNotExist:
return None
else: 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): def get_redirect_url(self):
""" """

View File

@ -8,10 +8,12 @@ from openslides.agenda.models import Item, Speaker
from openslides.agenda.signals import agenda_list_of_speakers from openslides.agenda.signals import agenda_list_of_speakers
from openslides.config.api import config from openslides.config.api import config
from openslides.participant.models import Group, User 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.exceptions import OpenSlidesError
from openslides.utils.test import TestCase from openslides.utils.test import TestCase
from .models import RelatedItem
class ListOfSpeakerModelTests(TestCase): class ListOfSpeakerModelTests(TestCase):
def setUp(self): def setUp(self):
@ -264,6 +266,20 @@ class GlobalListOfSpeakersLinks(SpeakerViewTestCase):
response = self.speaker2_client.get('/agenda/list_of_speakers/add/') response = self.speaker2_client.get('/agenda/list_of_speakers/add/')
self.assertMessage(response, 'You were successfully added to the list of speakers.') 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): def test_global_next_speaker_url(self):
response = self.admin_client.get('/agenda/list_of_speakers/next/') response = self.admin_client.get('/agenda/list_of_speakers/next/')
self.assertRedirects(response, '/dashboard/') self.assertRedirects(response, '/dashboard/')