add finished view

This commit is contained in:
Gesche 2021-05-05 22:54:21 +02:00
parent a59354693c
commit 7277fc7b5c
5 changed files with 37 additions and 2 deletions

View File

@ -70,7 +70,7 @@ class StoryPart(models.Model):
user = models.ForeignKey(User, on_delete=CASCADE) user = models.ForeignKey(User, on_delete=CASCADE)
previous_part = models.ForeignKey('StoryPart', on_delete=CASCADE, null=True, blank=True) previous_part = models.ForeignKey('StoryPart', on_delete=CASCADE, null=True, blank=True)
text = models.TextField(null=True, blank=True) text = models.TextField(null=True, blank=True)
part_of = models.ForeignKey('Story', on_delete=CASCADE) part_of = models.ForeignKey('Story', on_delete=CASCADE, related_name='parts')
turn_number = models.IntegerField() turn_number = models.IntegerField()
@property @property

View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>Fertig!</h1>
{% for story in stories %}
{% for story_part in story.parts.all %}
<div>{{ story_part.text }} <i>({{ story_part.user }})</i></div>
{% endfor %}
<br>
<br>
{% endfor %}
</body>
</html>

View File

@ -6,6 +6,10 @@
</head> </head>
<body> <body>
<h1>Runde {{ current_round }} / {{ total_rounds }}</h1> <h1>Runde {{ current_round }} / {{ total_rounds }}</h1>
{% if previous_part %}
<div>Letzter Satz: {{ previous_part.text }}</div>
{% endif %}
<form action="{% url 'writing:update_story_part' story_round_pk=story_round_pk story_pk=story_pk pk=pk %}" method="post"> <form action="{% url 'writing:update_story_part' story_round_pk=story_round_pk story_pk=story_pk pk=pk %}" method="post">
{% csrf_token %} {% csrf_token %}
{{ form.as_p }} {{ form.as_p }}

View File

@ -11,4 +11,5 @@ urlpatterns = [
path('open/<int:story_round_pk>/<int:story_pk>/<int:pk>/', views.StoryPartUpdate.as_view(), name='update_story_part'), path('open/<int:story_round_pk>/<int:story_pk>/<int:pk>/', views.StoryPartUpdate.as_view(), name='update_story_part'),
path('open/<int:pk>/waiting/', views.WaitForOthersView.as_view(), name='wait_for_others'), path('open/<int:pk>/waiting/', views.WaitForOthersView.as_view(), name='wait_for_others'),
path('open/<int:story_round_pk>/', views.RedirectToNextOpenPart.as_view(), name='redirect_story_part'), path('open/<int:story_round_pk>/', views.RedirectToNextOpenPart.as_view(), name='redirect_story_part'),
path('finished/<int:pk>/', views.RoundFinishedView.as_view(), name ='finished'),
] ]

View File

@ -67,7 +67,8 @@ class StoryPartUpdate(LoginRequiredMixin, UpdateView):
context = super(StoryPartUpdate, self).get_context_data(**kwargs) context = super(StoryPartUpdate, self).get_context_data(**kwargs)
context.update({ context.update({
'current_round': self.object.turn_number + 1, 'current_round': self.object.turn_number + 1,
'total_rounds': self.object.part_of.part_of_round.number_of_rounds 'total_rounds': self.object.part_of.part_of_round.number_of_rounds,
'previous_part': self.object.previous_part,
}) })
context.update(self.kwargs) context.update(self.kwargs)
return context return context
@ -110,3 +111,12 @@ class RedirectToNextOpenPart(LoginRequiredMixin, RedirectView):
class WaitForOthersView(LoginRequiredMixin, DetailView): class WaitForOthersView(LoginRequiredMixin, DetailView):
model = StoryRound model = StoryRound
template_name = 'writingtogether/wait_for_others.html' template_name = 'writingtogether/wait_for_others.html'
class RoundFinishedView(LoginRequiredMixin, ListView):
model = Story
context_object_name = 'stories'
template_name = 'writingtogether/finished.html'
def get_queryset(self):
return Story.objects.filter(part_of_round_id=self.kwargs['pk']).prefetch_related('parts')