Skip to content
This repository has been archived by the owner on Apr 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #142 from plone/maurits-export-import-selections-13
Browse files Browse the repository at this point in the history
Export and import selections.
  • Loading branch information
jensens committed May 12, 2016
2 parents fa22cf9 + 62c4d9a commit d316de4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
5 changes: 3 additions & 2 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ New features:

Bug fixes:

- *add item here*

- Export and import plugins, link_shortcuts, and image_shortcuts.
Issue https://github.com/plone/Products.TinyMCE/issues/141
[maurits]

1.3.20 (2016-04-25)
-------------------
Expand Down
36 changes: 36 additions & 0 deletions Products/TinyMCE/exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,15 @@ class TinyMCESettingsXMLAdapter(XMLAdapterBase):
'containsanchors': {'type': 'List', 'default': u'ATEvent\nATNewsItem\nATDocument\nATRelativePathCriterion'},
'linkable': {'type': 'List', 'default': u'ATTopic\nATEvent\nATFile\nATFolder\nATImage\nATBTreeFolder\nATNewsItem\nATDocument'},
'imageobjects': {'type': 'List', 'default': u'ATImage'},
'plugins': {'type': 'Selection', 'default': []},
'customplugins': {'type': 'List', 'default': u''},
'entity_encoding': {'type': 'Text', 'default': u'raw'},
'rooted': {'type': 'Bool', 'default': False},
},
'contentbrowser': {
'anchor_selector': {'type': 'Text', 'default': u'h2,h3'},
'link_shortcuts': {'type': 'Selection', 'default': []},
'image_shortcuts': {'type': 'Selection', 'default': []},
}
}

Expand Down Expand Up @@ -126,6 +129,15 @@ def _exportNode(self):
child = self._doc.createElement('element')
child.setAttribute('value', value)
fieldnode.appendChild(child)
elif category[field]['type'] == 'Selection':
if not fieldvalue:
fieldnode.setAttribute('value', '')
else:
for value in fieldvalue:
if value:
child = self._doc.createElement('element')
child.setAttribute('value', value)
fieldnode.appendChild(child)
categorynode.appendChild(fieldnode)
object.appendChild(categorynode)
return object
Expand Down Expand Up @@ -169,6 +181,30 @@ def _importNode(self, node):
string = string.decode("utf-8", "ignore")

setattr(self.context, fieldnode.nodeName, string)
elif self.attributes[categorynode.nodeName][fieldnode.nodeName]['type'] == 'Selection':
field = getattr(self.context, fieldnode.nodeName)
if field is None or fieldnode.getAttribute("purge").lower() == 'true':
items = []
else:
items = field
for element in fieldnode.childNodes:
if element.nodeName != '#text' and element.nodeName != '#comment':
remove = element.getAttribute('remove').lower() == 'true'
value = element.getAttribute('value')
if remove and value in items:
items.remove(value)
if not remove and value not in items:
items.append(value)

for index, key in enumerate(items):
# Don't break on international characters or otherwise
# funky data -
if isinstance(key, str):
# On Plone 4.1 this should not be reached
# as string is unicode in any case
items[index] = key.decode("utf-8", "ignore")

setattr(self.context, fieldnode.nodeName, items)

self._logger.info('TinyMCE Settings imported.')

Expand Down
13 changes: 13 additions & 0 deletions Products/TinyMCE/tests/test_exportimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ def test_import_export(self):
<customplugins purge="True">
<element value="testplugin"/>
</customplugins>
<plugins>
<element value="ploneinlinestyles"/>
<element value="plonebrowser"/>
</plugins>
</resourcetypes>
<contentbrowser>
<anchor_selector value="h2,h3"/>
<link_shortcuts />
</contentbrowser>
</object>
"""

Expand All @@ -41,6 +49,11 @@ def test_import_export(self):

tinymce_utility = getUtility(ITinyMCE)
self.assertIn('testplugin', tinymce_utility.customplugins)
self.assertIn('ploneinlinestyles', tinymce_utility.plugins)
self.assertIn('plonebrowser', tinymce_utility.plugins)
self.assertTrue(isinstance(tinymce_utility.plugins, (list, tuple)))
self.assertFalse(tinymce_utility.link_shortcuts)
self.assertTrue(isinstance(tinymce_utility.link_shortcuts, (list, tuple)))

# Let's create a dummy export context.
context = DummyExportContext(self.portal)
Expand Down

0 comments on commit d316de4

Please sign in to comment.