Merge pull request #1292 from ostcar/fix_list_of_speaker_on_related_item

Fixed link to list of speaker on related items.
This commit is contained in:
Norman Jäckel 2014-05-19 09:50:47 +02:00
commit 60ba0f6900
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.
"""
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):
"""

View File

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