-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There is frequently a need to force through a redemption (and related enrollment/fulfillment) of a particular learner, covered by a particular subsidy access policy, into some specific course run. This commit introduces a new Django Model to support such an operation. ENT-8703
- Loading branch information
1 parent
1946d7b
commit 3f28c3c
Showing
15 changed files
with
598 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +0,0 @@ | ||
""" | ||
Utility functions for the content_assignments app. | ||
""" | ||
import traceback | ||
|
||
|
||
def chunks(a_list, chunk_size): | ||
""" | ||
Helper to break a list up into chunks. Returns a generator of lists. | ||
""" | ||
for i in range(0, len(a_list), chunk_size): | ||
yield a_list[i:i + chunk_size] | ||
|
||
|
||
def format_traceback(exception): | ||
trace = ''.join(traceback.format_tb(exception.__traceback__)) | ||
return f'{exception}\n{trace}' | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...prise_access/apps/subsidy_access_policy/migrations/0025_forced_policy_redemption_model.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Generated by Django 4.2.10 on 2024-03-27 20:28 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django_extensions.db.fields | ||
import simple_history.models | ||
import uuid | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('subsidy_access_policy', '0024_subsidyaccesspolicy_late_redemption_allowed_until'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='HistoricalForcedPolicyRedemption', | ||
fields=[ | ||
('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')), | ||
('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')), | ||
('uuid', models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, help_text='The uuid that uniquely identifies this policy record.')), | ||
('lms_user_id', models.IntegerField(db_index=True, help_text=('The id of the Open edX LMS user record that identifies the learner.',))), | ||
('course_run_key', models.CharField(db_index=True, help_text=('The course run key to enroll the learner into.',), max_length=255)), | ||
('content_price_cents', models.BigIntegerField(help_text='Cost of the content in USD Cents, should be >= 0.')), | ||
('wait_to_redeem', models.BooleanField(default=False, help_text='If selected, will not force redemption when the record is saved via Django admin.')), | ||
('redeemed_at', models.DateTimeField(blank=True, help_text='The time the forced redemption succeeded.', null=True)), | ||
('errored_at', models.DateTimeField(blank=True, help_text='The time the forced redemption failed.', null=True)), | ||
('traceback', models.TextField(blank=True, editable=False, help_text='Any traceback we recorded when an error was encountered.', null=True)), | ||
('transaction_uuid', models.UUIDField(db_index=True, help_text=('The transaction uuid caused by successful redemption.',), null=True)), | ||
('history_id', models.AutoField(primary_key=True, serialize=False)), | ||
('history_date', models.DateTimeField()), | ||
('history_change_reason', models.CharField(max_length=100, null=True)), | ||
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)), | ||
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)), | ||
('subsidy_access_policy', models.ForeignKey(blank=True, db_constraint=False, help_text='The SubsidyAccessPolicy that this forced redemption relates to.', null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='subsidy_access_policy.subsidyaccesspolicy')), | ||
], | ||
options={ | ||
'verbose_name': 'historical forced policy redemption', | ||
'verbose_name_plural': 'historical forced policy redemptions', | ||
'ordering': ('-history_date', '-history_id'), | ||
'get_latest_by': ('history_date', 'history_id'), | ||
}, | ||
bases=(simple_history.models.HistoricalChanges, models.Model), | ||
), | ||
migrations.CreateModel( | ||
name='ForcedPolicyRedemption', | ||
fields=[ | ||
('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')), | ||
('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')), | ||
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, help_text='The uuid that uniquely identifies this policy record.', primary_key=True, serialize=False, unique=True)), | ||
('lms_user_id', models.IntegerField(db_index=True, help_text=('The id of the Open edX LMS user record that identifies the learner.',))), | ||
('course_run_key', models.CharField(db_index=True, help_text=('The course run key to enroll the learner into.',), max_length=255)), | ||
('content_price_cents', models.BigIntegerField(help_text='Cost of the content in USD Cents, should be >= 0.')), | ||
('wait_to_redeem', models.BooleanField(default=False, help_text='If selected, will not force redemption when the record is saved via Django admin.')), | ||
('redeemed_at', models.DateTimeField(blank=True, help_text='The time the forced redemption succeeded.', null=True)), | ||
('errored_at', models.DateTimeField(blank=True, help_text='The time the forced redemption failed.', null=True)), | ||
('traceback', models.TextField(blank=True, editable=False, help_text='Any traceback we recorded when an error was encountered.', null=True)), | ||
('transaction_uuid', models.UUIDField(db_index=True, help_text=('The transaction uuid caused by successful redemption.',), null=True)), | ||
('subsidy_access_policy', models.ForeignKey(help_text='The SubsidyAccessPolicy that this forced redemption relates to.', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='forced_redemptions', to='subsidy_access_policy.subsidyaccesspolicy')), | ||
], | ||
options={ | ||
'get_latest_by': 'modified', | ||
'abstract': False, | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.