def update_fake_course_run_edx_key(user, course_run):
"""
Convenience method to update a cached edX model based on the data from a CourseRun that was added
by the seed_db command
"""
start_date = course_run.start_date
year = start_date.strftime('%Y')
month = start_date.strftime('%B')
short_month = month[:3]
course_run.edx_course_key = re.sub(r'\w{3}_\d{4}$', '{}_{}'.format(short_month, year), course_run.edx_course_key)
course_run.title = re.sub(r'\w+ \d{4}$', '{} {}'.format(month, year), course_run.title)
try:
course_run.save()
except IntegrityError:
# If another course run already has this edx key, just tack on the pk to the end
course_run.edx_course_key = '{}({})'.format(course_run.edx_course_key, course_run.pk)
course_run.title = '{} ({})'.format(course_run.title, course_run.pk)
course_run.save()
update_cached_edx_data_for_run(user, course_run)
return course_run
评论列表
文章目录