Skip to content

Instantly share code, notes, and snippets.

Created October 3, 2012 09:57
Show Gist options
  • Save bosim/3826155 to your computer and use it in GitHub Desktop.
Save bosim/3826155 to your computer and use it in GitHub Desktop.
Script for exporting ATVocabularyManager vocabularies to IMS VDEX format. Put it in the "custom" folder and access it using http://<my-site>/portal_vocabularies/<vocabName>/exportVocabulary
def recurse(element):
elements = []
for item in element.objectValues():
d = {'uid' : item.UID(),
'title' : item.title,
'children' : []}
if hasattr(item, 'objectValues'):
d['children'] = recurse(item)
return elements
def indent(text, level):
return (' '.join([' ' for i in range(0, level * 2)])) + text + '\n'
def prettyPrint(elements, level):
result = ""
for element in elements:
result += indent('<term>', level)
result += indent(' <termIdentifier>%s</termIdentifier>' % element['uid'], level)
result += indent(' <caption>', level)
result += indent(' <langstring language="da">%s</langstring>' % element['title'], level)
result += indent(' </caption>', level)
result += prettyPrint(element['children'], level + 1)
result += indent('</term>', level)
return result
result = recurse(context)
print """
<?xml version="1.0" encoding="UTF-8"?>
<vdex xmlns="" xmlns:xsi="" xsi:schemaLocation=" imsvdex_v1p0.xsd imsmd_rootv1p2p1.xsd" orderSignificant="false" profileType="flatTokenTerms" language="en">
<langstring language="da">EDIT TITLE</langstring>
<vocabIdentifier>EDIT NAME</vocabIdentifier>
print prettyPrint(result, 1)
print "</vdex>"
return printed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment