Merge pull request #21166 from open-craft/guruprasad/fix-courseenrollment-mode-default

[BB-1506] Use a callable as the default value for CourseEnrollment.mode
This commit is contained in:
David Ormsbee
2019-12-26 10:25:27 -05:00
committed by GitHub
3 changed files with 35 additions and 1 deletions

View File

@@ -255,6 +255,14 @@ class CourseMode(models.Model):
self.expiration_datetime_is_explicit = True
self._expiration_datetime = new_datetime
@classmethod
def get_default_mode_slug(cls):
"""
Returns the default mode slug to be used in the CourseEnrollment model mode field
as the default value.
"""
return cls.DEFAULT_MODE_SLUG
@classmethod
def all_modes_for_courses(cls, course_id_list):
"""Find all modes for a list of course IDs, including expired modes.

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.22 on 2019-07-19 13:06
from __future__ import unicode_literals
import course_modes.models
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('student', '0026_allowedauthuser'),
]
operations = [
migrations.AlterField(
model_name='courseenrollment',
name='mode',
field=models.CharField(default=course_modes.models.CourseMode.get_default_mode_slug, max_length=100),
),
migrations.AlterField(
model_name='historicalcourseenrollment',
name='mode',
field=models.CharField(default=course_modes.models.CourseMode.get_default_mode_slug, max_length=100),
),
]

View File

@@ -1101,7 +1101,7 @@ class CourseEnrollment(models.Model):
# Represents the modes that are possible. We'll update this later with a
# list of possible values.
mode = models.CharField(default=CourseMode.DEFAULT_MODE_SLUG, max_length=100)
mode = models.CharField(default=CourseMode.get_default_mode_slug, max_length=100)
# An audit row will be created for every change to a CourseEnrollment. This
# will create a new model behind the scenes - HistoricalCourseEnrollment and a