.
This commit is contained in:
+21
-2
@@ -1,3 +1,4 @@
|
||||
from dal import autocomplete
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.forms.models import model_to_dict
|
||||
@@ -5,7 +6,7 @@ from django.shortcuts import render, get_object_or_404, redirect
|
||||
|
||||
from django.contrib.auth.decorators import login_required, user_passes_test
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.core.exceptions import PermissionDenied, FieldError
|
||||
|
||||
from django.http import Http404, JsonResponse
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
@@ -806,4 +807,22 @@ class ExamCloneMixin():
|
||||
object = form.save()
|
||||
object.exam_questions.set(self.exam_questions)
|
||||
object.save()
|
||||
return HttpResponseRedirect(object.get_absolute_url())
|
||||
return HttpResponseRedirect(object.get_absolute_url())
|
||||
|
||||
|
||||
class ExaminationAutocomplete(autocomplete.Select2QuerySetView):
|
||||
def get_queryset(self):
|
||||
# Don't forget to filter out results depending on the visitor !
|
||||
if not self.request.user.is_authenticated:
|
||||
return Examination.objects.none()
|
||||
|
||||
qs = Examination.objects.all()
|
||||
|
||||
if self.q:
|
||||
# This raises a fielderror which breaks creating a new item if not caught
|
||||
try:
|
||||
qs = qs.filter(name__icontains=self.q)
|
||||
except FieldError:
|
||||
return Examination.objects.none()
|
||||
|
||||
return qs
|
||||
Reference in New Issue
Block a user