def update_background(course_id, extension_dict):
    "\n    Update time on selected students' quizzes to a specified percentage.\n\n    :param course_id: The Canvas ID of the Course to update in\n    :type course_id: int\n    :param extension_dict: A dictionary that includes the percent of\n        time and a list of canvas user ids.\n\n        Example:\n        {\n            'percent': '300',\n            'user_ids': [\n                '0123456',\n                '1234567',\n                '9867543',\n                '5555555'\n            ]\n        }\n    :type extension_dict: dict\n    "
    job = get_current_job()
    update_job(job, 0, 'Starting...', 'started')
    with app.app_context():
        if (not extension_dict):
            update_job(job, 0, 'Invalid Request', 'failed', error=True)
            logger.warning('Invalid Request: {}'.format(extension_dict))
            return job.meta
        try:
            course_json = get_course(course_id)
        except requests.exceptions.HTTPError:
            update_job(job, 0, 'Course not found.', 'failed', error=True)
            logger.exception('Unable to find course #{}'.format(course_id))
            return job.meta
        course_name = course_json.get('name', '<UNNAMED COURSE>')
        user_ids = extension_dict.get('user_ids', [])
        percent = extension_dict.get('percent', None)
        if (not percent):
            update_job(job, 0, '`percent` field required.', 'failed', error=True)
            logger.warning('Percent field not provided. Request: {}'.format(extension_dict))
            return job.meta
        (course, created) = get_or_create(db.session, Course, canvas_id=course_id)
        course.course_name = course_name
        db.session.commit()
        for user_id in user_ids:
            try:
                canvas_user = get_user(course_id, user_id)
                sortable_name = canvas_user.get('sortable_name', '<MISSING NAME>')
                sis_id = canvas_user.get('sis_user_id')
            except requests.exceptions.HTTPError:
                logger.warning('Unable to find user #{} in course #{}'.format(user_id, course_id))
                continue
            (user, created) = get_or_create(db.session, User, canvas_id=user_id)
            user.sortable_name = sortable_name
            user.sis_id = sis_id
            db.session.commit()
            (extension, created) = get_or_create(db.session, Extension, course_id=course.id, user_id=user.id)
            extension.percent = percent
            db.session.commit()
        quizzes = get_quizzes(course_id)
        num_quizzes = len(quizzes)
        quiz_time_list = []
        unchanged_quiz_time_list = []
        if (num_quizzes < 1):
            update_job(job, 0, 'Sorry, there are no quizzes for this course.', 'failed', error=True)
            logger.warning('No quizzes found for course {}. Unable to update.'.format(course_id))
            return job.meta
        for (index, quiz) in enumerate(quizzes):
            quiz_id = quiz.get('id', None)
            quiz_title = quiz.get('title', '[UNTITLED QUIZ]')
            comp_perc = int(((float(index) / float(num_quizzes)) * 100))
            updating_str = 'Updating quiz #{} - {} [{} of {}]'
            update_job(job, comp_perc, updating_str.format(quiz_id, quiz_title, (index + 1), num_quizzes), 'processing', error=False)
            extension_response = extend_quiz(course_id, quiz, percent, user_ids)
            if (extension_response.get('success', False) is True):
                (quiz_obj, created) = get_or_create(db.session, Quiz, canvas_id=quiz_id, course_id=course.id)
                quiz_obj.title = quiz_title
                quiz_obj.time_limit = quiz.get('time_limit')
                db.session.commit()
                added_time = extension_response.get('added_time', None)
                if (added_time is not None):
                    quiz_time_list.append({'title': quiz_title, 'added_time': added_time})
                else:
                    unchanged_quiz_time_list.append({'title': quiz_title})
            else:
                update_job(job, comp_perc, extension_response.get('message', 'An unknown error occured.'), 'failed', error=True)
                logger.error('Extension failed: {}'.format(extension_response))
                return job.meta
        msg_str = 'Success! {} {} been updated for {} student(s) to have {}% time. {} {} no time limit and were left unchanged.'
        message = msg_str.format(len(quiz_time_list), ('quizzes have' if (len(quiz_time_list) != 1) else 'quiz has'), len(user_ids), percent, len(unchanged_quiz_time_list), ('quizzes have' if (len(unchanged_quiz_time_list) != 1) else 'quiz has'))
        update_job(job, 100, message, 'complete', error=False)
        job.meta['quiz_list'] = quiz_time_list
        job.meta['unchanged_list'] = unchanged_quiz_time_list
        job.save()
        return job.meta
Update time on selected students' quizzes to a specified percentage.

