Commit 2c90dc73 by Don Mitchell

Don't access kvs directly but use x_module and field_data mechanisms

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