explanationList

This commit is contained in:
matic_t 2020-08-10 08:38:08 -07:00
parent 752ec44d43
commit ec811028ab
8 changed files with 50 additions and 30 deletions

View File

@ -169,13 +169,16 @@
.explanations:not(:empty) {
font-style: italic;
&:not(.solo) {
&:before {
content: '[';
}
&:after {
content: ']';
}
}
}
.example {
clear: left;

View File

@ -5,7 +5,7 @@ from model.tags import export_tag
def export_to_xml(model):
xml_document = export_entry(model.entry)
serializer = __new__(XMLSerializer())
return serializer.serializeToString(xml_document);
return serializer.serializeToString(xml_document)
def export_entry(entry):
@ -155,17 +155,21 @@ def export_translation(doc, translation):
actual_t.setAttribute("source", translation.source)
translation_xml.appendChild(actual_t)
explanationList = doc.createElement("explanationList")
for explanation in translation.explanationList:
explanationList.appendChild(explanation.export(doc))
if len(translation.explanationList) > 0 :
explanationList = _export_explanation_list(doc, translation.explanationList)
translation_xml.appendChild(explanationList)
return translation_xml
def _export_explanation_list(doc, lst):
result = doc.createElement('explanationList')
for explanation in lst:
console.log(explanation)
result.appendChild(explanation.export(doc))
return result
def _export_label_list(doc, lst):
result = doc.createElement("labelList")

View File

@ -4,6 +4,7 @@ import message.common_accessors as common_accessors
from browser import document, window
from model.translation import Translation
from model.sense import Sense
from model.explanation import Explanation
@ -14,8 +15,13 @@ class EditTranslation(DataChgClickMessage):
self.translation.translation = document.getElementById("etv").value
# This could be dangerous if double_list_getter is getting data from any other list as well.
self.translation.explanationList = common_accessors.double_list_getter('value', 'language', True)
explanations = common_accessors.double_list_getter('value', 'language', True)
self.translation.explanationList = []
for entry in explanations:
explanation = Explanation()
explanation.value = entry.value
explanation.language = entry.language
self.translation.explanationList.append(explanation)
# common_accessors.label_list_getter()
self.translation.tags = common_accessors.label_list_getter()

View File

@ -2,3 +2,4 @@ from model.model import Model
from model.sense import Sense
from model.translation import Translation
from model.example import Example
from model.explanation import Explanation

View File

@ -25,7 +25,13 @@ class Entry(Data):
self.senses = []
def import_xml(self, entry_xml):
# console.log(entry_xml)
# xmlClone = entry_xml.cloneNode(True)
status = entry_xml.querySelector("head status")
# xmlClone.removeChild(status)
# console.log(xmlClone)
headword = entry_xml.querySelector("head headword lemma")
grammar = entry_xml.querySelector("head grammar category")

View File

@ -16,7 +16,6 @@ class Explanation(Data):
def export(self, doc):
result = doc.createElement("explanation")
result.textContent = self.value
console.log(self.language)
if self.language != "": result.setAttribute('language', self.language)
return result

View File

@ -18,6 +18,7 @@ class Sense(Data):
def import_xml(self, sense_xml, idx):
self.original_idx = idx
for definition in sense_xml.querySelectorAll("definitionList definition"):
key = definition.getAttribute("type")
self.definition[key] = definition.textContent
@ -25,7 +26,6 @@ class Sense(Data):
self.labels = import_label_list("sense > labelList label", sense_xml)
self.translations = from_container_list(
sense_xml.querySelectorAll("translationContainerList translationContainer"))
for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"):
example = Example()
example.import_xml(example_xml)

View File

@ -35,7 +35,7 @@ class Translation(Data):
self.targetLang = ""
self.audio = ""
self.explanation = ""
self.explanationList = []
self.explanationList = set()
self.tags = []
def import_xml(self, translation_xml):
@ -48,7 +48,6 @@ class Translation(Data):
self.audio = translation.getAttribute("audio") if translation.hasAttribute("audio") else ""
explanationList = translation_xml.querySelectorAll("explanationList explanation")
for explanation_dom in explanationList:
explanation = Explanation()
explanation.import_dom(explanation_dom)
@ -69,9 +68,10 @@ class Translation(Data):
if self.source:
elements.append(h("span.translation-source", {}, self.source))
if (self.explanationList):
explanation_class = ".explanations" if self.translation else ".explanations.solo"
explanations = [explanation.value for explanation in self.explanationList]
elements.append(h("span.explanations", {}, ", ".join(explanations)))
elements.append(h("span{}".format(explanation_class), {}, ", ".join(explanations)))
return h("div.translation-div", {"on": {"click": M.msg(M.ShowTranslationMenu, self) }}, elements)
@ -83,5 +83,6 @@ class Translation(Data):
# result = result and self.source == ""
# result = result and self.targetLang == ""
result = result and self.explanation == ""
result = result and len(self.explanationList) == 0
result = result and len(self.tags) == 0
return result