feat: add course mode expiration explicit to admin (#31289)

* feat: add course mode expiration explicit to admin

Adds a checkbox for defining the expiration_datetime_is_explicit to the course_mode Django admin screen.

* fix: Change labels to use "lock"

* fix: increment migration name number

* fix: delete migration

delete the migration and recreate in the next commit

* fix: add back migration

Add back the migration to hopefully fix strange failing test.

* fix: fix failing test
This commit is contained in:
Collin Preston
2023-03-21 10:46:52 -04:00
committed by GitHub
parent 373d3d58b6
commit 831a8bcc36
4 changed files with 48 additions and 2 deletions

View File

@@ -125,6 +125,12 @@ class CourseModeForm(forms.ModelForm):
mode_slug = cleaned_data.get("mode_slug")
upgrade_deadline = cleaned_data.get("_expiration_datetime")
verification_deadline = cleaned_data.get("verification_deadline")
expiration_datetime_is_explicit = cleaned_data.get("expiration_datetime_is_explicit")
if expiration_datetime_is_explicit and upgrade_deadline is None:
raise forms.ValidationError(
"An upgrade deadline must be specified when setting Lock upgrade deadline date to True."
)
# Allow upgrade deadlines ONLY for the "verified" mode
# This avoids a nasty error condition in which the upgrade deadline is set
@@ -189,6 +195,7 @@ class CourseModeAdmin(admin.ModelAdmin):
'min_price',
'currency',
'_expiration_datetime',
'expiration_datetime_is_explicit',
'verification_deadline',
'sku',
'android_sku',

View File

@@ -0,0 +1,23 @@
# Generated by Django 3.2.18 on 2023-03-06 20:39
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('course_modes', '0014_auto_20230207_1212'),
]
operations = [
migrations.AlterField(
model_name='coursemode',
name='expiration_datetime_is_explicit',
field=models.BooleanField(default=False, help_text='OPTIONAL: Set to True to lock in the explicitly defined upgrade deadline date. Set to False if there is no upgrade deadline or to use the default upgrade deadline.', verbose_name='Lock upgrade deadline date'),
),
migrations.AlterField(
model_name='historicalcoursemode',
name='expiration_datetime_is_explicit',
field=models.BooleanField(default=False, help_text='OPTIONAL: Set to True to lock in the explicitly defined upgrade deadline date. Set to False if there is no upgrade deadline or to use the default upgrade deadline.', verbose_name='Lock upgrade deadline date'),
),
]

View File

@@ -89,7 +89,14 @@ class CourseMode(models.Model):
# The system prefers to set this automatically based on default settings. But
# if the field is set manually we want a way to indicate that so we don't
# overwrite the manual setting of the field.
expiration_datetime_is_explicit = models.BooleanField(default=False)
expiration_datetime_is_explicit = models.BooleanField(
default=False,
verbose_name=_("Lock upgrade deadline date"),
help_text=_(
"OPTIONAL: Set to True to lock in the explicitly defined upgrade deadline date. "
"Set to False if there is no upgrade deadline or to use the default upgrade deadline."
)
)
# DEPRECATED: the `expiration_date` field has been replaced by `expiration_datetime`
expiration_date = models.DateField(default=None, null=True, blank=True)

View File

@@ -163,6 +163,14 @@ class AdminCourseModeFormTest(ModuleStoreTestCase):
'For other modes, please set the enrollment end date in Studio.'
))
def test_validate_expiration_datetime_is_explicit_only_with_upgrade_deadline(self):
# Only allow the expiration_datetime_is_explicit to be True if the upgrade_deadline is
# defined with a date, otherwise cause a validation error.
form = self._admin_form("verified", expiration_datetime_is_explicit=True)
self._assert_form_has_error(form, (
"An upgrade deadline must be specified when setting Lock upgrade deadline date to True."
))
@ddt.data("honor", "no-id-professional", "credit")
def test_validate_verification_deadline_only_for_verified(self, course_mode):
# Only the verified mode should have a verification deadline set.
@@ -192,7 +200,7 @@ class AdminCourseModeFormTest(ModuleStoreTestCase):
return CourseModeForm(instance=course_mode)
def _admin_form(self, mode, upgrade_deadline=None):
def _admin_form(self, mode, upgrade_deadline=None, expiration_datetime_is_explicit=False):
"""Load the course mode admin form. """
course_mode = CourseModeFactory.create(
course_id=self.course.id,
@@ -203,6 +211,7 @@ class AdminCourseModeFormTest(ModuleStoreTestCase):
"mode_slug": mode,
"mode_display_name": mode,
"_expiration_datetime": upgrade_deadline,
"expiration_datetime_is_explicit": expiration_datetime_is_explicit,
"currency": "usd",
"min_price": 10,
}, instance=course_mode)