Skip to content

Commit

Permalink
fix: replace created/updated instead of status
Browse files Browse the repository at this point in the history
- also made migrations
  • Loading branch information
ilee2u committed Sep 26, 2024
1 parent 92d4509 commit 4c787e2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lms/djangoapps/verify_student/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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'),
),
]
26 changes: 4 additions & 22 deletions lms/djangoapps/verify_student/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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"""
Expand Down

0 comments on commit 4c787e2

Please sign in to comment.