-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix word cloud modules not exporting correctly. #492
Conversation
Please explain why there is not assertions on values of metadata fields in exported word_cloud xml (in test) |
If the tag doesn't matter, I suggest that we put a default definition into definition_to_xml and remove the wordcloud and videoalpha-specific workarounds. @chrisndodge, what do you think of this? |
@cahrens good point. |
@cahrens @chrisndodge The latest commit has a more general approach. We still need to raise an exception if the XML isn't well-formed, so we only provide a default when |
Can I rope @cpennington in on this? I say that because this is how I originally implemented the video-module fix and Cale thought it would be better not to do this in the base class. Maybe now that we're seeing multiple instances of the same problem this changes how we approach it. I guess another approach could be to make a RawDescriptorWithOnlyMetadata class which derives from RawDescriptor and overrides the definition_to_xml() method. Then we have video_module.py and word_cloud derive from that intermediate class? |
@chrisndodge That would be doable, but since RawDescriptor only has two methods it seems odd to subclass it just to stub out one of them. |
@@ -20,6 +20,8 @@ def definition_from_xml(cls, xml_object, system): | |||
return {'data': etree.tostring(xml_object, pretty_print=True, encoding='unicode')}, [] | |||
|
|||
def definition_to_xml(self, resource_fs): | |||
if not self.data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I like this approach. If we go with it, write a unit test for this new functionality (independent of word cloud or video alpha).
return {'data': etree.tostring(xml_object, pretty_print=True, encoding='unicode')}, [] | ||
|
||
def definition_to_xml(self, resource_fs): | ||
return etree.Element(self.category) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If self.data
isn't empty, then this will delete it, which isn't what we want, I don't think, since during import we import content to self.data
if there is content to import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpennington So we should check if data
is empty, return the empty tag if so, and read in the XML otherwise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah.
On Tue, Jul 30, 2013 at 1:16 PM, Peter Fogg notifications@github.comwrote:
In common/lib/xmodule/xmodule/raw_module.py:
+class EmptyDataRawDescriptor(XmlDescriptor, XMLEditingDescriptor):
- """
- Version of RawDescriptor for modules which may have no XML data,
- but use XMLEditingDescriptor for import/export handling.
- """
- data = String(default='', scope=Scope.content)
- @classmethod
- def definition_from_xml(cls, xml_object, system):
if len(xml_object) == 0 and len(xml_object.items()) == 0:
return {'data': ''}, []
return {'data': etree.tostring(xml_object, pretty_print=True, encoding='unicode')}, []
- def definition_to_xml(self, resource_fs):
return etree.Element(self.category)
So we should check if data is empty, return the empty tag if so, and read
in the XML otherwise?—
Reply to this email directly or view it on GitHubhttps://github.com/edx/edx-platform/pull/492/files#r5482617
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
This allows a more general approach to modules such as word_cloud and video which have no XML data (it's all store in metadata), but use XmlDescriptor for backwards compatibility. They now generate an empty tag on export, and clear out empty tags on import. Also a small change to the video module as a result -- if it's asked to parse empty XML data, it won't try to parse anything.
@cpennington @cahrens @chrisndodge Is this good to merge? |
I see you ended up making a new subclass of RawDescriptor. LGTM |
I'll defer to @cpennington and @cdodge. |
👍 |
Fix word cloud modules not exporting correctly.
…gging-cache-info Add logging for cache infor openedx#492
* stv/kill/image-modal/deprecate: Deprecate ImageModal HtmlModule
fix: rename migration dependencies name
@chrisndodge @cahrens Fixes STUD-146. I also looked through other modules to see if this might be an issue -- it looks like word cloud and video are the only ones which inherit from
RawDescriptor
and could end up with no data.