From 4e5c59f01b582c4ccfdd7adbafe2c68f7ad75298 Mon Sep 17 00:00:00 2001 From: Lucas Brandstaetter <lucas@branstaetter.tech> Date: Thu, 28 Dec 2023 23:01:19 +0100 Subject: [PATCH] Fix speaker list append --- src/api/tests/schedule.py | 50 +++++++++++++++++++++++++++++++++++---- src/core/models/events.py | 4 +--- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/api/tests/schedule.py b/src/api/tests/schedule.py index 8cd756bf3..3fa2c6d7e 100644 --- a/src/api/tests/schedule.py +++ b/src/api/tests/schedule.py @@ -42,8 +42,8 @@ class ScheduleTest(TestCase): self.token.save() def _test_schedule_export(self, url_suffix: str, expected_content_type: str, content_parser): - url = reverse('api:conference-schedule') + url_suffix - resp = self.client.get(url) + schedule_url = reverse('api:conference-schedule') + url_suffix + resp = self.client.get(schedule_url) self.assertEqual(200, resp.status_code) self.assertEqual(resp['Content-Type'], expected_content_type) content_str = resp.content.decode('utf-8') @@ -68,14 +68,22 @@ class ScheduleTest(TestCase): schedule_duration=timedelta(minutes=42), ) ev1.save() + event_url = reverse('api:event-schedule', kwargs={'pk': ev1.pk}) # check that event is in the output - resp = self.client.get(url) + resp = self.client.get(schedule_url) self.assertEqual(200, resp.status_code) content_str = resp.content.decode('utf-8') content_parser(content_str) self.assertIn(ev1.name, content_str) + if url_suffix == '.json': + resp = self.client.get(event_url) + self.assertEqual(200, resp.status_code) + content_str = resp.content.decode('utf-8') + content_parser(content_str) + self.assertIn(ev1.name, content_str) + # create too-short and non-public events ev2a = Event( conference=self.conf, @@ -99,7 +107,7 @@ class ScheduleTest(TestCase): ev2b.save() # check that none of the new events are in the output - resp = self.client.get(url) + resp = self.client.get(schedule_url) self.assertEqual(200, resp.status_code) content_str = resp.content.decode('utf-8') content_parser(content_str) @@ -107,6 +115,40 @@ class ScheduleTest(TestCase): self.assertNotIn(ev2a.name, content_str) self.assertNotIn(ev2b.name, content_str) + # Add addintional data to event 1 to append the persons + ev1.additional_data = { + 'id': 12334, + 'url': 'https://fahrplan.events.ccc.de/congress/2023/fahrplan/events/12334.html', + 'slug': 'Vogc-12334-eroffnung', + 'type': 'lecture', + 'track': 'CCC', + 'persons': [ + { + 'id': 987654, + 'guid': 'aaaaaaaa-0000-000d-d00d-1d1d1d1d1d1d', + 'name': 'arthur', + 'links': [], + 'biography': 'Test speaker', + 'public_name': 'arthur', + } + ], + } + ev1.save() + + # check that event is in the output + resp = self.client.get(schedule_url) + self.assertEqual(200, resp.status_code) + content_str = resp.content.decode('utf-8') + content_parser(content_str) + self.assertIn(ev1.name, content_str) + + if url_suffix == '.json': + resp = self.client.get(event_url) + self.assertEqual(200, resp.status_code) + content_str = resp.content.decode('utf-8') + content_parser(content_str) + self.assertIn(ev1.name, content_str) + def test_export_json(self): self._test_schedule_export('.json', 'application/json', json.loads) diff --git a/src/core/models/events.py b/src/core/models/events.py index b18f3374a..c080fcb2c 100644 --- a/src/core/models/events.py +++ b/src/core/models/events.py @@ -227,9 +227,7 @@ class Event(TaggedItemMixin, BackendMixin, models.Model): @property def public_speakers(self) -> list: """Returns a list of all public speakers of this event.""" - persons = ( - self.participants.filter(is_public=True, role=EventParticipant.Role.SPEAKER).select_related('participant').order_by('participant__display_name') - ) + persons = [participant.participant for participant in self.participants.filter(is_public=True, role=EventParticipant.Role.SPEAKER)] if len(persons) == 0 and self.kind == Event.Kind.SELF_ORGANIZED and self.owner: persons.add(self.owner) -- GitLab