@@ -113,7 +113,7 @@ class CourseRerunUIStateManager(CourseActionUIStateManager):
|
||||
FAILED = "failed"
|
||||
SUCCEEDED = "succeeded"
|
||||
|
||||
def initiated(self, source_course_key, destination_course_key, user):
|
||||
def initiated(self, source_course_key, destination_course_key, user, display_name):
|
||||
"""
|
||||
To be called when a new rerun is initiated for the given course by the given user.
|
||||
"""
|
||||
@@ -123,6 +123,7 @@ class CourseRerunUIStateManager(CourseActionUIStateManager):
|
||||
user=user,
|
||||
allow_not_found=True,
|
||||
source_course_key=source_course_key,
|
||||
display_name=display_name,
|
||||
)
|
||||
|
||||
def succeeded(self, course_key):
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import SchemaMigration
|
||||
from django.db import models
|
||||
|
||||
|
||||
class Migration(SchemaMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
# Adding field 'CourseRerunState.display_name'
|
||||
db.add_column('course_action_state_coursererunstate', 'display_name',
|
||||
self.gf('django.db.models.fields.CharField')(default='', max_length=255, blank=True),
|
||||
keep_default=False)
|
||||
|
||||
|
||||
def backwards(self, orm):
|
||||
# Deleting field 'CourseRerunState.display_name'
|
||||
db.delete_column('course_action_state_coursererunstate', 'display_name')
|
||||
|
||||
|
||||
models = {
|
||||
'auth.group': {
|
||||
'Meta': {'object_name': 'Group'},
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
|
||||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
|
||||
},
|
||||
'auth.permission': {
|
||||
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
|
||||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
|
||||
},
|
||||
'auth.user': {
|
||||
'Meta': {'object_name': 'User'},
|
||||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
|
||||
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
|
||||
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
|
||||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
|
||||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
|
||||
},
|
||||
'contenttypes.contenttype': {
|
||||
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
|
||||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
|
||||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
|
||||
},
|
||||
'course_action_state.coursererunstate': {
|
||||
'Meta': {'unique_together': "(('course_key', 'action'),)", 'object_name': 'CourseRerunState'},
|
||||
'action': ('django.db.models.fields.CharField', [], {'max_length': '100', 'db_index': 'True'}),
|
||||
'course_key': ('xmodule_django.models.CourseKeyField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'created_time': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
'created_user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'created_by_user+'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['auth.User']"}),
|
||||
'display_name': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '255'}),
|
||||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'message': ('django.db.models.fields.CharField', [], {'max_length': '1000'}),
|
||||
'should_display': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
|
||||
'source_course_key': ('xmodule_django.models.CourseKeyField', [], {'max_length': '255', 'db_index': 'True'}),
|
||||
'state': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
|
||||
'updated_time': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
|
||||
'updated_user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'updated_by_user+'", 'null': 'True', 'on_delete': 'models.SET_NULL', 'to': "orm['auth.User']"})
|
||||
}
|
||||
}
|
||||
|
||||
complete_apps = ['course_action_state']
|
||||
@@ -109,6 +109,9 @@ class CourseRerunState(CourseActionUIState):
|
||||
# Original course that is being rerun
|
||||
source_course_key = CourseKeyField(max_length=255, db_index=True)
|
||||
|
||||
# Display name for destination course
|
||||
display_name = models.CharField(max_length=255, default="", blank=True)
|
||||
|
||||
# MANAGERS
|
||||
# Override the abstract class' manager with a Rerun-specific manager that inherits from the base class' manager.
|
||||
objects = CourseRerunUIStateManager()
|
||||
|
||||
@@ -17,10 +17,13 @@ class TestCourseRerunStateManager(TestCase):
|
||||
self.source_course_key = CourseLocator("source_org", "source_course_num", "source_run")
|
||||
self.course_key = CourseLocator("test_org", "test_course_num", "test_run")
|
||||
self.created_user = UserFactory()
|
||||
self.display_name = "destination course name"
|
||||
self.expected_rerun_state = {
|
||||
'created_user': self.created_user,
|
||||
'updated_user': self.created_user,
|
||||
'course_key': self.course_key,
|
||||
'source_course_key': self.source_course_key,
|
||||
"display_name": self.display_name,
|
||||
'action': CourseRerunUIStateManager.ACTION,
|
||||
'should_display': True,
|
||||
'message': "",
|
||||
@@ -53,10 +56,16 @@ class TestCourseRerunStateManager(TestCase):
|
||||
})
|
||||
self.verify_rerun_state()
|
||||
|
||||
def test_rerun_initiated(self):
|
||||
def initiate_rerun(self):
|
||||
CourseRerunState.objects.initiated(
|
||||
source_course_key=self.source_course_key, destination_course_key=self.course_key, user=self.created_user
|
||||
source_course_key=self.source_course_key,
|
||||
destination_course_key=self.course_key,
|
||||
user=self.created_user,
|
||||
display_name=self.display_name,
|
||||
)
|
||||
|
||||
def test_rerun_initiated(self):
|
||||
self.initiate_rerun()
|
||||
self.expected_rerun_state.update(
|
||||
{'state': CourseRerunUIStateManager.State.IN_PROGRESS}
|
||||
)
|
||||
@@ -64,9 +73,7 @@ class TestCourseRerunStateManager(TestCase):
|
||||
|
||||
def test_rerun_succeeded(self):
|
||||
# initiate
|
||||
CourseRerunState.objects.initiated(
|
||||
source_course_key=self.source_course_key, destination_course_key=self.course_key, user=self.created_user
|
||||
)
|
||||
self.initiate_rerun()
|
||||
|
||||
# set state to succeed
|
||||
CourseRerunState.objects.succeeded(course_key=self.course_key)
|
||||
@@ -80,9 +87,7 @@ class TestCourseRerunStateManager(TestCase):
|
||||
|
||||
def test_rerun_failed(self):
|
||||
# initiate
|
||||
CourseRerunState.objects.initiated(
|
||||
source_course_key=self.source_course_key, destination_course_key=self.course_key, user=self.created_user
|
||||
)
|
||||
self.initiate_rerun()
|
||||
|
||||
# set state to fail
|
||||
exception = Exception("failure in rerunning")
|
||||
|
||||
@@ -97,7 +97,7 @@ def replace_static_urls(text, data_directory, course_id=None, static_asset_path=
|
||||
Replace /static/$stuff urls either with their correct url as generated by collectstatic,
|
||||
(/static/$md5_hashed_stuff) or by the course-specific content static url
|
||||
/static/$course_data_dir/$stuff, or, if course_namespace is not None, by the
|
||||
correct url in the contentstore (c4x://)
|
||||
correct url in the contentstore (/c4x/.. or /asset-loc:..)
|
||||
|
||||
text: The source text to do the substitution in
|
||||
data_directory: The directory in which course data is stored
|
||||
|
||||
@@ -185,7 +185,7 @@ def add_staff_markup(user, has_instructor_access, block, view, frag, context):
|
||||
# TODO: make this more general, eg use an XModule attribute instead
|
||||
if isinstance(block, VerticalModule) and (not context or not context.get('child_of_vertical', False)):
|
||||
# check that the course is a mongo backed Studio course before doing work
|
||||
is_mongo_course = modulestore().get_modulestore_type(block.location.course_key) == ModuleStoreEnum.Type.mongo
|
||||
is_mongo_course = modulestore().get_modulestore_type(block.location.course_key) != ModuleStoreEnum.Type.xml
|
||||
is_studio_course = block.course_edit_method == "Studio"
|
||||
|
||||
if is_studio_course and is_mongo_course:
|
||||
|
||||
@@ -64,9 +64,6 @@ class StaticContent(object):
|
||||
def get_id(self):
|
||||
return self.location
|
||||
|
||||
def get_url_path(self):
|
||||
return self.location.to_deprecated_string()
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
return self._data
|
||||
@@ -108,7 +105,9 @@ class StaticContent(object):
|
||||
assert(isinstance(course_key, CourseKey))
|
||||
placeholder_id = uuid.uuid4().hex
|
||||
# create a dummy asset location with a fake but unique name. strip off the name, and return it
|
||||
url_path = unicode(course_key.make_asset_key('asset', placeholder_id).for_branch(None))
|
||||
url_path = StaticContent.serialize_asset_key_with_slash(
|
||||
course_key.make_asset_key('asset', placeholder_id).for_branch(None)
|
||||
)
|
||||
return url_path.replace(placeholder_id, '')
|
||||
|
||||
@staticmethod
|
||||
@@ -133,7 +132,7 @@ class StaticContent(object):
|
||||
# Generate url of urlparse.path component
|
||||
scheme, netloc, orig_path, params, query, fragment = urlparse(path)
|
||||
loc = StaticContent.compute_location(course_id, orig_path)
|
||||
loc_url = loc.to_deprecated_string()
|
||||
loc_url = StaticContent.serialize_asset_key_with_slash(loc)
|
||||
|
||||
# parse the query params for "^/static/" and replace with the location url
|
||||
orig_query = parse_qsl(query)
|
||||
@@ -144,7 +143,7 @@ class StaticContent(object):
|
||||
course_id,
|
||||
query_value[len('/static/'):],
|
||||
)
|
||||
new_query_url = new_query.to_deprecated_string()
|
||||
new_query_url = StaticContent.serialize_asset_key_with_slash(new_query)
|
||||
new_query_list.append((query_name, new_query_url))
|
||||
else:
|
||||
new_query_list.append((query_name, query_value))
|
||||
@@ -155,6 +154,17 @@ class StaticContent(object):
|
||||
def stream_data(self):
|
||||
yield self._data
|
||||
|
||||
@staticmethod
|
||||
def serialize_asset_key_with_slash(asset_key):
|
||||
"""
|
||||
Legacy code expects the serialized asset key to start w/ a slash; so, do that in one place
|
||||
:param asset_key:
|
||||
"""
|
||||
url = unicode(asset_key)
|
||||
if not url.startswith('/'):
|
||||
url = '/' + url # TODO - re-address this once LMS-11198 is tackled.
|
||||
return url
|
||||
|
||||
|
||||
class StaticContentStream(StaticContent):
|
||||
def __init__(self, loc, name, content_type, stream, last_modified_at=None, thumbnail_location=None, import_path=None,
|
||||
|
||||
@@ -66,7 +66,7 @@ class MongoContentStore(ContentStore):
|
||||
self.delete(content_id) # delete is a noop if the entry doesn't exist; so, don't waste time checking
|
||||
|
||||
thumbnail_location = content.thumbnail_location.to_deprecated_list_repr() if content.thumbnail_location else None
|
||||
with self.fs.new_file(_id=content_id, filename=content.get_url_path(), content_type=content.content_type,
|
||||
with self.fs.new_file(_id=content_id, filename=unicode(content.location), content_type=content.content_type,
|
||||
displayname=content.name, content_son=content_son,
|
||||
thumbnail_location=thumbnail_location,
|
||||
import_path=content.import_path,
|
||||
|
||||
@@ -393,15 +393,13 @@ class MixedModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase):
|
||||
if source_modulestore == dest_modulestore:
|
||||
return source_modulestore.clone_course(source_course_id, dest_course_id, user_id, fields, **kwargs)
|
||||
|
||||
# ensure super's only called once. The delegation above probably calls it; so, don't move
|
||||
# the invocation above the delegation call
|
||||
super(MixedModuleStore, self).clone_course(source_course_id, dest_course_id, user_id, fields, **kwargs)
|
||||
|
||||
if dest_modulestore.get_modulestore_type() == ModuleStoreEnum.Type.split:
|
||||
split_migrator = SplitMigrator(dest_modulestore, source_modulestore)
|
||||
split_migrator.migrate_mongo_course(
|
||||
source_course_id, user_id, dest_course_id.org, dest_course_id.course, dest_course_id.run, fields, **kwargs
|
||||
)
|
||||
# the super handles assets and any other necessities
|
||||
super(MixedModuleStore, self).clone_course(source_course_id, dest_course_id, user_id, fields, **kwargs)
|
||||
|
||||
@strip_key
|
||||
def create_item(self, user_id, course_key, block_type, block_id=None, fields=None, **kwargs):
|
||||
|
||||
@@ -952,11 +952,10 @@ class SplitMongoModuleStore(ModuleStoreWriteBase):
|
||||
In split, other than copying the assets, this is cheap as it merely creates a new version of the
|
||||
existing course.
|
||||
"""
|
||||
super(SplitMongoModuleStore, self).clone_course(source_course_id, dest_course_id, user_id, fields, **kwargs)
|
||||
source_index = self.get_course_index_info(source_course_id)
|
||||
if source_index is None:
|
||||
raise ItemNotFoundError("Cannot find a course at {0}. Aborting".format(source_course_id))
|
||||
return self.create_course(
|
||||
new_course = self.create_course(
|
||||
dest_course_id.org, dest_course_id.course, dest_course_id.run,
|
||||
user_id,
|
||||
fields=fields,
|
||||
@@ -965,6 +964,9 @@ class SplitMongoModuleStore(ModuleStoreWriteBase):
|
||||
skip_auto_publish=True,
|
||||
**kwargs
|
||||
)
|
||||
# don't copy assets until we create the course in case something's awry
|
||||
super(SplitMongoModuleStore, self).clone_course(source_course_id, dest_course_id, user_id, fields, **kwargs)
|
||||
return new_course
|
||||
|
||||
DEFAULT_ROOT_BLOCK_ID = 'course'
|
||||
def create_course(
|
||||
@@ -1794,7 +1796,7 @@ class SplitMongoModuleStore(ModuleStoreWriteBase):
|
||||
xblock_class = self.mixologist.mix(xblock_class)
|
||||
|
||||
for field_name, value in fields.iteritems():
|
||||
if value:
|
||||
if value is not None:
|
||||
if isinstance(xblock_class.fields[field_name], Reference):
|
||||
fields[field_name] = value.block_id
|
||||
elif isinstance(xblock_class.fields[field_name], ReferenceList):
|
||||
|
||||
Reference in New Issue
Block a user