continue unifying views
This commit is contained in:
+66
-40
@@ -5,64 +5,90 @@ app_name = "longs"
|
||||
|
||||
urlpatterns = [
|
||||
# path('', views.question_list, name='question_list'),
|
||||
path("", views.index, name="index"),
|
||||
path("", views.LongExamViews.index, name="index"),
|
||||
path("author/<int:pk>/", views.author_detail, name="author_detail"),
|
||||
path("author/", views.author_list, name="author_list"),
|
||||
path("question/", views.LongView.as_view(), name="long_view"),
|
||||
path("series/", views.LongSeriesView.as_view(), name="long_series_view"),
|
||||
path("series/<int:pk>", views.long_series_detail, name="long_series_detail"),
|
||||
#path("unchecked/", views.unchecked_list, name="unchecked_list"),
|
||||
#path("verified/<int:pk>/", views.verified_detail, name="verified_detail"),
|
||||
# path("unchecked/", views.unchecked_list, name="unchecked_list"),
|
||||
# path("verified/<int:pk>/", views.verified_detail, name="verified_detail"),
|
||||
path("question/<int:pk>/", views.long_detail, name="long_detail"),
|
||||
path("question/<int:pk>/split", views.long_split, name="long_split"),
|
||||
path("question/<int:pk>/clone", views.LongClone.as_view(), name="long_clone"),
|
||||
#path("verified/", views.verified, name="verified"),
|
||||
#path("all_questions/", views.all_questions, name="all_questions"),
|
||||
# path("verified/", views.verified, name="verified"),
|
||||
# path("all_questions/", views.all_questions, name="all_questions"),
|
||||
path("question/<int:pk>/scrap", views.long_scrap, name="long_scrap"),
|
||||
path("exam/<int:pk>/<int:sk>/mark", views.mark, name="mark"),
|
||||
path("exam/<int:pk>/mark", views.mark_overview, name="mark_overview"),
|
||||
# path("exam/<int:pk>/<int:sk>/", views.exam_take, name="exam_take"),
|
||||
path("exam/<int:pk>/question/<int:sk>/", views.exam_question_detail, name="exam_question_detail"),
|
||||
path("exam/<int:pk>/", views.exam_overview, name="exam_overview"),
|
||||
path("exam/<int:pk>/json_edit", views.exam_json_edit, name="exam_json_edit"),
|
||||
path("exam/<int:pk>/scores", views.exam_scores_cid,
|
||||
name="exam_scores_cid"),
|
||||
path("exam/<int:pk>/scores/<int:sk>/", views.exam_scores_cid_user,
|
||||
name="exam_scores_cid_user"),
|
||||
path("exam/<int:pk>/toggle_active", views.exam_toggle_active, name="exam_toggle_active"),
|
||||
path("exam/<int:pk>/toggle_results_published", views.exam_toggle_results_published, name="exam_toggle_results_published"),
|
||||
path("exam/submit", views.postExamAnswers, name="exam_answers_submit"),
|
||||
path("exam/", views.exam_list, name="exam_list"),
|
||||
path("exam/json/", views.active_exams, name="active_exams"),
|
||||
path("exam/<int:pk>/mark", views.LongExamViews.mark_overview, name="mark_overview"),
|
||||
# path("exam/<int:pk>/<int:sk>/", views.exam_take, name="exam_take"),
|
||||
path(
|
||||
"exam/<int:pk>/question/<int:sk>/",
|
||||
views.LongExamViews.exam_question_detail,
|
||||
name="exam_question_detail",
|
||||
),
|
||||
path("exam/<int:pk>/", views.LongExamViews.exam_overview, name="exam_overview"),
|
||||
path("exam/<int:pk>/json_edit", views.LongExamViews.exam_json_edit, name="exam_json_edit"),
|
||||
path("exam/<int:pk>/scores", views.exam_scores_cid, name="exam_scores_cid"),
|
||||
path(
|
||||
"exam/<int:pk>/scores/<int:sk>/",
|
||||
views.exam_scores_cid_user,
|
||||
name="exam_scores_cid_user",
|
||||
),
|
||||
path(
|
||||
"exam/<int:pk>/toggle_active",
|
||||
views.LongExamViews.exam_toggle_active,
|
||||
name="exam_toggle_active",
|
||||
),
|
||||
path(
|
||||
"exam/<int:pk>/toggle_results_published",
|
||||
views.LongExamViews.exam_toggle_results_published,
|
||||
name="exam_toggle_results_published",
|
||||
),
|
||||
path("exam/submit", views.LongExamViews.postExamAnswers, name="exam_answers_submit"),
|
||||
path("exam/", views.LongExamViews.exam_list, name="exam_list"),
|
||||
path("exam/json/", views.LongExamViews.active_exams, name="active_exams"),
|
||||
path("exam/json/<int:pk>", views.exam_json, name="exam_json"),
|
||||
path("exam/json/<int:pk>/recreate", views.exam_json_recreate, name="exam_json_recreate"),
|
||||
path(
|
||||
"exam/json/<int:pk>/recreate",
|
||||
views.LongExamViews.exam_json_recreate,
|
||||
name="exam_json_recreate",
|
||||
),
|
||||
path("create/", views.LongCreate.as_view(), name="long_create"),
|
||||
path("create/series", views.LongSeriesCreate.as_view(), name="long_series_create"),
|
||||
path("create/series/<int:pk>", views.LongSeriesCreate.as_view(), name="long_series_id_create"),
|
||||
path("create/defaults",
|
||||
views.LongCreationDefaultView.as_view(),
|
||||
name="long_create_defaults"),
|
||||
path(
|
||||
"create/series/<int:pk>",
|
||||
views.LongSeriesCreate.as_view(),
|
||||
name="long_series_id_create",
|
||||
),
|
||||
path(
|
||||
"create/defaults",
|
||||
views.LongCreationDefaultView.as_view(),
|
||||
name="long_create_defaults",
|
||||
),
|
||||
path("region/create/", views.create_region, name="create_region"),
|
||||
path("region/ajax/get_region_id",
|
||||
views.get_region_id,
|
||||
name="get_region_id"),
|
||||
path("abnormality/create/",
|
||||
views.create_abnormality,
|
||||
name="create_abnormality"),
|
||||
path("abnormality/ajax/get_abnormality_id",
|
||||
views.get_abnormality_id,
|
||||
name="get_abnormality_id"),
|
||||
path("examination/create/",
|
||||
views.create_examination,
|
||||
name="create_examination"),
|
||||
path("examination/ajax/get_examination_id",
|
||||
views.get_examination_id,
|
||||
name="get_examination_id"),
|
||||
path("region/ajax/get_region_id", views.get_region_id, name="get_region_id"),
|
||||
path("abnormality/create/", views.create_abnormality, name="create_abnormality"),
|
||||
path(
|
||||
"abnormality/ajax/get_abnormality_id",
|
||||
views.get_abnormality_id,
|
||||
name="get_abnormality_id",
|
||||
),
|
||||
path("examination/create/", views.create_examination, name="create_examination"),
|
||||
path(
|
||||
"examination/ajax/get_examination_id",
|
||||
views.get_examination_id,
|
||||
name="get_examination_id",
|
||||
),
|
||||
path(
|
||||
"question/<int:pk>/update",
|
||||
views.LongUpdate.as_view(),
|
||||
name="long_update",
|
||||
),
|
||||
path("series/<int:pk>/update", views.LongSeriesUpdate.as_view(), name="long_series_update"),
|
||||
path(
|
||||
"series/<int:pk>/update",
|
||||
views.LongSeriesUpdate.as_view(),
|
||||
name="long_series_update",
|
||||
),
|
||||
path("<int:pk>/add_note", views.AddNote.as_view(), name="long_add_note"),
|
||||
]
|
||||
|
||||
+4
-178
@@ -56,6 +56,8 @@ from django.forms.models import model_to_dict
|
||||
from longs.forms import LongCreationDefaultForm
|
||||
from longs.models import LongCreationDefault
|
||||
|
||||
from generic.views import ExamViews
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -69,11 +71,6 @@ class AuthorOrCheckerRequiredMixin(object):
|
||||
return obj
|
||||
|
||||
|
||||
@login_required
|
||||
def index(request):
|
||||
exams = Exam.objects.all()
|
||||
return render(request, "longs/index.html", {"exams": exams})
|
||||
|
||||
|
||||
# def index(request):
|
||||
# other_longs = Long.objects.exclude(author=request.user.pk)
|
||||
@@ -652,62 +649,6 @@ def loadJsonAnswer(answer):
|
||||
return True
|
||||
|
||||
|
||||
def exam_json_edit(request, pk):
|
||||
if request.is_ajax() and request.method == "POST":
|
||||
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
if request.POST.get("set_open_access") == "true":
|
||||
state = True
|
||||
else:
|
||||
state = False
|
||||
|
||||
questions_changed = []
|
||||
for q in exam.exam_questions.all():
|
||||
q.open_access = state
|
||||
q.save()
|
||||
questions_changed.append(q.pk)
|
||||
|
||||
data = {"status": "success", "questions": questions_changed, "state": state}
|
||||
return JsonResponse(data, status=200)
|
||||
else:
|
||||
data = {"status": "error"}
|
||||
return JsonResponse(data, status=400)
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def postExamAnswers(request):
|
||||
if request.is_ajax and request.method == "POST":
|
||||
|
||||
n = 0
|
||||
|
||||
for answer in json.loads(request.POST.get("answers")):
|
||||
ret = loadJsonAnswer(answer)
|
||||
|
||||
#if ret is not True:
|
||||
# return ret
|
||||
|
||||
if ret:
|
||||
n = n + 1
|
||||
|
||||
# print(UserAnswer.objects.filter(exam__id=q["eid"]))
|
||||
# print(request.urlencode())
|
||||
|
||||
return JsonResponse({"success": True, "question_count": n})
|
||||
return JsonResponse({"success": False, "error": "Invalid data"})
|
||||
|
||||
|
||||
# @user_passes_test(user_is_admin, login_url="/accounts/login")
|
||||
@login_required
|
||||
def mark_overview(request, pk):
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
questions = exam.exam_questions.all()
|
||||
|
||||
return render(
|
||||
request, "longs/mark_overview.html", {"exam": exam, "questions": questions}
|
||||
)
|
||||
|
||||
|
||||
# @user_passes_test(user_is_admin, login_url="/accounts/login")
|
||||
@login_required
|
||||
@@ -855,56 +796,6 @@ def mark(request, pk, sk):
|
||||
)
|
||||
|
||||
|
||||
def exam_toggle_results_published(request, pk):
|
||||
if request.is_ajax() and request.method == "POST":
|
||||
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
exam.publish_results = (
|
||||
True if request.POST.get("publish_results") == "true" else False
|
||||
)
|
||||
exam.save()
|
||||
data = {"status": "success", "publish_results": exam.publish_results}
|
||||
return JsonResponse(data, status=200)
|
||||
else:
|
||||
data = {"status": "error"}
|
||||
return JsonResponse(data, status=400)
|
||||
|
||||
|
||||
def exam_toggle_active(request, pk):
|
||||
if request.is_ajax() and request.method == "POST":
|
||||
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
exam.active = True if request.POST.get("active") == "true" else False
|
||||
exam.save()
|
||||
data = {"status": "success", "active": exam.active}
|
||||
return JsonResponse(data, status=200)
|
||||
else:
|
||||
data = {"status": "error"}
|
||||
return JsonResponse(data, status=400)
|
||||
|
||||
|
||||
def active_exams(request, json=True):
|
||||
exams = Exam.objects.all()
|
||||
|
||||
active_exams = {"exams": []}
|
||||
|
||||
for exam in exams:
|
||||
if exam.active:
|
||||
active_exams["exams"].append(
|
||||
{
|
||||
"name": exam.get_exam_name(),
|
||||
"url": request.build_absolute_uri(exam.get_json_url()),
|
||||
"type": "long",
|
||||
}
|
||||
)
|
||||
|
||||
if json == False:
|
||||
return active_exams["exams"]
|
||||
|
||||
return JsonResponse(active_exams)
|
||||
|
||||
|
||||
def exam_json(request, pk):
|
||||
|
||||
@@ -962,6 +853,7 @@ def exam_json(request, pk):
|
||||
"questions": exam_questions,
|
||||
}
|
||||
|
||||
|
||||
if exam.time_limit:
|
||||
exam_json["exam_time"] = exam.time_limit
|
||||
|
||||
@@ -973,16 +865,6 @@ def exam_json(request, pk):
|
||||
return JsonResponse(exam_json)
|
||||
|
||||
|
||||
@login_required
|
||||
def exam_json_recreate(request, pk):
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
exam.recreate_json = True
|
||||
exam.save()
|
||||
|
||||
return redirect("longs:exam_overview", pk=pk)
|
||||
|
||||
|
||||
@login_required
|
||||
def exam_scores_cid(request, pk):
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
@@ -1155,60 +1037,4 @@ def exam_scores_cid_user(request, pk, sk):
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def exam_question_detail(request, pk, sk):
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
|
||||
question = exam.exam_questions.all()[sk]
|
||||
|
||||
exam_length = len(exam.exam_questions.all())
|
||||
|
||||
pos = exam.get_question_index(question) + 1
|
||||
|
||||
print(question.exams.through.sort_value)
|
||||
|
||||
previous = -1
|
||||
if sk > 0:
|
||||
previous = sk - 1
|
||||
next = sk + 1
|
||||
if sk == exam_length - 1:
|
||||
next = False
|
||||
|
||||
return render(
|
||||
request,
|
||||
"longs/long_detail.html",
|
||||
{
|
||||
"question": question,
|
||||
"exam": exam,
|
||||
"next": next,
|
||||
"previous": previous,
|
||||
"exam_length": exam_length,
|
||||
"pos": pos,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
def exam_list(request):
|
||||
exams = Exam.objects.all()
|
||||
return render(request, "longs/exam_list.html", {"exams": exams})
|
||||
|
||||
|
||||
@login_required
|
||||
def exam_overview(request, pk):
|
||||
print(type(pk))
|
||||
#print(Exam.objects.all())
|
||||
#exams = Exam.objects.all()
|
||||
#print("test", Exam.objects.all().get(id=pk))
|
||||
exam = get_object_or_404(Exam, pk=pk)
|
||||
print("exam", exam)
|
||||
|
||||
questions = exam.exam_questions.all()
|
||||
|
||||
question_number = len(questions)
|
||||
|
||||
return render(
|
||||
request,
|
||||
"longs/exam_overview.html",
|
||||
{"exam": exam, "questions": questions, "question_number": question_number},
|
||||
)
|
||||
LongExamViews = ExamViews(Exam, "longs", "long", loadJsonAnswer)
|
||||
Reference in New Issue
Block a user