.
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.core.exceptions import ValidationError
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
from sortedm2m.fields import SortedManyToManyField
|
||||
|
||||
@@ -30,6 +31,7 @@ from anatomy.models import Modality
|
||||
|
||||
from generic.models import (
|
||||
CidUser,
|
||||
CidUserExam,
|
||||
Examination,
|
||||
# Condition,
|
||||
ExamBase,
|
||||
@@ -627,6 +629,49 @@ class CaseCollection(models.Model):
|
||||
authors = [i for i in self.author.all()]
|
||||
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):
|
||||
case = models.ForeignKey(Case, on_delete=models.CASCADE)
|
||||
|
||||
Reference in New Issue
Block a user