Newer
Older
aamir-khan
committed
Returns:
VerificationStatus object if found any else None
"""
try:
return self.checkpoint_status.filter(user_id=user_id).latest() # pylint: disable=E1101
except ObjectDoesNotExist:
return None
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
@classmethod
def get_verification_checkpoint(cls, course_id, checkpoint_name):
"""Get the verification checkpoint for given course_id and checkpoint name
Arguments:
course_id(CourseKey): CourseKey
checkpoint_name(str): checkpoint name
Returns:
VerificationCheckpoint object if exists otherwise None
"""
try:
return cls.objects.get(course_id=course_id, checkpoint_name=checkpoint_name)
except cls.DoesNotExist:
return None
class VerificationStatus(models.Model):
"""A verification status represents a user’s progress
through the verification process for a particular checkpoint
Model is an append-only table that represents the user status changes in
verification process
"""
VERIFICATION_STATUS_CHOICES = (
("submitted", "submitted"),
("approved", "approved"),
("denied", "denied"),
("error", "error")
)
aamir-khan
committed
checkpoint = models.ForeignKey(VerificationCheckpoint, related_name="checkpoint_status")
user = models.ForeignKey(User)
status = models.CharField(choices=VERIFICATION_STATUS_CHOICES, db_index=True, max_length=32)
timestamp = models.DateTimeField(auto_now_add=True)
response = models.TextField(null=True, blank=True)
error = models.TextField(null=True, blank=True)
zubair-arbi
committed
# This field is used to save location of Reverification module in courseware
location_id = models.CharField(
null=True,
blank=True,
max_length=255,
help_text=ugettext_lazy("Usage id of Reverification XBlock.")
)
aamir-khan
committed
class Meta(object): # pylint: disable=missing-docstring
get_latest_by = "timestamp"
verbose_name = "Verification Status"
verbose_name_plural = "Verification Statuses"
aamir-khan
committed
def add_verification_status(cls, checkpoint, user, status, location_id=None):
""" Create new verification status object
Arguments:
checkpoint(VerificationCheckpoint): VerificationCheckpoint object
user(User): user object
status(str): String representing the status from VERIFICATION_STATUS_CHOICES
zubair-arbi
committed
location_id(str): Usage key of Reverification XBlock
zubair-arbi
committed
cls.objects.create(checkpoint=checkpoint, user=user, status=status, location_id=location_id)
@classmethod
def add_status_from_checkpoints(cls, checkpoints, user, status):
""" Create new verification status objects against the given checkpoints
Arguments:
checkpoints(list): list of VerificationCheckpoint objects
user(User): user object
status(str): String representing the status from VERIFICATION_STATUS_CHOICES
Returns:
None
"""
for checkpoint in checkpoints:
zubair-arbi
committed
# get 'location_id' from last entry (if it exists) and add it in
# new entry
try:
location_id = cls.objects.filter(checkpoint=checkpoint).latest().location_id
except cls.DoesNotExist:
zubair-arbi
committed
cls.objects.create(checkpoint=checkpoint, user=user, status=status, location_id=location_id)
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
@classmethod
def get_user_attempts(cls, user_id, course_key, related_assessment, location_id):
"""
Get re-verification attempts against a user for a given 'checkpoint'
and 'course_id'.
Arguments:
user_id(str): User Id string
course_key(str): A CourseKey of a course
related_assessment(str): Verification checkpoint name
location_id(str): Location of Reverification XBlock in courseware
Returns:
count of re-verification attempts
"""
return cls.objects.filter(
user_id=user_id,
checkpoint__course_id=course_key,
checkpoint__checkpoint_name=related_assessment,
location_id=location_id,
status="submitted"
).count()
@classmethod
def get_location_id(cls, photo_verification):
""" Return the location id of xblock
Args:
photo_verification(SoftwareSecurePhotoVerification): SoftwareSecurePhotoVerification object
Return:
Location Id of xblock if any else empty string
"""
try:
ver_status = cls.objects.filter(checkpoint__photo_verification=photo_verification).latest()
return ver_status.location_id
except cls.DoesNotExist:
return ""
class InCourseReverificationConfiguration(ConfigurationModel):
"""Configure in-course re-verification.
Enable or disable in-course re-verification feature.
When this flag is disabled, the "in-course re-verification" feature
will be disabled.
When the flag is enabled, the "in-course re-verification" feature
will be enabled.
"""
pass
class SkippedReverification(models.Model):
"""
Model for tracking skipped Reverification of a user against a specific
course.
If user skipped the Reverification for a specific course then in future
user cannot see the reverification link.
"""
user = models.ForeignKey(User)
course_id = CourseKeyField(max_length=255, db_index=True)
checkpoint = models.ForeignKey(VerificationCheckpoint, related_name="skipped_checkpoint")
created_at = models.DateTimeField(auto_now_add=True)
class Meta: # pylint: disable=missing-docstring, old-style-class
unique_together = (('user', 'course_id'),)
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
@classmethod
def add_skipped_reverification_attempt(cls, checkpoint, user_id, course_id):
""" Create skipped reverification object
Arguments:
checkpoint(VerificationCheckpoint): VerificationCheckpoint object
user_id(str): User Id of currently logged in user
course_id(CourseKey): CourseKey
Returns:
None
"""
cls.objects.create(checkpoint=checkpoint, user_id=user_id, course_id=course_id)
@classmethod
def check_user_skipped_reverification_exists(cls, user, course_id):
"""Check user skipped re-verification attempt exists against specific course
Arguments:
user(User): user object
course_id(CourseKey): CourseKey
Returns:
Boolean
"""
return cls.objects.filter(user=user, course_id=course_id).exists()