From 62628f6bd2103257f749330405ffe24572eed1bb Mon Sep 17 00:00:00 2001 From: Xavier Antoviaque Date: Wed, 5 Mar 2014 15:21:11 -0400 Subject: [PATCH 1/2] Only add mentoring application to INSTALLED_APPS when in virtualenv --- cms/envs/common.py | 29 +++++++++++++++++++---------- lms/envs/common.py | 29 +++++++++++++++++++---------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index b914239585..e90d2b2139 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -24,6 +24,7 @@ Longer TODO: # want to import all variables from base settings files # pylint: disable=W0401, W0611, W0614 +import imp import sys import lms.envs.common from lms.envs.common import ( @@ -467,9 +468,6 @@ INSTALLED_APPS = ( # for course creator table 'django.contrib.admin', - # XBlocks containing migrations - 'mentoring', - # for managing course modes 'course_modes', @@ -536,11 +534,22 @@ MAX_FAILED_LOGIN_ATTEMPTS_ALLOWED = 5 MAX_FAILED_LOGIN_ATTEMPTS_LOCKOUT_PERIOD_SECS = 15 * 60 -### JSdraw (only installed in some instances) +### Apps only installed in some instances -try: - import edx_jsdraw -except ImportError: - pass -else: - INSTALLED_APPS += ('edx_jsdraw',) +OPTIONAL_APPS = ( + 'edx_jsdraw', + 'mentoring', +) + +for app_name in OPTIONAL_APPS: + # First attempt to only find the module rather than actually importing it, + # to avoid circular references - only try to import if it can't be found + # by find_module, which doesn't work with import hooks + try: + imp.find_module(app_name) + except ImportError: + try: + __import__(app_name) + except ImportError: + continue + INSTALLED_APPS += (app_name,) diff --git a/lms/envs/common.py b/lms/envs/common.py index d2653ad881..769035b321 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -26,6 +26,7 @@ Longer TODO: import sys import os +import imp import json from path import path @@ -1163,9 +1164,6 @@ INSTALLED_APPS = ( 'reverification', 'embargo', - - # XBlocks containing migrations - 'mentoring', ) ######################### MARKETING SITE ############################### @@ -1447,11 +1445,22 @@ ALL_LANGUAGES = ( ) -### JSdraw (only installed in some instances) +### Apps only installed in some instances -try: - import edx_jsdraw -except ImportError: - pass -else: - INSTALLED_APPS += ('edx_jsdraw',) +OPTIONAL_APPS = ( + 'edx_jsdraw', + 'mentoring', +) + +for app_name in OPTIONAL_APPS: + # First attempt to only find the module rather than actually importing it, + # to avoid circular references - only try to import if it can't be found + # by find_module, which doesn't work with import hooks + try: + imp.find_module(app_name) + except ImportError: + try: + __import__(app_name) + except ImportError: + continue + INSTALLED_APPS += (app_name,) From 76ae57c7ec0021e12750b3f07ca59d9478daa20e Mon Sep 17 00:00:00 2001 From: Xavier Antoviaque Date: Thu, 6 Mar 2014 18:11:36 -0400 Subject: [PATCH 2/2] Update import location of `prefer_xmodules` --- cms/envs/common.py | 3 ++- lms/envs/common.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index e90d2b2139..e9f5455080 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -35,7 +35,8 @@ from path import path from lms.lib.xblock.mixin import LmsBlockMixin from cms.lib.xblock.mixin import CmsBlockMixin from xmodule.modulestore.inheritance import InheritanceMixin -from xmodule.x_module import XModuleMixin, prefer_xmodules +from xmodule.modulestore import prefer_xmodules +from xmodule.x_module import XModuleMixin from dealer.git import git ############################ FEATURE CONFIGURATION ############################# diff --git a/lms/envs/common.py b/lms/envs/common.py index 769035b321..197e677b5f 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -35,7 +35,8 @@ from .discussionsettings import * from lms.lib.xblock.mixin import LmsBlockMixin from xmodule.modulestore.inheritance import InheritanceMixin -from xmodule.x_module import XModuleMixin, prefer_xmodules +from xmodule.modulestore import prefer_xmodules +from xmodule.x_module import XModuleMixin ################################### FEATURES ################################### # The display name of the platform to be used in templates/emails/etc.