.
This commit is contained in:
+20
-10
@@ -1,4 +1,6 @@
|
||||
from django.urls import path, include
|
||||
|
||||
from generic.models import Examination
|
||||
from . import views
|
||||
|
||||
|
||||
@@ -6,14 +8,22 @@ app_name = "generic"
|
||||
|
||||
urlpatterns = [
|
||||
# path('', views.question_list, name='question_list'),
|
||||
path("examination/create/",
|
||||
views.create_examination,
|
||||
name="create_examination"),
|
||||
path("examination/ajax/get_examination_id",
|
||||
views.get_examination_id,
|
||||
name="get_examination_id"),
|
||||
path("generic_exam_json_edit",
|
||||
views.generic_exam_json_edit,
|
||||
name="generic_exam_json_edit"),
|
||||
|
||||
path("examination/create/", views.create_examination, name="create_examination"),
|
||||
path(
|
||||
"examination/ajax/get_examination_id",
|
||||
views.get_examination_id,
|
||||
name="get_examination_id",
|
||||
),
|
||||
path(
|
||||
"generic_exam_json_edit",
|
||||
views.generic_exam_json_edit,
|
||||
name="generic_exam_json_edit",
|
||||
),
|
||||
path(
|
||||
"examination-autocomplete",
|
||||
views.ExaminationAutocomplete.as_view(
|
||||
model=Examination, create_field="examination"
|
||||
),
|
||||
name="examination-autocomplete",
|
||||
),
|
||||
]
|
||||
|
||||
+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