Commit 7c923355 by Douglas Hall

Remove gating api import from course xmodule to avoid importing django related…

Remove gating api import from course xmodule to avoid importing django related code into non-django related code
parent 30b5cebc
......@@ -780,6 +780,10 @@ def _get_gating_info(course, xblock):
"""
info = {}
if xblock.category == 'sequential' and course.enable_subsection_gating:
if not hasattr(course, 'gating_prerequisites'):
# Cache gating prerequisites on course module so that we are not
# hitting the database for every xblock in the course
setattr(course, 'gating_prerequisites', gating_api.get_prerequisites(course.id)) # pylint: disable=literal-used-as-attribute
info["is_prereq"] = gating_api.is_prerequisite(course.id, xblock.location)
info["prereqs"] = [
p for p in course.gating_prerequisites if unicode(xblock.location) not in p['namespace']
......
......@@ -108,7 +108,7 @@ class TestSubsectionGating(CourseTestCase):
''
)
@patch('xmodule.course_module.gating_api.get_prerequisites')
@patch('contentstore.views.item.gating_api.get_prerequisites')
@patch('contentstore.views.item.gating_api.get_required_content')
@patch('contentstore.views.item.gating_api.is_prerequisite')
def test_get_prerequisite(self, mock_is_prereq, mock_get_required_content, mock_get_prereqs):
......
......@@ -14,7 +14,6 @@ from path import Path as path
from xblock.core import XBlock
from xblock.fields import Scope, List, String, Dict, Boolean, Integer, Float
from openedx.core.lib.gating import api as gating_api
from xmodule import course_metadata_utils
from xmodule.course_metadata_utils import DEFAULT_START_DATE
from xmodule.exceptions import UndefinedContext
......@@ -1395,18 +1394,6 @@ class CourseDescriptor(CourseFields, SequenceDescriptor, LicenseMixin):
"""
return datetime.now(UTC()) <= self.start
@property
def gating_prerequisites(self):
"""
Course content that can be used to gate other course content within this course.
Returns:
list: Returns a list of dicts containing the gating milestone data
"""
if not self._gating_prerequisites:
self._gating_prerequisites = gating_api.get_prerequisites(self.id)
return self._gating_prerequisites
class CourseSummary(object):
"""
......
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