From 593c2d1ae8335fa618f60dac7e3336d7bcac8e61 Mon Sep 17 00:00:00 2001 From: noraiz-anwar <noraizbhatti@gmail.com> Date: Fri, 13 Jul 2018 11:03:05 +0500 Subject: [PATCH] add python getter in capa system --- cms/djangoapps/contentstore/management/commands/import.py | 2 +- cms/djangoapps/contentstore/tests/test_course_settings.py | 2 +- cms/djangoapps/contentstore/views/preview.py | 2 +- common/djangoapps/util/tests/test_sandboxing.py | 2 +- common/lib/xmodule/xmodule/capa_module.py | 5 +++-- common/lib/xmodule/xmodule/modulestore/django.py | 2 +- common/lib/xmodule/xmodule/modulestore/tests/django_utils.py | 2 +- common/lib/xmodule/xmodule/tests/test_utils_django.py | 2 +- .../{djangoapps => lib/xmodule/xmodule}/util/sandboxing.py | 4 ++-- .../xmodule/xmodule/util/{django.py => xmodule_django.py} | 0 lms/djangoapps/courseware/access_utils.py | 2 +- lms/djangoapps/courseware/module_render.py | 2 +- lms/djangoapps/dashboard/git_import.py | 2 +- 13 files changed, 15 insertions(+), 14 deletions(-) rename common/{djangoapps => lib/xmodule/xmodule}/util/sandboxing.py (95%) rename common/lib/xmodule/xmodule/util/{django.py => xmodule_django.py} (100%) diff --git a/cms/djangoapps/contentstore/management/commands/import.py b/cms/djangoapps/contentstore/management/commands/import.py index 57d8c0a0a22..1928fd8caae 100644 --- a/cms/djangoapps/contentstore/management/commands/import.py +++ b/cms/djangoapps/contentstore/management/commands/import.py @@ -3,10 +3,10 @@ Script for importing courseware from XML format """ from django.core.management.base import BaseCommand from django_comment_common.utils import are_permissions_roles_seeded, seed_permissions_roles -from lms.djangoapps.dashboard.git_import import DEFAULT_PYTHON_LIB_FILENAME from xmodule.contentstore.django import contentstore from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.django import modulestore +from xmodule.util.sandboxing import DEFAULT_PYTHON_LIB_FILENAME from xmodule.modulestore.xml_importer import import_course_from_xml diff --git a/cms/djangoapps/contentstore/tests/test_course_settings.py b/cms/djangoapps/contentstore/tests/test_course_settings.py index 60defed4ec6..c7a03d94de6 100644 --- a/cms/djangoapps/contentstore/tests/test_course_settings.py +++ b/cms/djangoapps/contentstore/tests/test_course_settings.py @@ -1149,7 +1149,7 @@ class CourseMetadataEditingTest(CourseTestCase): self.assertEqual(tab_list, course.tabs) @patch.dict(settings.FEATURES, {'ENABLE_EDXNOTES': True}) - @patch('xmodule.util.django.get_current_request') + @patch('xmodule.util.xmodule_django.get_current_request') def test_post_settings_with_staff_not_enrolled(self, mock_request): """ Tests that we can post advance settings when course staff is not enrolled. diff --git a/cms/djangoapps/contentstore/views/preview.py b/cms/djangoapps/contentstore/views/preview.py index d43eeba3e58..926fce6f54b 100644 --- a/cms/djangoapps/contentstore/views/preview.py +++ b/cms/djangoapps/contentstore/views/preview.py @@ -29,7 +29,7 @@ from openedx.core.lib.xblock_utils import ( wrap_xblock_aside, xblock_local_resource_url ) -from util.sandboxing import can_execute_unsafe_code, get_python_lib_zip +from xmodule.util.sandboxing import can_execute_unsafe_code, get_python_lib_zip from xblock_config.models import StudioConfig from xblock_django.user_service import DjangoXBlockUserService from xmodule.contentstore.django import contentstore diff --git a/common/djangoapps/util/tests/test_sandboxing.py b/common/djangoapps/util/tests/test_sandboxing.py index 2dd9ae6c609..1a98ff751f7 100644 --- a/common/djangoapps/util/tests/test_sandboxing.py +++ b/common/djangoapps/util/tests/test_sandboxing.py @@ -7,7 +7,7 @@ from django.test.utils import override_settings from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import CourseLocator, LibraryLocator -from util.sandboxing import can_execute_unsafe_code +from xmodule.util.sandboxing import can_execute_unsafe_code class SandboxingTest(TestCase): diff --git a/common/lib/xmodule/xmodule/capa_module.py b/common/lib/xmodule/xmodule/capa_module.py index 2c9e73d101b..9fe0dae734b 100644 --- a/common/lib/xmodule/xmodule/capa_module.py +++ b/common/lib/xmodule/xmodule/capa_module.py @@ -11,7 +11,9 @@ import dogstats_wrapper as dog_stats_api from capa import responsetypes from xmodule.exceptions import NotFoundError, ProcessingError from xmodule.raw_module import RawDescriptor +from xmodule.contentstore.django import contentstore from xmodule.util.misc import escape_html_characters +from xmodule.util.sandboxing import get_python_lib_zip from xmodule.x_module import DEPRECATION_VSCOMPAT_EVENT, XModule, module_attr from .capa_base import CapaFields, CapaMixin, ComplexEncoder @@ -331,7 +333,6 @@ class CapaDescriptor(CapaFields, RawDescriptor): if limit_responses == 0: # Don't even start collecting answers return - capa_system = LoncapaSystem( ajax_url=None, # TODO set anonymous_student_id to the anonymous ID of the user which answered each problem @@ -341,7 +342,7 @@ class CapaDescriptor(CapaFields, RawDescriptor): anonymous_student_id=None, cache=None, can_execute_unsafe_code=lambda: None, - get_python_lib_zip=lambda: None, + get_python_lib_zip=(lambda: get_python_lib_zip(contentstore, self.runtime.course_id)), DEBUG=None, filestore=self.runtime.resources_fs, i18n=self.runtime.service(self, "i18n"), diff --git a/common/lib/xmodule/xmodule/modulestore/django.py b/common/lib/xmodule/xmodule/modulestore/django.py index 2bdad9ffa29..5fb1f9921f8 100644 --- a/common/lib/xmodule/xmodule/modulestore/django.py +++ b/common/lib/xmodule/xmodule/modulestore/django.py @@ -28,7 +28,7 @@ from openedx.core.djangoapps.request_cache.middleware import RequestCache from xmodule.contentstore.django import contentstore from xmodule.modulestore.draft_and_published import BranchSettingMixin from xmodule.modulestore.mixed import MixedModuleStore -from xmodule.util.django import get_current_request_hostname +from xmodule.util.xmodule_django import get_current_request_hostname # We also may not always have the current request user (crum) module available try: diff --git a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py index 7555f909fa8..5e4dbe5a5ab 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/django_utils.py @@ -271,7 +271,7 @@ class ModuleStoreIsolationMixin(CacheIsolationMixin, SignalIsolationMixin): # List of modulestore signals enabled for this test. Defaults to an empty # list. The list of signals available is found on the SignalHandler class, - # in /common/lib/xmodule/xmodule/modulestore/django.py + # in /common/lib/xmodule/xmodule/modulestore/xmodule_django.py # # You must use the signal itself, and not its name. So for example: # diff --git a/common/lib/xmodule/xmodule/tests/test_utils_django.py b/common/lib/xmodule/xmodule/tests/test_utils_django.py index 29d2c485134..f79d3b5a042 100644 --- a/common/lib/xmodule/xmodule/tests/test_utils_django.py +++ b/common/lib/xmodule/xmodule/tests/test_utils_django.py @@ -1,5 +1,5 @@ """Tests for methods defined in util/django.py""" -from xmodule.util.django import get_current_request, get_current_request_hostname +from xmodule.util.xmodule_django import get_current_request, get_current_request_hostname from nose.tools import assert_is_none from unittest import TestCase diff --git a/common/djangoapps/util/sandboxing.py b/common/lib/xmodule/xmodule/util/sandboxing.py similarity index 95% rename from common/djangoapps/util/sandboxing.py rename to common/lib/xmodule/xmodule/util/sandboxing.py index 9a2127be4f1..b68fb75b8b8 100644 --- a/common/djangoapps/util/sandboxing.py +++ b/common/lib/xmodule/xmodule/util/sandboxing.py @@ -1,7 +1,7 @@ import re - from django.conf import settings -from lms.djangoapps.dashboard.git_import import DEFAULT_PYTHON_LIB_FILENAME + +DEFAULT_PYTHON_LIB_FILENAME = 'python_lib.zip' def can_execute_unsafe_code(course_id): diff --git a/common/lib/xmodule/xmodule/util/django.py b/common/lib/xmodule/xmodule/util/xmodule_django.py similarity index 100% rename from common/lib/xmodule/xmodule/util/django.py rename to common/lib/xmodule/xmodule/util/xmodule_django.py diff --git a/lms/djangoapps/courseware/access_utils.py b/lms/djangoapps/courseware/access_utils.py index e0def5cebd8..1c69d88d6a1 100644 --- a/lms/djangoapps/courseware/access_utils.py +++ b/lms/djangoapps/courseware/access_utils.py @@ -13,7 +13,7 @@ from courseware.access_response import AccessResponse, StartDateError from courseware.masquerade import is_masquerading_as_student from openedx.features.course_experience import COURSE_PRE_START_ACCESS_FLAG from student.roles import CourseBetaTesterRole -from xmodule.util.django import get_current_request_hostname +from xmodule.util.xmodule_django import get_current_request_hostname DEBUG_ACCESS = False log = getLogger(__name__) diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index dd38fa8af94..e11f9b7f1e3 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -69,7 +69,7 @@ from track import contexts from util import milestones_helpers from util.json_request import JsonResponse from django.utils.text import slugify -from util.sandboxing import can_execute_unsafe_code, get_python_lib_zip +from xmodule.util.sandboxing import can_execute_unsafe_code, get_python_lib_zip from xblock_django.user_service import DjangoXBlockUserService from xmodule.contentstore.django import contentstore from xmodule.error_module import ErrorDescriptor, NonStaffErrorDescriptor diff --git a/lms/djangoapps/dashboard/git_import.py b/lms/djangoapps/dashboard/git_import.py index 347cfdec548..990cfc92efd 100644 --- a/lms/djangoapps/dashboard/git_import.py +++ b/lms/djangoapps/dashboard/git_import.py @@ -15,6 +15,7 @@ from django.core import management from django.core.management.base import CommandError from django.utils import timezone from django.utils.translation import ugettext_lazy as _ +from xmodule.util.sandboxing import DEFAULT_PYTHON_LIB_FILENAME from opaque_keys.edx.keys import CourseKey from dashboard.models import CourseImportLog @@ -22,7 +23,6 @@ from dashboard.models import CourseImportLog log = logging.getLogger(__name__) DEFAULT_GIT_REPO_DIR = '/edx/var/app/edxapp/course_repos' -DEFAULT_PYTHON_LIB_FILENAME = 'python_lib.zip' class GitImportError(Exception): -- GitLab