.
This commit is contained in:
@@ -19,6 +19,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from django.utils.html import mark_safe
|
from django.utils.html import mark_safe
|
||||||
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
from sortedm2m.fields import SortedManyToManyField
|
from sortedm2m.fields import SortedManyToManyField
|
||||||
|
|
||||||
@@ -30,6 +31,7 @@ from anatomy.models import Modality
|
|||||||
|
|
||||||
from generic.models import (
|
from generic.models import (
|
||||||
CidUser,
|
CidUser,
|
||||||
|
CidUserExam,
|
||||||
Examination,
|
Examination,
|
||||||
# Condition,
|
# Condition,
|
||||||
ExamBase,
|
ExamBase,
|
||||||
@@ -627,6 +629,49 @@ class CaseCollection(models.Model):
|
|||||||
authors = [i for i in self.author.all()]
|
authors = [i for i in self.author.all()]
|
||||||
return authors
|
return authors
|
||||||
|
|
||||||
|
def check_cid_user(self, cid, passcode, request=None):
|
||||||
|
if request is not None and request.user.is_superuser:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if self.valid_users.exists():
|
||||||
|
|
||||||
|
user = self.valid_users.filter(cid=cid).first()
|
||||||
|
|
||||||
|
if not user or user.passcode != passcode:
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_or_create_cid_user_exam(self, cid_user, start_time=None):
|
||||||
|
content_type = ContentType.objects.get_for_model(self)
|
||||||
|
c = CidUserExam.objects.filter(
|
||||||
|
content_type=content_type, object_id=self.pk, cid_user=cid_user
|
||||||
|
).first()
|
||||||
|
if c:
|
||||||
|
return c
|
||||||
|
|
||||||
|
if start_time is None:
|
||||||
|
start_time = timezone.now()
|
||||||
|
new = CidUserExam(
|
||||||
|
content_type=content_type,
|
||||||
|
object_id=self.pk,
|
||||||
|
cid_user=cid_user,
|
||||||
|
start_time=start_time,
|
||||||
|
)
|
||||||
|
new.save()
|
||||||
|
return new
|
||||||
|
|
||||||
|
def get_cid_user_exams(self, cid_user=None):
|
||||||
|
content_type = ContentType.objects.get_for_model(self)
|
||||||
|
if cid_user is None:
|
||||||
|
return CidUserExam.objects.filter(
|
||||||
|
content_type=content_type,
|
||||||
|
object_id=self.pk,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return CidUserExam.objects.filter(
|
||||||
|
content_type=content_type, object_id=self.pk, cid_user=cid_user
|
||||||
|
)
|
||||||
|
|
||||||
class CaseDetail(models.Model):
|
class CaseDetail(models.Model):
|
||||||
case = models.ForeignKey(Case, on_delete=models.CASCADE)
|
case = models.ForeignKey(Case, on_delete=models.CASCADE)
|
||||||
|
|||||||
@@ -16,6 +16,10 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
{% if take %}
|
||||||
|
<h1>TAKE</h1>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ urlpatterns = [
|
|||||||
path("collection/<int:pk>/delete", views.CaseCollectionDelete.as_view(), name="collection_delete"),
|
path("collection/<int:pk>/delete", views.CaseCollectionDelete.as_view(), name="collection_delete"),
|
||||||
path("collection/<int:pk>/update", views.CaseCollectionUpdate.as_view(), name="collection_update"),
|
path("collection/<int:pk>/update", views.CaseCollectionUpdate.as_view(), name="collection_update"),
|
||||||
path("collection/<int:pk>", views.collection_detail_view, name="collection_detail_view"),
|
path("collection/<int:pk>", views.collection_detail_view, name="collection_detail_view"),
|
||||||
|
path("collection/<int:pk>/take/<int:cid>/<str:passcode", views.collection_detail_view_take, name="collection_detail_view_take"),
|
||||||
path("collection/<int:pk>/<int:case_number>", views.collection_case_view, name="collection_case_view"),
|
path("collection/<int:pk>/<int:case_number>", views.collection_case_view, name="collection_case_view"),
|
||||||
|
path("collection/<int:pk>/<int:case_number>/take/<int:cid>/<str:passcode", views.collection_case_view_take, name="collection_case_view_take"),
|
||||||
path("condition/", views.ConditionView.as_view(), name="condition_view"),
|
path("condition/", views.ConditionView.as_view(), name="condition_view"),
|
||||||
path("categories/", views.categories_list, name="categories_list"),
|
path("categories/", views.categories_list, name="categories_list"),
|
||||||
path("condition/<int:pk>", views.condition_detail, name="condition_detail"),
|
path("condition/<int:pk>", views.condition_detail, name="condition_detail"),
|
||||||
|
|||||||
+13
-2
@@ -1050,10 +1050,21 @@ def collection_detail_view(request, pk):
|
|||||||
request, "atlas/collection_detail_view.html", {"collection": collection}
|
request, "atlas/collection_detail_view.html", {"collection": collection}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def collection_case_view_take(request, pk, case_number, cid, passcode):
|
||||||
def collection_case_view(request, pk, case_number):
|
return collection_case_view(pk, case_number, True, cid, passcode)
|
||||||
collection = get_object_or_404(CaseCollection, pk=pk)
|
collection = get_object_or_404(CaseCollection, pk=pk)
|
||||||
|
|
||||||
|
if not collection.check_cid_user(cid, passcode, request):
|
||||||
|
raise Http404("Error accessing exam")
|
||||||
|
|
||||||
|
def collection_case_view(request, pk, case_number, take=False, cid=None, passcode=None):
|
||||||
|
collection = get_object_or_404(CaseCollection, pk=pk)
|
||||||
|
|
||||||
|
if take:
|
||||||
|
if not collection.check_cid_user(cid, passcode, request):
|
||||||
|
raise Http404("Error accessing exam")
|
||||||
|
|
||||||
|
|
||||||
cases = collection.cases.all().order_by("casedetail__sort_order").prefetch_related()
|
cases = collection.cases.all().order_by("casedetail__sort_order").prefetch_related()
|
||||||
case = cases[case_number]
|
case = cases[case_number]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user