diff --git a/lms/djangoapps/verify_student/api.py b/lms/djangoapps/verify_student/api.py index 94bd41442164..7b8310fde030 100644 --- a/lms/djangoapps/verify_student/api.py +++ b/lms/djangoapps/verify_student/api.py @@ -136,7 +136,7 @@ def update_verification_attempt( 'Status must be one of: %(status_list)s', { 'status': status, - 'status_list': VerificationAttempt.STATUS_CHOICES, + 'status_list': VerificationAttempt.STATUS, }, ) raise VerificationAttemptInvalidStatus diff --git a/lms/djangoapps/verify_student/migrations/0017_remove_verificationattempt_created_and_more.py b/lms/djangoapps/verify_student/migrations/0017_remove_verificationattempt_created_and_more.py new file mode 100644 index 000000000000..38f89402ad83 --- /dev/null +++ b/lms/djangoapps/verify_student/migrations/0017_remove_verificationattempt_created_and_more.py @@ -0,0 +1,40 @@ +# Generated by Django 4.2.15 on 2024-09-26 18:59 + +from django.db import migrations, models +import django.utils.timezone +import lms.djangoapps.verify_student.statuses +import model_utils.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('verify_student', '0016_verificationattempt_status_changed'), + ] + + operations = [ + migrations.RemoveField( + model_name='verificationattempt', + name='created', + ), + migrations.RemoveField( + model_name='verificationattempt', + name='modified', + ), + migrations.AddField( + model_name='verificationattempt', + name='created_at', + field=models.DateTimeField(auto_now_add=True, db_index=True, default=django.utils.timezone.now), + preserve_default=False, + ), + migrations.AddField( + model_name='verificationattempt', + name='hide_status_from_user', + field=models.BooleanField(default=False, null=True), + ), + migrations.AlterField( + model_name='verificationattempt', + name='status', + field=model_utils.fields.StatusField(choices=[(lms.djangoapps.verify_student.statuses.VerificationAttemptStatus['CREATED'], lms.djangoapps.verify_student.statuses.VerificationAttemptStatus['CREATED']), (lms.djangoapps.verify_student.statuses.VerificationAttemptStatus['PENDING'], lms.djangoapps.verify_student.statuses.VerificationAttemptStatus['PENDING']), (lms.djangoapps.verify_student.statuses.VerificationAttemptStatus['APPROVED'], lms.djangoapps.verify_student.statuses.VerificationAttemptStatus['APPROVED']), (lms.djangoapps.verify_student.statuses.VerificationAttemptStatus['DENIED'], lms.djangoapps.verify_student.statuses.VerificationAttemptStatus['DENIED'])], default=lms.djangoapps.verify_student.statuses.VerificationAttemptStatus['CREATED'], max_length=100, no_check_for_status=True, verbose_name='status'), + ), + ] diff --git a/lms/djangoapps/verify_student/models.py b/lms/djangoapps/verify_student/models.py index 2230ea266f66..32f02acd4af5 100644 --- a/lms/djangoapps/verify_student/models.py +++ b/lms/djangoapps/verify_student/models.py @@ -1217,7 +1217,7 @@ def __str__(self): return str(self.arguments) -class VerificationAttempt(TimeStampedModel, StatusModel): +class VerificationAttempt(StatusModel): """ The model represents impelementation-agnostic information about identity verification (IDV) attempts. @@ -1227,18 +1227,11 @@ class VerificationAttempt(TimeStampedModel, StatusModel): user = models.ForeignKey(User, db_index=True, on_delete=models.CASCADE) name = models.CharField(blank=True, max_length=255) - STATUS_CHOICES = [ + STATUS = Choices( VerificationAttemptStatus.CREATED, VerificationAttemptStatus.PENDING, VerificationAttemptStatus.APPROVED, VerificationAttemptStatus.DENIED, - ] - - status = models.CharField(max_length=64, choices=[(status, status) for status in STATUS_CHOICES]) - - status_changed = models.DateTimeField( - null=True, - blank=True, ) expiration_datetime = models.DateTimeField( @@ -1251,19 +1244,8 @@ class VerificationAttempt(TimeStampedModel, StatusModel): null=True, ) - def save(self, *args: Any, **kwargs: Any) -> None: - """ - Overriding the save method in order to make sure that - status_changed field is updated whenever the status is - updated, even if it is not given as a parameter to the - update field argument. - """ - update_fields = kwargs.get('update_fields', None) - if update_fields and 'status' in update_fields: - self.status_changed = now() - kwargs['update_fields'] = set(update_fields).union({'status_changed'}) - - super().save(*args, **kwargs) + created_at = models.DateTimeField(auto_now_add=True, db_index=True) + updated_at = models.DateTimeField(auto_now=True, db_index=True) def should_display_status_to_user(self): """When called, returns true or false based on the type of VerificationAttempt"""