Commit 2c60a1d5 by Will Daly

Merge pull request #6934 from edx/will/fix-embargo-migration

Fix embargo migration to the new data models.
parents 78deaed2 7e746f7d
...@@ -11,13 +11,16 @@ class Migration(DataMigration): ...@@ -11,13 +11,16 @@ class Migration(DataMigration):
for old_course in orm.EmbargoedCourse.objects.all(): for old_course in orm.EmbargoedCourse.objects.all():
new_course, __ = orm.RestrictedCourse.objects.get_or_create(course_key=old_course.course_id) 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): for country in self._embargoed_countries_list(orm):
country_model = orm.Country.objects.get(country=country) country_model = orm.Country.objects.get(country=country)
orm.CountryAccessRule.objects.get_or_create( orm.CountryAccessRule.objects.get_or_create(
country=country_model, country=country_model,
rule_type='blacklist', rule_type='blacklist',
enroll_msg_key='embargo',
access_msg_key='embargo',
restricted_course=new_course restricted_course=new_course
) )
...@@ -31,12 +34,15 @@ class Migration(DataMigration): ...@@ -31,12 +34,15 @@ class Migration(DataMigration):
# doesn't give us access to class methods on the Django model objects. # doesn't give us access to class methods on the Django model objects.
try: try:
current_config = orm.EmbargoedState.objects.order_by('-change_date')[0] current_config = orm.EmbargoedState.objects.order_by('-change_date')[0]
return [ if current_config.enabled and current_config.embargoed_countries:
country.strip().upper() for country return [
in current_config.embargoed_countries.split(',') country.strip().upper() for country
] in current_config.embargoed_countries.split(',')
]
except IndexError: except IndexError:
return [] pass
return []
models = { models = {
'auth.group': { 'auth.group': {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment