block edit someone else test

This commit is contained in:
Hubert Jankowski 2022-04-09 13:24:16 +02:00
parent 5b8fde0e1c
commit cbe3e3532a
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):