Responses to comments on https://github.com/edx/edx-platform/pull/3539
Conflicts: common/lib/xmodule/xmodule/modulestore/locations.py
This commit is contained in:
@@ -291,16 +291,6 @@ def create_new_course(request):
|
||||
try:
|
||||
course_key = SlashSeparatedCourseKey(org, number, run)
|
||||
|
||||
# see if the course already exists
|
||||
existing_course_exists = False
|
||||
try:
|
||||
existing_course_exists = modulestore('direct').has_course(course_key, ignore_case=True)
|
||||
except InsufficientSpecificationError:
|
||||
pass
|
||||
|
||||
if existing_course_exists:
|
||||
raise InvalidLocationError()
|
||||
|
||||
# instantiate the CourseDescriptor and then persist it
|
||||
# note: no system to pass
|
||||
if display_name is None:
|
||||
@@ -310,7 +300,8 @@ def create_new_course(request):
|
||||
|
||||
# Set a unique wiki_slug for newly created courses. To maintain active wiki_slugs for
|
||||
# existing xml courses this cannot be changed in CourseDescriptor.
|
||||
## TODO get rid of defining wiki slug in this org/course/run specific way
|
||||
# # TODO get rid of defining wiki slug in this org/course/run specific way and reconcile
|
||||
# w/ xmodule.course_module.CourseDescriptor.__init__
|
||||
wiki_slug = u"{0}.{1}.{2}".format(course_key.org, course_key.course, course_key.run)
|
||||
definition_data = {'wiki_slug': wiki_slug}
|
||||
|
||||
@@ -325,26 +316,12 @@ def create_new_course(request):
|
||||
fields.update(metadata)
|
||||
|
||||
# Creating the course raises InvalidLocationError if an existing course with this org/name is found
|
||||
modulestore('direct').create_course(
|
||||
new_course = modulestore('direct').create_course(
|
||||
course_key.org,
|
||||
course_key.offering,
|
||||
fields=fields,
|
||||
)
|
||||
|
||||
new_course = modulestore('direct').get_course(course_key)
|
||||
|
||||
# clone a default 'about' overview module as well
|
||||
dest_about_location = new_course.location.replace(
|
||||
category='about',
|
||||
name='overview'
|
||||
)
|
||||
overview_template = AboutDescriptor.get_template('overview.yaml')
|
||||
modulestore('direct').create_and_save_xmodule(
|
||||
dest_about_location,
|
||||
system=new_course.system,
|
||||
definition_data=overview_template.get('data')
|
||||
)
|
||||
|
||||
# can't use auth.add_users here b/c it requires request.user to already have Instructor perms in this course
|
||||
# however, we can assume that b/c this user had authority to create the course, the user can add themselves
|
||||
CourseInstructorRole(new_course.id).add_users(request.user)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import logging
|
||||
import re
|
||||
from bson.son import SON
|
||||
|
||||
from opaque_keys import InvalidKeyError, OpaqueKey
|
||||
|
||||
@@ -240,6 +241,25 @@ class LocationBase(object):
|
||||
def course_key(self):
|
||||
return SlashSeparatedCourseKey(self.org, self.course, self.run)
|
||||
|
||||
def to_deprecated_son(self, prefix='', tag='i4x'):
|
||||
"""
|
||||
Returns a SON object that represents this location
|
||||
"""
|
||||
# adding tag b/c deprecated form used it
|
||||
son = SON({prefix + 'tag': tag})
|
||||
for field_name in self.KEY_FIELDS:
|
||||
# Temporary filtering of run field because deprecated form left it out
|
||||
if field_name != 'run':
|
||||
son[prefix + field_name] = getattr(self, field_name)
|
||||
return son
|
||||
|
||||
@classmethod
|
||||
def _from_deprecated_son(cls, id_dict, run):
|
||||
"""
|
||||
Return the Location decoding this id_dict and run
|
||||
"""
|
||||
return cls(id_dict['org'], id_dict['course'], run, id_dict['category'], id_dict['name'], id_dict['revision'])
|
||||
|
||||
|
||||
class Location(LocationBase, UsageKey, DefinitionKey):
|
||||
"""
|
||||
@@ -313,6 +333,14 @@ class AssetLocation(LocationBase, AssetKey):
|
||||
"""
|
||||
return AssetLocation(course_key.org, course_key.course, course_key.run, self.category, self.name, self.revision)
|
||||
|
||||
def to_deprecated_list_repr(self):
|
||||
"""
|
||||
Thumbnail locations are stored as lists [c4x, org, course, thumbnail, path, None] in contentstore.mongo
|
||||
That should be the only use of this method, but the method is general enough to provide the pre-opaque
|
||||
Location fields as an array in the old order with the tag.
|
||||
"""
|
||||
return ['c4x', self.org, self.course, self.block_type, self.name, None]
|
||||
|
||||
|
||||
class i4xEncoder(json.JSONEncoder):
|
||||
"""
|
||||
|
||||
@@ -21,6 +21,7 @@ from xmodule.video_module.transcripts_utils import (
|
||||
TranscriptsGenerationException,
|
||||
)
|
||||
from xmodule.modulestore.mongo.base import MongoModuleStore
|
||||
from xmodule.modulestore.locations import AssetLocation
|
||||
|
||||
SRT_content = textwrap.dedent("""
|
||||
0
|
||||
@@ -63,7 +64,7 @@ def _clear_assets(location):
|
||||
|
||||
assets, __ = store.get_all_content_for_course(location.course_key)
|
||||
for asset in assets:
|
||||
asset_location = MongoModuleStore._location_from_id(asset["_id"], location.course_key.run)
|
||||
asset_location = AssetLocation._from_deprecated_son(asset["_id"], location.course_key.run)
|
||||
del_cached_content(asset_location)
|
||||
mongo_id = StaticContent.get_id_from_location(asset_location)
|
||||
store.delete(mongo_id)
|
||||
|
||||
Reference in New Issue
Block a user