From f1369b912eb90da8f56cb2899ca20791b446eed4 Mon Sep 17 00:00:00 2001 From: John Eskew Date: Tue, 23 May 2017 17:58:54 -0400 Subject: [PATCH] Move LicenseMixin and accompanying code to openedx/core/lib. --- cms/djangoapps/contentstore/views/preview.py | 2 +- cms/envs/common.py | 3 ++- common/lib/xmodule/xmodule/course_module.py | 2 +- .../xmodule/xmodule/video_module/video_module.py | 2 +- lms/djangoapps/courseware/module_render.py | 2 +- lms/envs/common.py | 3 ++- openedx/core/lib/license/__init__.py | 2 ++ .../xmodule => openedx/core/lib/license}/mixin.py | 13 +------------ .../core/lib/license}/templates/license.html | 0 .../lib/license}/templates/license_wrapper.html | 0 openedx/core/lib/license/wrapper.py | 14 ++++++++++++++ 11 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 openedx/core/lib/license/__init__.py rename {common/lib/xmodule/xmodule => openedx/core/lib/license}/mixin.py (82%) rename {common => openedx/core/lib/license}/templates/license.html (100%) rename {common => openedx/core/lib/license}/templates/license_wrapper.html (100%) create mode 100644 openedx/core/lib/license/wrapper.py diff --git a/cms/djangoapps/contentstore/views/preview.py b/cms/djangoapps/contentstore/views/preview.py index a10e263856..65694915b3 100644 --- a/cms/djangoapps/contentstore/views/preview.py +++ b/cms/djangoapps/contentstore/views/preview.py @@ -15,6 +15,7 @@ from django.utils.translation import ugettext as _ from edxmako.shortcuts import render_to_string from lms.djangoapps.lms_xblock.field_data import LmsFieldData from opaque_keys.edx.keys import UsageKey +from openedx.core.lib.license import wrap_with_license from openedx.core.lib.partitions.partitions_service import PartitionService from openedx.core.lib.xblock_utils import ( replace_static_urls, @@ -34,7 +35,6 @@ from xblock_django.user_service import DjangoXBlockUserService from xmodule.contentstore.django import contentstore from xmodule.error_module import ErrorDescriptor from xmodule.exceptions import NotFoundError, ProcessingError -from xmodule.mixin import wrap_with_license from xmodule.modulestore.django import ModuleI18nService, modulestore from xmodule.services import SettingsService from xmodule.studio_editable import has_author_view diff --git a/cms/envs/common.py b/cms/envs/common.py index 3593c00fc7..2777132278 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -106,7 +106,7 @@ from lms.djangoapps.lms_xblock.mixin import LmsBlockMixin from cms.lib.xblock.authoring_mixin import AuthoringMixin import dealer.git from xmodule.modulestore.edit_info import EditInfoMixin -from xmodule.mixin import LicenseMixin +from openedx.core.lib.license import LicenseMixin ############################ FEATURE CONFIGURATION ############################# @@ -280,6 +280,7 @@ MAKO_TEMPLATES['main'] = [ COMMON_ROOT / 'static', # required to statically include common Underscore templates OPENEDX_ROOT / 'core' / 'djangoapps' / 'cors_csrf' / 'templates', OPENEDX_ROOT / 'core' / 'djangoapps' / 'dark_lang' / 'templates', + OPENEDX_ROOT / 'core' / 'lib' / 'license' / 'templates', CMS_ROOT / 'djangoapps' / 'pipeline_js' / 'templates', ] diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 8ee3776a7d..a209249c1f 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -16,7 +16,7 @@ from pytz import utc from xblock.fields import Boolean, Dict, Float, Integer, List, Scope, String from xmodule import course_metadata_utils from xmodule.graders import grader_from_conf -from xmodule.mixin import LicenseMixin +from openedx.core.lib.license import LicenseMixin from xmodule.seq_module import SequenceDescriptor, SequenceModule from xmodule.tabs import CourseTabList, InvalidTabsException diff --git a/common/lib/xmodule/xmodule/video_module/video_module.py b/common/lib/xmodule/xmodule/video_module/video_module.py index cc384f3802..ac22e978b5 100644 --- a/common/lib/xmodule/xmodule/video_module/video_module.py +++ b/common/lib/xmodule/xmodule/video_module/video_module.py @@ -46,7 +46,7 @@ from .video_xfields import VideoFields from .video_handlers import VideoStudentViewHandlers, VideoStudioViewHandlers from xmodule.video_module import manage_video_subtitles_save -from xmodule.mixin import LicenseMixin +from openedx.core.lib.license import LicenseMixin # The following import/except block for edxval is temporary measure until # edxval is a proper XBlock Runtime Service. diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 3a276749cc..c34b744fe6 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -76,7 +76,7 @@ from xmodule.contentstore.django import contentstore from xmodule.error_module import ErrorDescriptor, NonStaffErrorDescriptor from xmodule.exceptions import NotFoundError, ProcessingError from xmodule.lti_module import LTIModule -from xmodule.mixin import wrap_with_license +from openedx.core.lib.license import wrap_with_license from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.x_module import XModuleDescriptor diff --git a/lms/envs/common.py b/lms/envs/common.py index 543271b61b..9732fbc353 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -40,7 +40,7 @@ from django.utils.translation import ugettext_lazy as _ from .discussionsettings import * from xmodule.modulestore.modulestore_settings import update_module_store_settings from xmodule.modulestore.edit_info import EditInfoMixin -from xmodule.mixin import LicenseMixin +from openedx.core.lib.license import LicenseMixin from lms.djangoapps.lms_xblock.mixin import LmsBlockMixin ################################### FEATURES ################################### @@ -502,6 +502,7 @@ MAKO_TEMPLATES['main'] = [ COMMON_ROOT / 'djangoapps' / 'pipeline_mako' / 'templates', OPENEDX_ROOT / 'core' / 'djangoapps' / 'cors_csrf' / 'templates', OPENEDX_ROOT / 'core' / 'djangoapps' / 'dark_lang' / 'templates', + OPENEDX_ROOT / 'core' / 'lib' / 'license' / 'templates', ] # Django templating diff --git a/openedx/core/lib/license/__init__.py b/openedx/core/lib/license/__init__.py new file mode 100644 index 0000000000..ab669fd620 --- /dev/null +++ b/openedx/core/lib/license/__init__.py @@ -0,0 +1,2 @@ +from .wrapper import wrap_with_license +from .mixin import LicenseMixin diff --git a/common/lib/xmodule/xmodule/mixin.py b/openedx/core/lib/license/mixin.py similarity index 82% rename from common/lib/xmodule/xmodule/mixin.py rename to openedx/core/lib/license/mixin.py index 1447f41342..49342e573e 100644 --- a/common/lib/xmodule/xmodule/mixin.py +++ b/openedx/core/lib/license/mixin.py @@ -1,5 +1,5 @@ """ -Reusable mixins for XBlocks and/or XModules +License mixin for XBlocks and XModules """ from xblock.fields import Scope, String, XBlockMixin @@ -51,14 +51,3 @@ class LicenseMixin(XBlockMixin): """ if getattr(self, "license", default): node.set('license', self.license) - - -def wrap_with_license(block, view, frag, context): # pylint: disable=unused-argument - """ - In the LMS, display the custom license underneath the XBlock. - """ - license = getattr(block, "license", None) # pylint: disable=redefined-builtin - if license: - context = {"license": license} - frag.content += block.runtime.render_template('license_wrapper.html', context) - return frag diff --git a/common/templates/license.html b/openedx/core/lib/license/templates/license.html similarity index 100% rename from common/templates/license.html rename to openedx/core/lib/license/templates/license.html diff --git a/common/templates/license_wrapper.html b/openedx/core/lib/license/templates/license_wrapper.html similarity index 100% rename from common/templates/license_wrapper.html rename to openedx/core/lib/license/templates/license_wrapper.html diff --git a/openedx/core/lib/license/wrapper.py b/openedx/core/lib/license/wrapper.py new file mode 100644 index 0000000000..2d17015408 --- /dev/null +++ b/openedx/core/lib/license/wrapper.py @@ -0,0 +1,14 @@ +""" +Code to wrap web fragments with a license. +""" + + +def wrap_with_license(block, view, frag, context): # pylint: disable=unused-argument + """ + In the LMS, display the custom license underneath the XBlock. + """ + license = getattr(block, "license", None) # pylint: disable=redefined-builtin + if license: + context = {"license": license} + frag.content += block.runtime.render_template('license_wrapper.html', context) + return frag