Commit c9b472d2 by John Eskew

Move Model imports down into methods which use the models, since

Django 1.9 no longer allows model imports during app init.
parent 7f2d20cd
......@@ -11,7 +11,6 @@ from xmodule.capa_module import CapaModule
from edxmako.shortcuts import render_to_string
from django.conf import settings
from webob import Response
from .models import TagCategories
_ = lambda text: text
......@@ -29,6 +28,7 @@ class StructuredTagsAside(XBlockAside):
"""
Return available tags
"""
from .models import TagCategories
return TagCategories.objects.all()
def _get_studio_resource_url(self, relative_url):
......
......@@ -5,9 +5,6 @@ from django.contrib.staticfiles.storage import staticfiles_storage
from django.contrib.staticfiles import finders
from django.conf import settings
from static_replace.models import AssetBaseUrlConfig, AssetExcludedExtensionsConfig
from xmodule.modulestore.django import modulestore
from xmodule.modulestore import ModuleStoreEnum
from xmodule.contentstore.content import StaticContent
from opaque_keys.edx.locator import AssetLocator
......@@ -177,6 +174,8 @@ def replace_static_urls(text, data_directory=None, course_id=None, static_asset_
if exists_in_staticfiles_storage:
url = staticfiles_storage.url(rest)
else:
# Import here because models can't be imported at top of module __init__.py.
from static_replace.models import AssetBaseUrlConfig, AssetExcludedExtensionsConfig
# if not, then assume it's courseware specific content and then look in the
# Mongo-backed database
base_url = AssetBaseUrlConfig.get_base_url()
......
"""
Support for converting a django user to an XBlock user
"""
from django.contrib.auth.models import User
from opaque_keys.edx.keys import CourseKey
from xblock.reference.user_service import XBlockUser, UserService
from xblock.reference.user_service import UserService
from student.models import anonymous_id_for_user, get_user_by_username_or_email
ATTR_KEY_IS_AUTHENTICATED = 'edx-platform.is_authenticated'
......@@ -43,6 +42,7 @@ class DjangoXBlockUserService(UserService):
if not self.get_current_user().opt_attrs.get(ATTR_KEY_USER_IS_STAFF):
return None
from django.contrib.auth.models import User
try:
user = get_user_by_username_or_email(username_or_email=username)
except User.DoesNotExist:
......@@ -55,6 +55,7 @@ class DjangoXBlockUserService(UserService):
"""
A function that returns an XBlockUser from the current Django request.user
"""
from xblock.reference.user_service import XBlockUser
xblock_user = XBlockUser(is_current_user=True)
if django_user is not None and django_user.is_authenticated():
......
......@@ -29,7 +29,6 @@ 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
import xblock.reference.plugins
try:
# We may not always have the request_cache module available
......@@ -39,20 +38,6 @@ try:
except ImportError:
HAS_REQUEST_CACHE = False
# We also may not always have the current request user (crum) module available
try:
from xblock_django.user_service import DjangoXBlockUserService
from crum import get_current_user
HAS_USER_SERVICE = True
except ImportError:
HAS_USER_SERVICE = False
try:
from xblock_django.models import XBlockDisableConfig
except ImportError:
XBlockDisableConfig = None
log = logging.getLogger(__name__)
ASSET_IGNORE_REGEX = getattr(settings, "ASSET_IGNORE_REGEX", r"(^\._.*$)|(^\.DS_Store$)|(^.*~$)")
......@@ -180,6 +165,15 @@ def create_modulestore_instance(
if issubclass(class_, BranchSettingMixin):
_options['branch_setting_func'] = _get_modulestore_branch_setting
# We also may not always have the current request user (crum) module available
try:
from xblock_django.user_service import DjangoXBlockUserService
from crum import get_current_user
HAS_USER_SERVICE = True
except ImportError:
HAS_USER_SERVICE = False
if HAS_USER_SERVICE and not user_service:
xb_user_service = DjangoXBlockUserService(get_current_user())
else:
......@@ -188,6 +182,11 @@ def create_modulestore_instance(
if 'read_preference' in doc_store_config:
doc_store_config['read_preference'] = getattr(ReadPreference, doc_store_config['read_preference'])
try:
from xblock_django.models import XBlockDisableConfig
except ImportError:
XBlockDisableConfig = None
if XBlockDisableConfig and settings.FEATURES.get('ENABLE_DISABLING_XBLOCK_TYPES', False):
disabled_xblock_types = XBlockDisableConfig.disabled_block_types()
else:
......@@ -195,6 +194,8 @@ def create_modulestore_instance(
xblock_field_data_wrappers = [load_function(path) for path in settings.XBLOCK_FIELD_DATA_WRAPPERS]
import xblock.reference.plugins
return class_(
contentstore=content_store,
metadata_inheritance_cache_subsystem=metadata_inheritance_cache,
......
......@@ -5,8 +5,6 @@ from django.dispatch.dispatcher import receiver
from xmodule.modulestore.django import SignalHandler
from .models import CourseStructure
@receiver(SignalHandler.course_published)
def listen_for_course_publish(sender, course_key, **kwargs): # pylint: disable=unused-argument
......@@ -16,6 +14,8 @@ def listen_for_course_publish(sender, course_key, **kwargs): # pylint: disable=
# Import tasks here to avoid a circular import.
from .tasks import update_course_structure
from .models import CourseStructure
# Delete the existing discussion id map cache to avoid inconsistencies
try:
structure = CourseStructure.objects.get(course_id=course_key)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment