lib.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:micromasters 作者: mitodl 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号