Merge pull request #5076 from FinnStutzenstein/readdLastSpeakerFix

Fixed readding last speaker
This commit is contained in:
Sean 2019-10-16 09:57:07 +02:00 committed by GitHub
commit 0df87fd522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -535,12 +535,12 @@ class ListOfSpeakersViewSet(
list_of_speakers = self.get_object()
# Retrieve speaker which spoke last and next speaker
ordered_speakers = list_of_speakers.speakers.order_by("-end_time")
if len(ordered_speakers) == 0:
raise ValidationError({"detail": "There is no last speaker at the moment."})
last_speaker = ordered_speakers[0]
if last_speaker.end_time is None:
last_speaker = (
list_of_speakers.speakers.exclude(end_time=None)
.order_by("-end_time")
.first()
)
if not last_speaker:
raise ValidationError({"detail": "There is no last speaker at the moment."})
next_speaker = list_of_speakers.get_next_speaker()

View File

@ -497,7 +497,7 @@ class ManageSpeaker(TestCase):
username="test_user_KLGHjkHJKBhjJHGGJKJn",
password="test_password_JHt678VbhjuGhj76hjGA",
)
Speaker.objects.add(user2, self.list_of_speakers)
speaker2 = Speaker.objects.add(user2, self.list_of_speakers)
response = self.client.post(
reverse(
@ -511,6 +511,7 @@ class ManageSpeaker(TestCase):
and speaker.end_time is None
and speaker.weight is not None
)
self.assertTrue(speaker.weight < speaker2.weight)
def test_readd_last_speaker_no_admin(self):
self.util_add_user_as_last_speaker()