From df09e99ad18ed84313f542e7e982438035af785c Mon Sep 17 00:00:00 2001 From: cahrens Date: Thu, 12 Dec 2013 13:43:20 -0500 Subject: [PATCH] Create explicit Locations. Part of STUD-1030 --- common/lib/xmodule/xmodule/modulestore/mongo/base.py | 2 +- .../xmodule/modulestore/tests/test_mixed_modulestore.py | 6 +++--- lms/djangoapps/courseware/tests/test_module_render.py | 2 +- lms/djangoapps/courseware/views.py | 2 +- lms/djangoapps/django_comment_client/utils.py | 3 ++- lms/djangoapps/open_ended_grading/views.py | 5 +++-- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/mongo/base.py b/common/lib/xmodule/xmodule/modulestore/mongo/base.py index 276f7ccdbc..e13c609ab3 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo/base.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo/base.py @@ -724,7 +724,7 @@ class MongoModuleStore(ModuleStoreWriteBase): # @hack! We need to find the course location however, we don't # know the 'name' parameter in this context, so we have # to assume there's only one item in this query even though we are not specifying a name - course_search_location = ['i4x', location.org, location.course, 'course', None] + course_search_location = Location('i4x', location.org, location.course, 'course', None) courses = self.get_items(course_search_location, depth=depth) # make sure we found exactly one match on this above course search diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py index 04ff4bb15c..834e55398c 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mixed_modulestore.py @@ -182,15 +182,15 @@ class TestMixedModuleStore(object): ) def test_get_items(self): - modules = self.store.get_items(['i4x', None, None, 'course', None], IMPORT_COURSEID) + modules = self.store.get_items(Location('i4x', None, None, 'course', None), IMPORT_COURSEID) assert_equals(len(modules), 1) assert_equals(modules[0].location.course, self.import_course) - modules = self.store.get_items(['i4x', None, None, 'course', None], XML_COURSEID1) + modules = self.store.get_items(Location('i4x', None, None, 'course', None), XML_COURSEID1) assert_equals(len(modules), 1) assert_equals(modules[0].location.course, 'toy') - modules = self.store.get_items(['i4x', None, None, 'course', None], XML_COURSEID2) + modules = self.store.get_items(Location('i4x', None, None, 'course', None), XML_COURSEID2) assert_equals(len(modules), 1) assert_equals(modules[0].location.course, 'simple') diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py index 649ad3c8ad..ea40b19e81 100644 --- a/lms/djangoapps/courseware/tests/test_module_render.py +++ b/lms/djangoapps/courseware/tests/test_module_render.py @@ -79,7 +79,7 @@ class ModuleRenderTestCase(ModuleStoreTestCase, LoginEnrollmentTestCase): module = render.get_module( self.mock_user, mock_request, - ['i4x', 'edX', 'toy', 'html', 'toyjumpto'], + Location('i4x', 'edX', 'toy', 'html', 'toyjumpto'), field_data_cache, self.course_id ) diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index fcf1226295..137b529169 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -388,7 +388,7 @@ def jump_to_id(request, course_id, module_id): course_location = CourseDescriptor.id_to_location(course_id) items = modulestore().get_items( - ['i4x', course_location.org, course_location.course, None, module_id], + Location('i4x', course_location.org, course_location.course, None, module_id), course_id=course_id ) diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index a92797f7e6..7ec6786f1e 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -16,6 +16,7 @@ import edxmako import pystache_custom as pystache from xmodule.modulestore.django import modulestore +from xmodule.modulestore import Location from django.utils.timezone import UTC log = logging.getLogger(__name__) @@ -56,7 +57,7 @@ def has_forum_access(uname, course_id, rolename): def _get_discussion_modules(course): all_modules = modulestore().get_items( - ['i4x', course.location.org, course.location.course, 'discussion', None], + Location('i4x', course.location.org, course.location.course, 'discussion', None), course_id=course.id ) diff --git a/lms/djangoapps/open_ended_grading/views.py b/lms/djangoapps/open_ended_grading/views.py index 383187bbb9..02fb287905 100644 --- a/lms/djangoapps/open_ended_grading/views.py +++ b/lms/djangoapps/open_ended_grading/views.py @@ -16,7 +16,8 @@ import open_ended_notifications from xmodule.modulestore.django import modulestore from xmodule.modulestore import search -from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem +from xmodule.modulestore import Location +from xmodule.modulestore.exceptions import NoPathToItem from django.http import HttpResponse, Http404, HttpResponseRedirect from edxmako.shortcuts import render_to_string @@ -92,7 +93,7 @@ def find_peer_grading_module(course): # Get the course id and split it. course_id_parts = course.id.split("/") # Get the peer grading modules currently in the course. Explicitly specify the course id to avoid issues with different runs. - items = modulestore().get_items(['i4x', course_id_parts[0], course_id_parts[1], 'peergrading', None], + items = modulestore().get_items(Location('i4x', course_id_parts[0], course_id_parts[1], 'peergrading', None), course_id=course.id) #See if any of the modules are centralized modules (ie display info from multiple problems) items = [i for i in items if not getattr(i, "use_for_single_location", True)]