
from __future__ import absolute_import

from importlib import import_module

from django.conf import settings

_MODULESTORES = {}

FUNCTION_KEYS = ['render_template']


def load_function(path):
    """
    Load a function by name.

    path is a string of the form "path.to.module.function"
    returns the imported python object `function` from `path.to.module`
    """
    module_path, _, name = path.rpartition('.')
    return getattr(import_module(module_path), name)


def modulestore(name='default'):
    global _MODULESTORES

    if name not in _MODULESTORES:
        class_ = load_function(settings.MODULESTORE[name]['ENGINE'])

        options = {}
        options.update(settings.MODULESTORE[name]['OPTIONS'])
        for key in FUNCTION_KEYS:
            if key in options:
                options[key] = load_function(options[key])

        _MODULESTORES[name] = class_(
            **options
        )

    return _MODULESTORES[name]

# Initialize the modulestores immediately
for store_name in settings.MODULESTORE:
    modulestore(store_name)


from __future__ import absolute_import
from importlib import import_module
from os import environ

from django.conf import settings

_MODULESTORES = {}

FUNCTION_KEYS = ['render_template']


def load_function(path):
    """
    Load a function by name.

    path is a string of the form "path.to.module.function"
    returns the imported python object `function` from `path.to.module`
    """
    module_path, _, name = path.rpartition('.')
    return getattr(import_module(module_path), name)


def modulestore(name='default'):
    global _MODULESTORES

    if name not in _MODULESTORES:
        class_ = load_function(settings.MODULESTORE[name]['ENGINE'])

        options = {}
        options.update(settings.MODULESTORE[name]['OPTIONS'])
        for key in FUNCTION_KEYS:
            if key in options:
                options[key] = load_function(options[key])

        _MODULESTORES[name] = class_(
            **options
        )

    return _MODULESTORES[name]

if 'DJANGO_SETTINGS_MODULE' in environ:
    # Initialize the modulestores immediately
    for store_name in settings.MODULESTORE:
        modulestore(store_name)

Put quick check so we don't load course modules on init unless we're actually running in Django
Put quick check so we don't load course modules on init unless we're actually running in Django

  
  from __future__ import absolute_import
- 
  from importlib import import_module
+ from os import environ
  
  from django.conf import settings
  
  _MODULESTORES = {}
  
  FUNCTION_KEYS = ['render_template']
  
  
  def load_function(path):
      """
      Load a function by name.
  
      path is a string of the form "path.to.module.function"
      returns the imported python object `function` from `path.to.module`
      """
      module_path, _, name = path.rpartition('.')
      return getattr(import_module(module_path), name)
  
  
  def modulestore(name='default'):
      global _MODULESTORES
  
      if name not in _MODULESTORES:
          class_ = load_function(settings.MODULESTORE[name]['ENGINE'])
  
          options = {}
          options.update(settings.MODULESTORE[name]['OPTIONS'])
          for key in FUNCTION_KEYS:
              if key in options:
                  options[key] = load_function(options[key])
  
          _MODULESTORES[name] = class_(
              **options
          )
  
      return _MODULESTORES[name]
  
+ if 'DJANGO_SETTINGS_MODULE' in environ:
- # Initialize the modulestores immediately
+     # Initialize the modulestores immediately
- for store_name in settings.MODULESTORE:
+     for store_name in settings.MODULESTORE:
-     modulestore(store_name)
+         modulestore(store_name)
  
Put quick check so we don't load course modules on init unless we're actually running in Django
## Code Before:

from __future__ import absolute_import

from importlib import import_module

from django.conf import settings

_MODULESTORES = {}

FUNCTION_KEYS = ['render_template']


def load_function(path):
    """
    Load a function by name.

    path is a string of the form "path.to.module.function"
    returns the imported python object `function` from `path.to.module`
    """
    module_path, _, name = path.rpartition('.')
    return getattr(import_module(module_path), name)


def modulestore(name='default'):
    global _MODULESTORES

    if name not in _MODULESTORES:
        class_ = load_function(settings.MODULESTORE[name]['ENGINE'])

        options = {}
        options.update(settings.MODULESTORE[name]['OPTIONS'])
        for key in FUNCTION_KEYS:
            if key in options:
                options[key] = load_function(options[key])

        _MODULESTORES[name] = class_(
            **options
        )

    return _MODULESTORES[name]

# Initialize the modulestores immediately
for store_name in settings.MODULESTORE:
    modulestore(store_name)

## Instruction:
Put quick check so we don't load course modules on init unless we're actually running in Django
## Code After:

from __future__ import absolute_import
from importlib import import_module
from os import environ

from django.conf import settings

_MODULESTORES = {}

FUNCTION_KEYS = ['render_template']


def load_function(path):
    """
    Load a function by name.

    path is a string of the form "path.to.module.function"
    returns the imported python object `function` from `path.to.module`
    """
    module_path, _, name = path.rpartition('.')
    return getattr(import_module(module_path), name)


def modulestore(name='default'):
    global _MODULESTORES

    if name not in _MODULESTORES:
        class_ = load_function(settings.MODULESTORE[name]['ENGINE'])

        options = {}
        options.update(settings.MODULESTORE[name]['OPTIONS'])
        for key in FUNCTION_KEYS:
            if key in options:
                options[key] = load_function(options[key])

        _MODULESTORES[name] = class_(
            **options
        )

    return _MODULESTORES[name]

if 'DJANGO_SETTINGS_MODULE' in environ:
    # Initialize the modulestores immediately
    for store_name in settings.MODULESTORE:
        modulestore(store_name)
