Commit 6da7bff1 by Calen Pennington

Allow test_mixed_modulestore to be run without django setup

parent 92eadf1a
...@@ -315,7 +315,8 @@ class BulkOperationsMixin(object): ...@@ -315,7 +315,8 @@ class BulkOperationsMixin(object):
Sends out the signal that items have been published from within this course. Sends out the signal that items have been published from within this course.
""" """
if self.signal_handler and bulk_ops_record.has_publish_item: if self.signal_handler and bulk_ops_record.has_publish_item:
self.signal_handler.send("course_published", course_key=course_id) # We remove the branch, because publishing always means copying from draft to published
self.signal_handler.send("course_published", course_key=course_id.for_branch(None))
bulk_ops_record.has_publish_item = False bulk_ops_record.has_publish_item = False
def send_bulk_library_updated_signal(self, bulk_ops_record, library_id): def send_bulk_library_updated_signal(self, bulk_ops_record, library_id):
...@@ -1345,22 +1346,6 @@ class ModuleStoreWriteBase(ModuleStoreReadBase, ModuleStoreWrite): ...@@ -1345,22 +1346,6 @@ class ModuleStoreWriteBase(ModuleStoreReadBase, ModuleStoreWrite):
parent.children.append(item.location) parent.children.append(item.location)
self.update_item(parent, user_id) self.update_item(parent, user_id)
def _flag_publish_event(self, course_key):
"""
Wrapper around calls to fire the course_published signal
Unless we're nested in an active bulk operation, this simply fires the signal
otherwise a publish will be signalled at the end of the bulk operation
Arguments:
course_key - course_key to which the signal applies
"""
if self.signal_handler:
bulk_record = self._get_bulk_ops_record(course_key) if isinstance(self, BulkOperationsMixin) else None
if bulk_record and bulk_record.active:
bulk_record.has_publish_item = True
else:
self.signal_handler.send("course_published", course_key=course_key)
def _flag_library_updated_event(self, library_key): def _flag_library_updated_event(self, library_key):
""" """
Wrapper around calls to fire the library_updated signal Wrapper around calls to fire the library_updated signal
......
...@@ -5,7 +5,7 @@ This module provides an abstraction for Module Stores that support Draft and Pub ...@@ -5,7 +5,7 @@ This module provides an abstraction for Module Stores that support Draft and Pub
import threading import threading
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from contextlib import contextmanager from contextlib import contextmanager
from . import ModuleStoreEnum from . import ModuleStoreEnum, BulkOperationsMixin
# Things w/ these categories should never be marked as version=DRAFT # Things w/ these categories should never be marked as version=DRAFT
DIRECT_ONLY_CATEGORIES = ['course', 'chapter', 'sequential', 'about', 'static_tab', 'course_info'] DIRECT_ONLY_CATEGORIES = ['course', 'chapter', 'sequential', 'about', 'static_tab', 'course_info']
...@@ -62,7 +62,7 @@ class BranchSettingMixin(object): ...@@ -62,7 +62,7 @@ class BranchSettingMixin(object):
return self.default_branch_setting_func() return self.default_branch_setting_func()
class ModuleStoreDraftAndPublished(BranchSettingMixin): class ModuleStoreDraftAndPublished(BranchSettingMixin, BulkOperationsMixin):
""" """
A mixin for a read-write database backend that supports two branches, Draft and Published, with A mixin for a read-write database backend that supports two branches, Draft and Published, with
options to prefer Draft and fallback to Published. options to prefer Draft and fallback to Published.
...@@ -112,6 +112,23 @@ class ModuleStoreDraftAndPublished(BranchSettingMixin): ...@@ -112,6 +112,23 @@ class ModuleStoreDraftAndPublished(BranchSettingMixin):
""" """
raise NotImplementedError raise NotImplementedError
def _flag_publish_event(self, course_key):
"""
Wrapper around calls to fire the course_published signal
Unless we're nested in an active bulk operation, this simply fires the signal
otherwise a publish will be signalled at the end of the bulk operation
Arguments:
course_key - course_key to which the signal applies
"""
if self.signal_handler:
bulk_record = self._get_bulk_ops_record(course_key) if isinstance(self, BulkOperationsMixin) else None
if bulk_record and bulk_record.active:
bulk_record.has_publish_item = True
else:
# We remove the branch, because publishing always means copying from draft to published
self.signal_handler.send("course_published", course_key=course_key.for_branch(None))
class UnsupportedRevisionError(ValueError): class UnsupportedRevisionError(ValueError):
""" """
......
...@@ -13,7 +13,13 @@ from time import time ...@@ -13,7 +13,13 @@ from time import time
# Import this just to export it # Import this just to export it
from pymongo.errors import DuplicateKeyError # pylint: disable=unused-import from pymongo.errors import DuplicateKeyError # pylint: disable=unused-import
from django.core.cache import get_cache, InvalidCacheBackendError
try:
from django.core.cache import get_cache, InvalidCacheBackendError
DJANGO_AVAILABLE = True
except ImportError:
DJANGO_AVAILABLE = False
import dogstats_wrapper as dog_stats_api import dogstats_wrapper as dog_stats_api
from contracts import check, new_contract from contracts import check, new_contract
...@@ -216,15 +222,16 @@ class CourseStructureCache(object): ...@@ -216,15 +222,16 @@ class CourseStructureCache(object):
for set and get. for set and get.
""" """
def __init__(self): def __init__(self):
self.no_cache_found = False self.cache = None
try: if DJANGO_AVAILABLE:
self.cache = get_cache('course_structure_cache') try:
except InvalidCacheBackendError: self.cache = get_cache('course_structure_cache')
self.no_cache_found = True except InvalidCacheBackendError:
pass
def get(self, key, course_context=None): def get(self, key, course_context=None):
"""Pull the compressed, pickled struct data from cache and deserialize.""" """Pull the compressed, pickled struct data from cache and deserialize."""
if self.no_cache_found: if self.cache is None:
return None return None
with TIMER.timer("CourseStructureCache.get", course_context) as tagger: with TIMER.timer("CourseStructureCache.get", course_context) as tagger:
...@@ -245,7 +252,7 @@ class CourseStructureCache(object): ...@@ -245,7 +252,7 @@ class CourseStructureCache(object):
def set(self, key, structure, course_context=None): def set(self, key, structure, course_context=None):
"""Given a structure, will pickle, compress, and write to cache.""" """Given a structure, will pickle, compress, and write to cache."""
if self.no_cache_found: if self.cache is None:
return None return None
with TIMER.timer("CourseStructureCache.set", course_context) as tagger: with TIMER.timer("CourseStructureCache.set", course_context) as tagger:
......
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