|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright (c) 2014-2015 Harvard, edX & OpenCraft |
| 4 | +# |
| 5 | +# This software's license gives you freedom; you can copy, convey, |
| 6 | +# propagate, redistribute and/or modify this program under the terms of |
| 7 | +# the GNU Affero General Public License (AGPL) as published by the Free |
| 8 | +# Software Foundation (FSF), either version 3 of the License, or (at your |
| 9 | +# option) any later version of the AGPL published by the FSF. |
| 10 | +# |
| 11 | +# This program is distributed in the hope that it will be useful, but |
| 12 | +# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero |
| 14 | +# General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Affero General Public License |
| 17 | +# along with this program in a file in the toplevel directory called |
| 18 | +# "AGPLv3". If not, see <http://www.gnu.org/licenses/>. |
| 19 | +# |
| 20 | + |
| 21 | +# PURPOSE OF THIS MODULE: |
| 22 | +# problem-builder has a couple dependencies on models in the edx-platform |
| 23 | +# repository. This comes with two challenges: |
| 24 | +# 1. We cannot import from edx-platform during unit tests, because |
| 25 | +# it is not installed into the testing environment. |
| 26 | +# 2. Some edx-platform import paths differ between Open edX releases. |
| 27 | +# In the interest of performing these imports in a consistent way, |
| 28 | +# we centralize the imports here, to be re-imported by other modules. |
| 29 | + |
| 30 | +# pylint: disable=unused-import |
| 31 | + |
| 32 | +try: |
| 33 | + # Koa and earlier: use shortened import path. |
| 34 | + # This will raise a warning in Koa, but that's OK. |
| 35 | + from courseware.models import StudentModule |
| 36 | + from static_replace import replace_static_urls |
| 37 | + from student.models import AnonymousUserId |
| 38 | + from xblock_django.models import XBlockConfiguration |
| 39 | +except Exception: # pylint: disable=broad-except |
| 40 | + # (catch broadly, since the exception could manifest as either an ImportError |
| 41 | + # or an EdxPlatformDeprecatedImportError, the latter of which is not a subclass |
| 42 | + # of the former, and only exists on edx-platform master between Koa and Lilac). |
| 43 | + try: |
| 44 | + # Post-Koa: we must use the full import path. |
| 45 | + from lms.djangoapps.courseware.models import StudentModule |
| 46 | + from common.djangoapps.static_replace import replace_static_urls |
| 47 | + from common.djangoapps.student.models import AnonymousUserId |
| 48 | + from common.djangoapps.xblock_django.models import XBlockConfiguration |
| 49 | + except ImportError: |
| 50 | + # If we get here, we are not running within edx-platform |
| 51 | + # (e.g., we are running problem-builder unit tests). |
| 52 | + StudentModule = None |
| 53 | + replace_static_urls = None |
| 54 | + AnonymousUserId = None |
| 55 | + XBlockConfiguration = None |
0 commit comments