diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index 02625eb93f..74ff6657ea 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -104,6 +104,7 @@ def edit_item(request): item = modulestore().get_item(item_location) item.get_html = wrap_xmodule(item.get_html, item, "xmodule_edit.html") + return render_to_response('unit.html', { 'contents': item.get_html(), 'js_module': item.js_module_name, @@ -287,8 +288,16 @@ def save_item(request): # cdodge: also commit any metadata which might have been passed along in the # POST from the client, if it is there + # note, that the postback is not the complete metadata, as there's system metadata which is + # not presented to the end-user for editing. So let's fetch the original and + # 'apply' the submitted metadata, so we don't end up deleting system metadata if request.POST['metadata']: - modulestore().update_metadata(item_location, request.POST['metadata']) + posted_metadata = request.POST['metadata'] + # fetch original + existing_item = modulestore().get_item(item_location) + # update existing metadata with submitted metadata (which can be partial) + existing_item.metadata.update(posted_metadata) + modulestore().update_metadata(item_location, existing_item.metadata) # Export the course back to github # This uses wildcarding to find the course, which requires handling diff --git a/cms/templates/widgets/metadata-edit.html b/cms/templates/widgets/metadata-edit.html index 296b16e9c0..62d5563047 100644 --- a/cms/templates/widgets/metadata-edit.html +++ b/cms/templates/widgets/metadata-edit.html @@ -2,7 +2,7 @@

Metadata

diff --git a/common/lib/xmodule/xmodule/editing_module.py b/common/lib/xmodule/xmodule/editing_module.py index c562617c98..833d994b99 100644 --- a/common/lib/xmodule/xmodule/editing_module.py +++ b/common/lib/xmodule/xmodule/editing_module.py @@ -17,14 +17,13 @@ class EditingDescriptor(MakoModuleDescriptor): js = {'coffee': [resource_string(__name__, 'js/src/raw/edit.coffee')]} js_module_name = "RawDescriptor" - def get_context(self): - return { - 'module': self, - 'data': self.definition.get('data', ''), - 'metadata': self.metadata - # TODO (vshnayder): allow children and metadata to be edited. - #'children' : self.definition.get('children, ''), - # TODO: show both own metadata and inherited? - #'metadata' : self.own_metadata, - } + # cdodge: a little refactoring here, since we're basically doing the same thing + # here as with our parent class, let's call into it to get the basic fields + # set and then add our additional fields. Trying to keep it DRY. + def get_context(self): + _context = MakoModuleDescriptor.get_context(self) + # Add our specific template information (the raw data body) + _context.update({ 'data' : self.definition.get('data','') }) + return _context + diff --git a/common/lib/xmodule/xmodule/mako_module.py b/common/lib/xmodule/xmodule/mako_module.py index 87c2c7d5f9..f5f2fae23b 100644 --- a/common/lib/xmodule/xmodule/mako_module.py +++ b/common/lib/xmodule/xmodule/mako_module.py @@ -1,4 +1,5 @@ from x_module import XModuleDescriptor, DescriptorSystem +import logging class MakoDescriptorSystem(DescriptorSystem): @@ -32,9 +33,17 @@ class MakoModuleDescriptor(XModuleDescriptor): Return the context to render the mako template with """ return {'module': self, - 'metadata': self.metadata + 'metadata': self.metadata, + 'editable_metadata_fields' : self.editable_metadata_fields } def get_html(self): return self.system.render_template( self.mako_template, self.get_context()) + + # cdodge: encapsulate a means to expose "editable" metadata fields (i.e. not internal system metadata) + @property + def editable_metadata_fields(self): + subset = [name for name in self.metadata.keys() if name not in self.system_metadata_fields] + return subset + diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py index 8846926e05..90982d1955 100644 --- a/common/lib/xmodule/xmodule/x_module.py +++ b/common/lib/xmodule/xmodule/x_module.py @@ -352,6 +352,10 @@ class XModuleDescriptor(Plugin, HTMLSnippet): 'data_dir' ) + # cdodge: this is a list of metadata names which are 'system' metadata + # and should not be edited by an end-user + system_metadata_fields = [ 'data_dir' ] + # A list of descriptor attributes that must be equal for the descriptors to # be equal equality_attributes = ('definition', 'metadata', 'location',