From 0e4d0af5b65d79d9f5880ab8cc7b6e8a70a5dec4 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Thu, 12 Mar 2020 16:19:14 +0100 Subject: [PATCH] Fix AttributeError on speaker profile page The change in #255 introduced a regression on the speaker profile page (AttributeError in prefetch_related) that is fixed by this commit. A test to reproduce the error is included. addresses #251 --- devday/speaker/tests/test_views.py | 18 +++++++++++++++++- devday/speaker/views.py | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/devday/speaker/tests/test_views.py b/devday/speaker/tests/test_views.py index eba7de51..86082949 100644 --- a/devday/speaker/tests/test_views.py +++ b/devday/speaker/tests/test_views.py @@ -8,7 +8,7 @@ from speaker.models import PublishedSpeaker, Speaker from speaker.tests import speaker_testutils from speaker.tests.speaker_testutils import TemporaryMediaTestCase -from talk.models import Talk, Track, TalkPublishedSpeaker +from talk.models import Talk, TalkPublishedSpeaker, Track class TestCreateSpeakerView(TestCase): @@ -110,6 +110,22 @@ def test_context_has_speaker(self): self.assertEqual(response.status_code, 200) self.assertEqual(response.context["speaker"], self.speaker) + def test_talk_on_speaker_profile(self): + event = event_testutils.create_test_event() + talk = Talk.objects.create( + draft_speaker=self.speaker, + title="Test Talk", + abstract="Test abstract", + remarks="", + event=event, + ) + self.client.login(username=self.email, password=self.password) + response = self.client.get(self.url) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.context["speaker"], self.speaker) + self.assertIn("sessions", response.context) + self.assertIn(talk, response.context["sessions"]) + class TestUserSpeakerPortraitUploadView(TemporaryMediaTestCase): def setUp(self): diff --git a/devday/speaker/views.py b/devday/speaker/views.py index c7b1c749..48ae1073 100644 --- a/devday/speaker/views.py +++ b/devday/speaker/views.py @@ -67,7 +67,7 @@ def get_context_data(self, **kwargs): ).order_by("start_time"), "sessions": Talk.objects.filter(draft_speakers=context["speaker"]) .select_related("event") - .prefetch_related("draft_speaker", "published_speaker") + .prefetch_related("draft_speakers", "published_speakers") .order_by("-event__title", "title"), "speaker_image_height": settings.TALK_PUBLIC_SPEAKER_IMAGE_HEIGHT, "speaker_image_width": settings.TALK_PUBLIC_SPEAKER_IMAGE_WIDTH,