Don't access kvs directly but use x_module and field_data mechanisms
This commit is contained in:
@@ -56,8 +56,7 @@ def compute_inherited_metadata(descriptor):
|
||||
parent_metadata = descriptor.xblock_kvs.inherited_settings.copy()
|
||||
# add any of descriptor's explicitly set fields to the inheriting list
|
||||
for field in InheritanceMixin.fields.values():
|
||||
# pylint: disable = W0212
|
||||
if descriptor._field_data.has(descriptor, field.name):
|
||||
if field.is_set_on(descriptor):
|
||||
# inherited_settings values are json repr
|
||||
parent_metadata[field.name] = field.read_json(descriptor)
|
||||
|
||||
|
||||
@@ -324,16 +324,14 @@ class MongoModuleStore(ModuleStoreBase):
|
||||
for result in resultset:
|
||||
location = Location(result['_id'])
|
||||
# We need to collate between draft and non-draft
|
||||
# i.e. draft verticals can have children which are not in non-draft versions
|
||||
# i.e. draft verticals will have draft children but will have non-draft parents currently
|
||||
location = location.replace(revision=None)
|
||||
location_url = location.url()
|
||||
if location_url in results_by_url:
|
||||
existing_children = results_by_url[location_url].get('definition', {}).get('children', [])
|
||||
additional_children = result.get('definition', {}).get('children', [])
|
||||
total_children = existing_children + additional_children
|
||||
if 'definition' not in results_by_url[location_url]:
|
||||
results_by_url[location_url]['definition'] = {}
|
||||
results_by_url[location_url]['definition']['children'] = total_children
|
||||
results_by_url[location_url].setdefault('definition', {})['children'] = total_children
|
||||
results_by_url[location.url()] = result
|
||||
if location.category == 'course':
|
||||
root = location.url()
|
||||
@@ -643,12 +641,11 @@ class MongoModuleStore(ModuleStoreBase):
|
||||
"""
|
||||
# Save any changes to the xmodule to the MongoKeyValueStore
|
||||
xmodule.save()
|
||||
# split mongo's persist_dag is more general and useful.
|
||||
self.collection.save({
|
||||
'_id': xmodule.location.dict(),
|
||||
'metadata': own_metadata(xmodule),
|
||||
'definition': {
|
||||
'data': xmodule.xblock_kvs._data,
|
||||
'data': xmodule.get_explicitly_set_fields_by_scope(Scope.content),
|
||||
'children': xmodule.children if xmodule.has_children else []
|
||||
}
|
||||
})
|
||||
|
||||
@@ -15,6 +15,7 @@ from xmodule.modulestore.inheritance import own_metadata
|
||||
from xmodule.modulestore.mongo.base import location_to_query, namedtuple_to_son, get_course_id_no_run, MongoModuleStore
|
||||
import pymongo
|
||||
from pytz import UTC
|
||||
from xblock.fields import Scope
|
||||
|
||||
DRAFT = 'draft'
|
||||
# Things w/ these categories should never be marked as version='draft'
|
||||
@@ -237,8 +238,8 @@ class DraftModuleStore(MongoModuleStore):
|
||||
|
||||
draft.published_date = datetime.now(UTC)
|
||||
draft.published_by = published_by_id
|
||||
super(DraftModuleStore, self).update_item(location, draft._field_data._kvs._data)
|
||||
super(DraftModuleStore, self).update_children(location, draft._field_data._kvs._children)
|
||||
super(DraftModuleStore, self).update_item(location, draft.get_explicitly_set_fields_by_scope(Scope.content))
|
||||
super(DraftModuleStore, self).update_children(location, draft.children)
|
||||
super(DraftModuleStore, self).update_metadata(location, own_metadata(draft))
|
||||
self.delete_item(location)
|
||||
|
||||
|
||||
@@ -670,8 +670,8 @@ class XModuleDescriptor(XModuleFields, HTMLSnippet, ResourceTemplates, XBlock):
|
||||
"""
|
||||
result = {}
|
||||
for field in self.fields.values():
|
||||
if (field.scope == scope and self._field_data.has(self, field.name)):
|
||||
result[field.name] = self._field_data.get(self, field.name)
|
||||
if (field.scope == scope and field.is_set_on(self)):
|
||||
result[field.name] = field.read_json(self)
|
||||
return result
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user