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

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

@@ -15,37 +15,37 @@ class Sense(Data):
self.labels = []
self.translations = []
self.examples = []
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
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)
self.examples.append(example)
def merge_labels(self):
return ", ".join(val for _, val in self.labels)
def view(self, model, sense_num):
examples = [example.view(model, self) for example in self.examples]
result = h("div.elm-div", {}, [
h("div.sense-num", {"on": {"click": M.msg(M.ShowSenseMenu, self)}}, str(sense_num + 1)),
h("div.sense", {}, [
h("span.sense-label-list", { "on": { "click": M.msg(M.ShowSenseLabelEdit, self) }}, [
h("span.sense-label", {}, clean_label(slabel)) for _, slabel in self.labels ]),
h("span.sense-label", {}, clean_label(slabel)) for _, slabel in self.labels ]),
h("span.sense-definition", { "on": { "click": M.msg(M.ShowSenseDefinitionEdit, self) }}, self.definition["indicator"]),
h("div", {}, View.view_translations(self.translations, self, model)),
h("div", {}, examples)])])
return result

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))
explanations = [explanation.value for explanation in self.explanationList]
elements.append(h("span.explanations", {}, ", ".join(explanations)))
if (self.explanationList):
explanation_class = ".explanations" if self.translation else ".explanations.solo"
explanations = [explanation.value for explanation in self.explanationList]
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