:param course_id: The Canvas ID of the Course to update in
:type course_id: int
:param extension_dict: A dictionary that includes the percent of
    time and a list of canvas user ids.

    Example:
    {
        'percent': '300',
        'user_ids': [
            '0123456',
            '1234567',
            '9867543',
            '5555555'
        ]
    }
:type extension_dict: dict
def update_background(course_id, extension_dict):
    "\n    Update time on selected students' quizzes to a specified percentage.\n\n    :param course_id: The Canvas ID of the Course to update in\n    :type course_id: int\n    :param extension_dict: A dictionary that includes the percent of\n        time and a list of canvas user ids.\n\n        Example:\n        {\n            'percent': '300',\n            'user_ids': [\n                '0123456',\n                '1234567',\n                '9867543',\n                '5555555'\n            ]\n        }\n    :type extension_dict: dict\n    "
    job = get_current_job()
    update_job(job, 0, 'Starting...', 'started')
    with app.app_context():
        if (not extension_dict):
            update_job(job, 0, 'Invalid Request', 'failed', error=True)
            logger.warning('Invalid Request: {}'.format(extension_dict))
            return job.meta
        try:
            course_json = get_course(course_id)
        except requests.exceptions.HTTPError:
            update_job(job, 0, 'Course not found.', 'failed', error=True)
            logger.exception('Unable to find course #{}'.format(course_id))
            return job.meta
        course_name = course_json.get('name', '<UNNAMED COURSE>')
        user_ids = extension_dict.get('user_ids', [])
        percent = extension_dict.get('percent', None)
        if (not percent):
            update_job(job, 0, '`percent` field required.', 'failed', error=True)
            logger.warning('Percent field not provided. Request: {}'.format(extension_dict))
            return job.meta
        (course, created) = get_or_create(db.session, Course, canvas_id=course_id)
        course.course_name = course_name
        db.session.commit()
        for user_id in user_ids:
            try:
                canvas_user = get_user(course_id, user_id)
                sortable_name = canvas_user.get('sortable_name', '<MISSING NAME>')
                sis_id = canvas_user.get('sis_user_id')
            except requests.exceptions.HTTPError:
                logger.warning('Unable to find user #{} in course #{}'.format(user_id, course_id))
                continue
            (user, created) = get_or_create(db.session, User, canvas_id=user_id)
            user.sortable_name = sortable_name
            user.sis_id = sis_id
            db.session.commit()
            (extension, created) = get_or_create(db.session, Extension, course_id=course.id, user_id=user.id)
            extension.percent = percent
            db.session.commit()
        quizzes = get_quizzes(course_id)
        num_quizzes = len(quizzes)
        quiz_time_list = []
        unchanged_quiz_time_list = []
        if (num_quizzes < 1):
            update_job(job, 0, 'Sorry, there are no quizzes for this course.', 'failed', error=True)
            logger.warning('No quizzes found for course {}. Unable to update.'.format(course_id))
            return job.meta
        for (index, quiz) in enumerate(quizzes):
            quiz_id = quiz.get('id', None)
            quiz_title = quiz.get('title', '[UNTITLED QUIZ]')
            comp_perc = int(((float(index) / float(num_quizzes)) * 100))
            updating_str = 'Updating quiz #{} - {} [{} of {}]'
            update_job(job, comp_perc, updating_str.format(quiz_id, quiz_title, (index + 1), num_quizzes), 'processing', error=False)
            extension_response = extend_quiz(course_id, quiz, percent, user_ids)
            if (extension_response.get('success', False) is True):
                (quiz_obj, created) = get_or_create(db.session, Quiz, canvas_id=quiz_id, course_id=course.id)
                quiz_obj.title = quiz_title
                quiz_obj.time_limit = quiz.get('time_limit')
                db.session.commit()
                added_time = extension_response.get('added_time', None)
                if (added_time is not None):
                    quiz_time_list.append({'title': quiz_title, 'added_time': added_time})
                else:
                    unchanged_quiz_time_list.append({'title': quiz_title})
            else:
                update_job(job, comp_perc, extension_response.get('message', 'An unknown error occured.'), 'failed', error=True)
                logger.error('Extension failed: {}'.format(extension_response))
                return job.meta
        msg_str = 'Success! {} {} been updated for {} student(s) to have {}% time. {} {} no time limit and were left unchanged.'
        message = msg_str.format(len(quiz_time_list), ('quizzes have' if (len(quiz_time_list) != 1) else 'quiz has'), len(user_ids), percent, len(unchanged_quiz_time_list), ('quizzes have' if (len(unchanged_quiz_time_list) != 1) else 'quiz has'))
        update_job(job, 100, message, 'complete', error=False)
        job.meta['quiz_list'] = quiz_time_list
        job.meta['unchanged_list'] = unchanged_quiz_time_list
        job.save()
        return job.meta