Newer
Older
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"
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)
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
@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()
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'),)
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
@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()