.
This commit is contained in:
+9
-16
@@ -60,7 +60,7 @@ from .forms import (
|
||||
class AuthorOrCheckerRequiredMixin(object):
|
||||
def get_object(self, *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
|
||||
if self.request.user not in obj.author.all():
|
||||
raise PermissionDenied() # or Http404
|
||||
@@ -334,22 +334,15 @@ class QuestionCreateBase(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
|
||||
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)
|
||||
formset.instance = self.object
|
||||
formset.save()
|
||||
# If the normal submit button is pressed we save as normal
|
||||
if "submit" in self.request.POST:
|
||||
return response
|
||||
# else we redirect to the clone url
|
||||
else:
|
||||
return redirect("sbas:question_clone", pk=self.object.pk)
|
||||
|
||||
response = super().form_valid(form)
|
||||
# If the normal submit button is pressed we save as normal
|
||||
if "submit" in self.request.POST:
|
||||
return response
|
||||
# else we redirect to the clone url
|
||||
else:
|
||||
return super().form_invalid(form)
|
||||
return redirect("sbas:question_clone", pk=self.object.pk)
|
||||
|
||||
|
||||
class QuestionCreate(QuestionCreateBase):
|
||||
|
||||
@@ -470,7 +463,7 @@ class ExamDelete(AuthorOrCheckerRequiredMixin, ExamDeleteBase):
|
||||
# This view should return a list exams available to a 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.filter(author__id=user.id)
|
||||
|
||||
Reference in New Issue
Block a user