.
This commit is contained in:
+2
-9
@@ -60,7 +60,7 @@ from .forms import (
|
|||||||
class AuthorOrCheckerRequiredMixin(object):
|
class AuthorOrCheckerRequiredMixin(object):
|
||||||
def get_object(self, *args, **kwargs):
|
def get_object(self, *args, **kwargs):
|
||||||
obj = super().get_object(*args, **kwargs)
|
obj = super().get_object(*args, **kwargs)
|
||||||
if self.request.user.groups.filter(name="sba_checker").exists():
|
if self.request.user.groups.filter(name="sbas_checker").exists():
|
||||||
return obj
|
return obj
|
||||||
if self.request.user not in obj.author.all():
|
if self.request.user not in obj.author.all():
|
||||||
raise PermissionDenied() # or Http404
|
raise PermissionDenied() # or Http404
|
||||||
@@ -334,13 +334,8 @@ class QuestionCreateBase(RevisionMixin, LoginRequiredMixin, CreateView):
|
|||||||
|
|
||||||
form.instance.author.add(self.request.user.id)
|
form.instance.author.add(self.request.user.id)
|
||||||
|
|
||||||
context = self.get_context_data(form=form)
|
|
||||||
formset = context["answer_formset"]
|
|
||||||
|
|
||||||
if formset.is_valid():
|
|
||||||
response = super().form_valid(form)
|
response = super().form_valid(form)
|
||||||
formset.instance = self.object
|
|
||||||
formset.save()
|
|
||||||
# If the normal submit button is pressed we save as normal
|
# If the normal submit button is pressed we save as normal
|
||||||
if "submit" in self.request.POST:
|
if "submit" in self.request.POST:
|
||||||
return response
|
return response
|
||||||
@@ -348,8 +343,6 @@ class QuestionCreateBase(RevisionMixin, LoginRequiredMixin, CreateView):
|
|||||||
else:
|
else:
|
||||||
return redirect("sbas:question_clone", pk=self.object.pk)
|
return redirect("sbas:question_clone", pk=self.object.pk)
|
||||||
|
|
||||||
else:
|
|
||||||
return super().form_invalid(form)
|
|
||||||
|
|
||||||
class QuestionCreate(QuestionCreateBase):
|
class QuestionCreate(QuestionCreateBase):
|
||||||
|
|
||||||
@@ -470,7 +463,7 @@ class ExamDelete(AuthorOrCheckerRequiredMixin, ExamDeleteBase):
|
|||||||
# This view should return a list exams available to a user.
|
# This view should return a list exams available to a user.
|
||||||
# """
|
# """
|
||||||
# user = self.request.user
|
# user = self.request.user
|
||||||
# if user.groups.filter(name="sba_checker").exists():
|
# if user.groups.filter(name="sbas_checker").exists():
|
||||||
# return Exam.objects.all()
|
# return Exam.objects.all()
|
||||||
#
|
#
|
||||||
# return Exam.objects.filter(author__id=user.id)
|
# return Exam.objects.filter(author__id=user.id)
|
||||||
|
|||||||
Reference in New Issue
Block a user