implement advance to next round

This commit is contained in:
Gesche 2021-05-05 22:31:35 +02:00
parent 0d0cc2eeb5
commit a59354693c
2 changed files with 18 additions and 0 deletions

View File

@ -1,3 +1,5 @@
from typing import Tuple
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.db import models from django.db import models
from django.db.models import CASCADE from django.db.models import CASCADE
@ -29,6 +31,14 @@ class StoryRound(models.Model):
return False return False
return True return True
def advance_to_next_turn_and_get_status_and_round_number(self) -> Tuple[str, int]:
if self.current_turn+1 == self.number_of_rounds:
return 'finished', self.current_turn
self.current_turn += 1
self.save()
return 'ongoing', self.current_turn
#class Participant(models.Model): #class Participant(models.Model):
# user = models.ForeignKey(User, on_delete=CASCADE) # user = models.ForeignKey(User, on_delete=CASCADE)

View File

@ -88,6 +88,13 @@ class RedirectToNextOpenPart(LoginRequiredMixin, RedirectView):
def get_redirect_url(self, *args, **kwargs): def get_redirect_url(self, *args, **kwargs):
story_round = get_object_or_404(StoryRound, pk=kwargs['story_round_pk']) story_round = get_object_or_404(StoryRound, pk=kwargs['story_round_pk'])
if story_round.next_round_ready():
status, turn_number = story_round.advance_to_next_turn_and_get_status_and_round_number()
if status == 'finished':
self.pattern_name = 'writing:finished'
kwargs['pk'] = kwargs.pop('story_round_pk')
return super().get_redirect_url(*args, **kwargs)
story_part = story_round.get_next_story_part(user=self.request.user) story_part = story_round.get_next_story_part(user=self.request.user)
if story_part.finished: if story_part.finished:
@ -96,6 +103,7 @@ class RedirectToNextOpenPart(LoginRequiredMixin, RedirectView):
else: else:
kwargs['story_pk'] = story_part.part_of.pk kwargs['story_pk'] = story_part.part_of.pk
kwargs['pk'] = story_part.pk kwargs['pk'] = story_part.pk
return super().get_redirect_url(*args, **kwargs) return super().get_redirect_url(*args, **kwargs)