Skip to content

Commit

Permalink
fixup! feat: initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Agrendalath committed Sep 2, 2024
1 parent 079d6af commit e6b4b29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ def handle(self, *args, **kwargs):
total_count = ManualEnrollmentAudit.objects.count()
self.stdout.write(self.style.NOTICE(f'Starting backfill of {total_count} records from ManualEnrollmentAudit.'))

for manual_enrollment in ManualEnrollmentAudit.objects.all().iterator():
course_enrollment_audit, created = CourseEnrollmentAudit.create_from_manual_enrollment(manual_enrollment)

if created:
self.stdout.write(self.style.SUCCESS(
f'Created new CourseEnrollmentAudit for email: {manual_enrollment.enrolled_email}, course_id: {course_enrollment_audit.course_id}.'))
else:
self.stdout.write(self.style.WARNING(
f'Updated existing CourseEnrollmentAudit for email: {manual_enrollment.enrolled_email}, course_id: {course_enrollment_audit.course_id}.'))
batch_size = 10000
for i, manual_enrollment in enumerate(ManualEnrollmentAudit.objects.all().iterator(), 1):
CourseEnrollmentAudit.create_from_manual_enrollment(manual_enrollment)

if i % batch_size == 0:
self.stdout.write(self.style.SUCCESS(f'Processed {i} records...'))

self.stdout.write(self.style.SUCCESS('Backfill completed successfully.'))
3 changes: 2 additions & 1 deletion openedx_course_enrollment_audit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def create_from_manual_enrollment(cls, manual_enrollment):
parsed_role = parsed_data.get('role')
parsed_reason = parsed_data.get('reason')
except JSONDecodeError:
pass # If JSON is invalid or missing keys, fields remain None
# If the reason field is not a valid JSON, store it as is.
parsed_reason = manual_enrollment.reason

return cls.objects.update_or_create(
enrolled_email=manual_enrollment.enrolled_email,
Expand Down

0 comments on commit e6b4b29

Please sign in to comment.