Merge pull request 'block edit someone else test' (#33) from fature/block-edit-someone-else-test into master

Reviewed-on: #33
This commit is contained in:
s470631 2022-04-09 13:24:51 +02:00
commit ead24e0e2f
2 changed files with 5 additions and 0 deletions

View File

@ -0,0 +1,3 @@
Nie możesz edydotwać testu stworzonego przez innego użytkownika
<input type=button value="Powrót do porzpedniej strony" onClick="javascript:history.go(-1);">

View File

@ -192,6 +192,8 @@ class EditTestTemplateView(TemplateView):
self.test_id = test_id self.test_id = test_id
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context["test"] = self.get_queryset().filter(id=test_id).prefetch_related("questions__answers").first() context["test"] = self.get_queryset().filter(id=test_id).prefetch_related("questions__answers").first()
if context["test"].created_by.email != self.request.user.email:
return render(context, "canNotEditTest.html")
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):