|
|
@ -10,13 +10,13 @@ def export_to_xml(model):
|
|
|
|
def export_entry(entry):
|
|
|
|
def export_entry(entry):
|
|
|
|
parser = __new__(DOMParser())
|
|
|
|
parser = __new__(DOMParser())
|
|
|
|
doc = parser.parseFromString("<entry />", "text/xml")
|
|
|
|
doc = parser.parseFromString("<entry />", "text/xml")
|
|
|
|
|
|
|
|
|
|
|
|
entry_xml = doc.firstChild
|
|
|
|
entry_xml = doc.firstChild
|
|
|
|
|
|
|
|
|
|
|
|
# create head
|
|
|
|
# create head
|
|
|
|
head = doc.createElement("head")
|
|
|
|
head = doc.createElement("head")
|
|
|
|
entry_xml.appendChild(head)
|
|
|
|
entry_xml.appendChild(head)
|
|
|
|
|
|
|
|
|
|
|
|
status = doc.createElement("status")
|
|
|
|
status = doc.createElement("status")
|
|
|
|
status.textContent = entry.status
|
|
|
|
status.textContent = entry.status
|
|
|
|
head.appendChild(status)
|
|
|
|
head.appendChild(status)
|
|
|
@ -37,6 +37,16 @@ def export_entry(entry):
|
|
|
|
comment.textContent = entry.comment
|
|
|
|
comment.textContent = entry.comment
|
|
|
|
head.appendChild(comment)
|
|
|
|
head.appendChild(comment)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
head.appendChild(_export_label_list(doc, entry.labels))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
variants = doc.createElement("variantList")
|
|
|
|
|
|
|
|
head.appendChild(variants)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for v in entry.variants:
|
|
|
|
|
|
|
|
variant = doc.createElement("variant")
|
|
|
|
|
|
|
|
variant.textContent = v
|
|
|
|
|
|
|
|
variants.appendChild(variant)
|
|
|
|
|
|
|
|
|
|
|
|
# now lets do body
|
|
|
|
# now lets do body
|
|
|
|
body = doc.createElement("body")
|
|
|
|
body = doc.createElement("body")
|
|
|
|
entry_xml.appendChild(body)
|
|
|
|
entry_xml.appendChild(body)
|
|
|
@ -52,14 +62,7 @@ def export_entry(entry):
|
|
|
|
|
|
|
|
|
|
|
|
def export_sense(doc, sense):
|
|
|
|
def export_sense(doc, sense):
|
|
|
|
sense_xml = doc.createElement("sense")
|
|
|
|
sense_xml = doc.createElement("sense")
|
|
|
|
|
|
|
|
sense_xml.appendChild(_export_label_list(doc, sense.labels))
|
|
|
|
label_list = doc.createElement("labelList")
|
|
|
|
|
|
|
|
sense_xml.appendChild(label_list)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for label in sense.labels:
|
|
|
|
|
|
|
|
label_xml = doc.createElement("label")
|
|
|
|
|
|
|
|
label_xml.textContent = label
|
|
|
|
|
|
|
|
label_list.appendChild(label_xml)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
definition_list = doc.createElement("definitionList")
|
|
|
|
definition_list = doc.createElement("definitionList")
|
|
|
|
sense_xml.appendChild(definition_list)
|
|
|
|
sense_xml.appendChild(definition_list)
|
|
|
@ -92,9 +95,10 @@ def export_sense(doc, sense):
|
|
|
|
translation_container = doc.createElement("translationContainer")
|
|
|
|
translation_container = doc.createElement("translationContainer")
|
|
|
|
example_container.appendChild(translation_container)
|
|
|
|
example_container.appendChild(translation_container)
|
|
|
|
|
|
|
|
|
|
|
|
translation = doc.createElement("translation")
|
|
|
|
for t in example.translations:
|
|
|
|
translation.textContent = example.translation
|
|
|
|
translation = doc.createElement("translation")
|
|
|
|
translation_container.appendChild(translation)
|
|
|
|
translation.textContent = t
|
|
|
|
|
|
|
|
translation_container.appendChild(translation)
|
|
|
|
|
|
|
|
|
|
|
|
return sense_xml
|
|
|
|
return sense_xml
|
|
|
|
|
|
|
|
|
|
|
@ -103,28 +107,23 @@ def export_translation(doc, translation):
|
|
|
|
|
|
|
|
|
|
|
|
actual_t = doc.createElement("translation")
|
|
|
|
actual_t = doc.createElement("translation")
|
|
|
|
actual_t.textContent = translation.translation
|
|
|
|
actual_t.textContent = translation.translation
|
|
|
|
actual_t.setAttribute("source", translation.source)
|
|
|
|
if translation.source:
|
|
|
|
|
|
|
|
actual_t.setAttribute("source", translation.source)
|
|
|
|
translation_xml.appendChild(actual_t)
|
|
|
|
translation_xml.appendChild(actual_t)
|
|
|
|
|
|
|
|
|
|
|
|
explanation = doc.createElement("explanation")
|
|
|
|
explanation = doc.createElement("explanation")
|
|
|
|
explanation.textContent = translation.explanation
|
|
|
|
explanation.textContent = translation.explanation
|
|
|
|
translation_xml.appendChild(explanation)
|
|
|
|
translation_xml.appendChild(explanation)
|
|
|
|
|
|
|
|
|
|
|
|
tags = doc.createElement("tagsContainer")
|
|
|
|
translation_xml.appendChild(_export_label_list(doc, translation.tags))
|
|
|
|
translation_xml.appendChild(tags)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for tagname, tagvalue in translation.tags.items():
|
|
|
|
|
|
|
|
name_el = doc.createElement("type")
|
|
|
|
|
|
|
|
name_el.textContent = tagname
|
|
|
|
|
|
|
|
value_el = doc.createElement("value")
|
|
|
|
|
|
|
|
value_el.textContent = tagvalue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tag_el = doc.createElement("tag")
|
|
|
|
|
|
|
|
tag_el.appendChild(name_el)
|
|
|
|
|
|
|
|
tag_el.appendChild(value_el)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tags.appendChild(tag_el)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return translation_xml
|
|
|
|
return translation_xml
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _export_label_list(doc, lst):
|
|
|
|
|
|
|
|
result = doc.createElement("labelList")
|
|
|
|
|
|
|
|
for key, value in lst:
|
|
|
|
|
|
|
|
label_el = doc.createElement("label")
|
|
|
|
|
|
|
|
label_el.textContent = value
|
|
|
|
|
|
|
|
label_el.setAttribute('type', key)
|
|
|
|
|
|
|
|
result.appendChild(label_el)
|
|
|
|
|
|
|
|
return result
|
|
|
|