From 1840fe7f0643c33b2d7867d7d40db3f997a7c1af Mon Sep 17 00:00:00 2001 From: Nimisha Asthagiri Date: Tue, 27 Jan 2015 21:54:19 -0500 Subject: [PATCH] Mobile API: use bulk_operation context manager. --- lms/djangoapps/mobile_api/utils.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lms/djangoapps/mobile_api/utils.py b/lms/djangoapps/mobile_api/utils.py index 5905fc886d..cd7720f8a3 100644 --- a/lms/djangoapps/mobile_api/utils.py +++ b/lms/djangoapps/mobile_api/utils.py @@ -5,11 +5,13 @@ Common utility methods and decorators for Mobile APIs. import functools -from opaque_keys.edx.keys import CourseKey -from courseware.courses import get_course_with_access from rest_framework import permissions from rest_framework.authentication import OAuth2Authentication, SessionAuthentication +from opaque_keys.edx.keys import CourseKey +from xmodule.modulestore.django import modulestore +from courseware.courses import get_course_with_access + def mobile_course_access(depth=0, verify_enrolled=True): """ @@ -25,13 +27,14 @@ def mobile_course_access(depth=0, verify_enrolled=True): Raises 404 if access to course is disallowed. """ course_id = CourseKey.from_string(kwargs.pop('course_id')) - course = get_course_with_access( - request.user, - 'load_mobile' if verify_enrolled else 'load_mobile_no_enrollment_check', - course_id, - depth=depth - ) - return func(self, request, course=course, *args, **kwargs) + with modulestore().bulk_operations(course_id): + course = get_course_with_access( + request.user, + 'load_mobile' if verify_enrolled else 'load_mobile_no_enrollment_check', + course_id, + depth=depth + ) + return func(self, request, course=course, *args, **kwargs) return _wrapper return _decorator