Skip to content
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

Merged
merged 3 commits into from
Jul 31, 2013

Conversation

peter-fogg
Copy link
Contributor

@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.

@auraz
Copy link
Contributor

auraz commented Jul 25, 2013

Please explain why there is not assertions on values of metadata fields in exported word_cloud xml (in test)

@cahrens
Copy link

cahrens commented Jul 25, 2013

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?

@auraz
Copy link
Contributor

auraz commented Jul 25, 2013

@cahrens good point.

@peter-fogg
Copy link
Contributor Author

@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 self.data is empty (None or the empty string).

@chrisndodge
Copy link
Contributor

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?

@peter-fogg
Copy link
Contributor Author

@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:
Copy link

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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
.

Copy link
Contributor Author

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.
@peter-fogg
Copy link
Contributor Author

@cpennington @cahrens @chrisndodge Is this good to merge?

@chrisndodge
Copy link
Contributor

I see you ended up making a new subclass of RawDescriptor.

LGTM

@cahrens
Copy link

cahrens commented Jul 31, 2013

I'll defer to @cpennington and @cdodge.

@cpennington
Copy link
Contributor

👍

peter-fogg pushed a commit that referenced this pull request Jul 31, 2013
Fix word cloud modules not exporting correctly.
@peter-fogg peter-fogg merged commit 25955a7 into master Jul 31, 2013
@peter-fogg peter-fogg deleted the peter-fogg/fix-stud-146 branch July 31, 2013 15:19
hachiyanagi-ks added a commit to nttks/edx-platform that referenced this pull request Nov 16, 2015
hachiyanagi-ks added a commit to nttks/edx-platform that referenced this pull request Nov 16, 2015
diegomillan pushed a commit to eduNEXT/edx-platform that referenced this pull request Sep 14, 2016
* stv/kill/image-modal/deprecate:
  Deprecate ImageModal HtmlModule
xavierchan added a commit to xavierchan/edx-platform-1 that referenced this pull request Dec 16, 2019
fix: rename migration dependencies name
yoann-mroz pushed a commit to weuplearning/edx-platform that referenced this pull request Nov 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants