From 7e746f7df03d6b2171492d8f3bd33afae6a89f9e Mon Sep 17 00:00:00 2001 From: Will Daly Date: Mon, 9 Feb 2015 13:11:05 -0500 Subject: [PATCH] Fix embargo migration to the new data models. The previous version of this migration incorrectly handled disabled configuration. When configuration is disabled, the embargoed country field was the empty string; calling str.split(",") produced a list with a single empty list entry, which is not a valid country code. --- .../migrations/0004_migrate_embargo_config.py | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/common/djangoapps/embargo/migrations/0004_migrate_embargo_config.py b/common/djangoapps/embargo/migrations/0004_migrate_embargo_config.py index 0e1f7fb03a..6d577f39c3 100644 --- a/common/djangoapps/embargo/migrations/0004_migrate_embargo_config.py +++ b/common/djangoapps/embargo/migrations/0004_migrate_embargo_config.py @@ -11,13 +11,16 @@ class Migration(DataMigration): for old_course in orm.EmbargoedCourse.objects.all(): new_course, __ = orm.RestrictedCourse.objects.get_or_create(course_key=old_course.course_id) + # Set the message keys to 'embargo' + new_course.enroll_msg_key = 'embargo' + new_course.access_msg_key = 'embargo' + new_course.save() + for country in self._embargoed_countries_list(orm): country_model = orm.Country.objects.get(country=country) orm.CountryAccessRule.objects.get_or_create( country=country_model, rule_type='blacklist', - enroll_msg_key='embargo', - access_msg_key='embargo', restricted_course=new_course ) @@ -31,12 +34,15 @@ class Migration(DataMigration): # doesn't give us access to class methods on the Django model objects. try: current_config = orm.EmbargoedState.objects.order_by('-change_date')[0] - return [ - country.strip().upper() for country - in current_config.embargoed_countries.split(',') - ] + if current_config.enabled and current_config.embargoed_countries: + return [ + country.strip().upper() for country + in current_config.embargoed_countries.split(',') + ] except IndexError: - return [] + pass + + return [] models = { 'auth.group': {