story part update now redirects back to index

This commit is contained in:
Gesche 2021-05-04 23:41:06 +02:00
parent 1527f07fa3
commit e09f17bdfb
3 changed files with 10 additions and 3 deletions

View File

@ -6,7 +6,7 @@
</head> </head>
<body> <body>
<form action="{% url 'writing:create_story_part' %}" 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 }}
<input type="submit" value="Submit"> <input type="submit" value="Submit">

View File

@ -8,6 +8,6 @@ urlpatterns = [
path('', views.IndexView.as_view(), name='index'), path('', views.IndexView.as_view(), name='index'),
path('<int:pk>/', views.DetailView.as_view(), name='detail'), path('<int:pk>/', views.DetailView.as_view(), name='detail'),
path('create/', views.StoryRoundCreate.as_view(), name='create_story_round'), path('create/', views.StoryRoundCreate.as_view(), name='create_story_round'),
path('open/<int:story_round_pk>/<int:story_pk>/<int:story_part_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: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'),
] ]

View File

@ -63,6 +63,13 @@ class StoryPartUpdate(LoginRequiredMixin, UpdateView):
model = StoryPart model = StoryPart
fields = ['text'] fields = ['text']
template_name = 'writingtogether/story_part.html' template_name = 'writingtogether/story_part.html'
success_url = reverse_lazy('writing:index')
def get_context_data(self, **kwargs):
context = super(StoryPartUpdate, self).get_context_data(**kwargs)
context.update(self.kwargs)
return context
#def form_valid(self, form): #def form_valid(self, form):
# form.instance.created_by = self.request.user # form.instance.created_by = self.request.user
@ -82,5 +89,5 @@ class RedirectToNextOpenPart(LoginRequiredMixin, RedirectView):
story_part = story_round.get_next_story_part(user=self.request.user) story_part = story_round.get_next_story_part(user=self.request.user)
kwargs['story_pk'] = story_part.part_of.pk kwargs['story_pk'] = story_part.part_of.pk
kwargs['story_part_pk'] = story_part.pk kwargs['pk'] = story_part.pk
return super().get_redirect_url(*args, **kwargs) return super().get_redirect_url(*args, **kwargs)