implement advance to next round
This commit is contained in:
parent
0d0cc2eeb5
commit
a59354693c
|
@ -1,3 +1,5 @@
|
|||
from typing import Tuple
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import models
|
||||
from django.db.models import CASCADE
|
||||
|
@ -29,6 +31,14 @@ class StoryRound(models.Model):
|
|||
return False
|
||||
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):
|
||||
# user = models.ForeignKey(User, on_delete=CASCADE)
|
||||
|
|
|
@ -88,6 +88,13 @@ class RedirectToNextOpenPart(LoginRequiredMixin, RedirectView):
|
|||
def get_redirect_url(self, *args, **kwargs):
|
||||
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)
|
||||
|
||||
if story_part.finished:
|
||||
|
@ -96,6 +103,7 @@ class RedirectToNextOpenPart(LoginRequiredMixin, RedirectView):
|
|||
else:
|
||||
kwargs['story_pk'] = story_part.part_of.pk
|
||||
kwargs['pk'] = story_part.pk
|
||||
|
||||
return super().get_redirect_url(*args, **kwargs)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue