continue working on case collections
This commit is contained in:
+90
-21
@@ -27,7 +27,7 @@ from django.urls import reverse_lazy, reverse
|
||||
from django.http import Http404, JsonResponse
|
||||
from django.http import HttpResponseRedirect, HttpResponse
|
||||
|
||||
from generic.models import CidUser
|
||||
from generic.models import CidUser, CidUserExam
|
||||
|
||||
from .forms import (
|
||||
AddCollectionToCaseForm,
|
||||
@@ -38,6 +38,7 @@ from .forms import (
|
||||
CidReportAnswerMarkForm,
|
||||
ConditionForm,
|
||||
FindingForm,
|
||||
SelfReviewForm,
|
||||
SeriesForm,
|
||||
SeriesImageFormSet,
|
||||
SeriesFormSet,
|
||||
@@ -54,6 +55,7 @@ from .models import (
|
||||
Condition,
|
||||
PathologicalProcess,
|
||||
Presentation,
|
||||
SelfReview,
|
||||
Series,
|
||||
Examination,
|
||||
Finding,
|
||||
@@ -1114,7 +1116,7 @@ def collection_take_start(request, pk):
|
||||
valid_user = (collection.check_logged_in_user(request),)
|
||||
|
||||
cid_exam = None
|
||||
if valid_user:
|
||||
if collection.collection_type == "REV" or valid_user:
|
||||
cid_exam = collection.get_cid_user_exams(user_user=request.user).first()
|
||||
|
||||
template_variables = {
|
||||
@@ -1372,21 +1374,23 @@ def collection_case_view_take(
|
||||
collection = get_object_or_404(CaseCollection, pk=pk)
|
||||
|
||||
form = None
|
||||
answer: CidReportAnswer | UserReportAnswer
|
||||
answer: None | CidReportAnswer | UserReportAnswer = None
|
||||
|
||||
collection.check_user_can_take(cid, passcode, request)
|
||||
|
||||
cases = collection.cases.all().order_by("casedetail__sort_order").prefetch_related()
|
||||
case = cases[case_number]
|
||||
|
||||
if not collection.review_only():
|
||||
cid_user_exam = collection.get_or_create_cid_user_exam(
|
||||
cid=cid, user_user=request.user
|
||||
)
|
||||
cid_user_exam = collection.get_or_create_cid_user_exam(
|
||||
cid=cid, user_user=request.user
|
||||
)
|
||||
|
||||
if cid_user_exam.start_time is None:
|
||||
cid_user_exam.start_time = timezone.now()
|
||||
cid_user_exam.save()
|
||||
if cid_user_exam.start_time is None:
|
||||
cid_user_exam.start_time = timezone.now()
|
||||
cid_user_exam.save()
|
||||
|
||||
|
||||
if not collection.review_only():
|
||||
|
||||
if collection.collection_type == "REP":
|
||||
case_detail = CaseDetail.objects.get(case=case, collection=collection)
|
||||
@@ -1420,18 +1424,14 @@ def collection_case_view_take(
|
||||
cid_user_exam.end_time = timezone.now()
|
||||
cid_user_exam.save()
|
||||
|
||||
if cid is not None:
|
||||
kwargs = {"pk": pk, "cid": cid, "passcode": passcode}
|
||||
redirect_url = "atlas:collection_case_view_take"
|
||||
overview_url = "atlas:collection_take_overview"
|
||||
else:
|
||||
kwargs = {"pk": pk}
|
||||
redirect_url = "atlas:collection_case_view_take_user"
|
||||
overview_url = "atlas:collection_take_overview_user"
|
||||
|
||||
if cid is not None:
|
||||
kwargs = {"pk": pk, "cid": cid, "passcode": passcode}
|
||||
redirect_url = "atlas:collection_case_view_take"
|
||||
overview_url = "atlas:collection_take_overview"
|
||||
else:
|
||||
kwargs = {"pk": pk}
|
||||
redirect_url = "atlas:collection_case_view_take"
|
||||
redirect_url = "atlas:collection_case_view_take_user"
|
||||
overview_url = "atlas:collection_take_overview_user"
|
||||
|
||||
if "next" in request.POST:
|
||||
return redirect(redirect_url, case_number=case_number + 1, **kwargs)
|
||||
@@ -1457,18 +1457,23 @@ def collection_case_view_take(
|
||||
|
||||
# Set what details a user is / is not able to view when taking the case
|
||||
# this can be configured via the collection edit menu
|
||||
if collection.publish_results:
|
||||
if collection.publish_results or cid_user_exam.completed:
|
||||
completed = True
|
||||
show_title = collection.show_title_post
|
||||
show_history = collection.show_history_post
|
||||
show_description = collection.show_description_post
|
||||
show_discussion = collection.show_discussion_post
|
||||
show_report = collection.show_report_post
|
||||
|
||||
self_review = cid_user_exam.selfreview_set.filter(case=case)
|
||||
else:
|
||||
completed = False
|
||||
show_title = collection.show_title_pre
|
||||
show_history = collection.show_history_pre
|
||||
show_description = collection.show_description_pre
|
||||
show_discussion = collection.show_discussion_pre
|
||||
show_report = collection.show_report_pre
|
||||
self_review = []
|
||||
|
||||
return render(
|
||||
request,
|
||||
@@ -1490,6 +1495,8 @@ def collection_case_view_take(
|
||||
"show_discussion": show_discussion,
|
||||
"show_report": show_report,
|
||||
"cid_user_exam": cid_user_exam,
|
||||
"completed": completed,
|
||||
"self_review": self_review,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1735,3 +1742,65 @@ def collection_scores_cid(request, pk):
|
||||
GenericExamViews = ExamViews(
|
||||
CaseCollection, Case, None, CidReportAnswer, "atlas", "casecollection"
|
||||
)
|
||||
|
||||
class CollectionCloneMixin:
|
||||
def get_initial(self):
|
||||
old_object = get_object_or_404(self.model, pk=self.kwargs["exam_id"])
|
||||
initial_data = model_to_dict(old_object, exclude=["id"])
|
||||
|
||||
# We manually transfer the forign keys / m2m relationships
|
||||
questions = old_object.cases.all().values_list("id", flat=True)
|
||||
authors = old_object.author.all().values_list("id", flat=True)
|
||||
|
||||
self.cases = list(questions)
|
||||
self.author = list(authors)
|
||||
|
||||
return initial_data
|
||||
|
||||
def form_valid(self, form):
|
||||
object = form.save()
|
||||
# Reapply these otherwise they get lost?
|
||||
object.cases.set(self.cases)
|
||||
object.author.set(self.author)
|
||||
object.save()
|
||||
return HttpResponseRedirect(object.get_absolute_url())
|
||||
|
||||
class CollectionClone(CollectionCloneMixin, CaseCollectionCreate):
|
||||
"""Clone exam view"""
|
||||
|
||||
class AddSelfReview(CreateView):
|
||||
model = SelfReview
|
||||
form_class = SelfReviewForm
|
||||
|
||||
# fields = ("author", "note_type", "note")
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super(AddSelfReview, self).get_form_kwargs()
|
||||
# update the kwargs for the form init method with yours
|
||||
kwargs.update(self.kwargs) # self.kwargs contains all url conf params
|
||||
#kwargs.update({"user": self.request.user})
|
||||
return kwargs
|
||||
|
||||
def get_initial(self):
|
||||
user_exam_id = self.kwargs["user_exam_id"]
|
||||
case_id = self.kwargs["case_id"]
|
||||
|
||||
self.user_exam = get_object_or_404(CidUserExam, pk=user_exam_id)
|
||||
self.case = get_object_or_404(Case, pk=case_id)
|
||||
return {"user_exam": user_exam_id, "case": case_id}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
# This can also be accessed via view.**** in the template
|
||||
context = super(AddSelfReview, self).get_context_data(**kwargs)
|
||||
context["user_exam"] = self.user_exam
|
||||
context["case"] = self.case
|
||||
return context
|
||||
|
||||
# def form_valid(self, form):
|
||||
# model = form.save(commit=False)
|
||||
#
|
||||
# model.save()
|
||||
#
|
||||
# response = super().form_valid(form)
|
||||
#
|
||||
# return response
|
||||
Reference in New Issue
Block a user