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,11 +169,14 @@
.explanations:not(:empty) { .explanations:not(:empty) {
font-style: italic; font-style: italic;
&:before { &:not(.solo) {
content: '['; &:before {
} content: '[';
&:after { }
content: ']';
&:after {
content: ']';
}
} }
} }

View File

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

View File

@ -4,6 +4,7 @@ import message.common_accessors as common_accessors
from browser import document, window from browser import document, window
from model.translation import Translation from model.translation import Translation
from model.sense import Sense from model.sense import Sense
from model.explanation import Explanation
@ -14,8 +15,13 @@ class EditTranslation(DataChgClickMessage):
self.translation.translation = document.getElementById("etv").value self.translation.translation = document.getElementById("etv").value
# This could be dangerous if double_list_getter is getting data from any other list as well. # 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() # common_accessors.label_list_getter()
self.translation.tags = 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.sense import Sense
from model.translation import Translation from model.translation import Translation
from model.example import Example from model.example import Example
from model.explanation import Explanation

View File

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

View File

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

View File

@ -15,37 +15,37 @@ class Sense(Data):
self.labels = [] self.labels = []
self.translations = [] self.translations = []
self.examples = [] self.examples = []
def import_xml(self, sense_xml, idx): def import_xml(self, sense_xml, idx):
self.original_idx = idx self.original_idx = idx
for definition in sense_xml.querySelectorAll("definitionList definition"): for definition in sense_xml.querySelectorAll("definitionList definition"):
key = definition.getAttribute("type") key = definition.getAttribute("type")
self.definition[key] = definition.textContent self.definition[key] = definition.textContent
self.labels = import_label_list("sense > labelList label", sense_xml) self.labels = import_label_list("sense > labelList label", sense_xml)
self.translations = from_container_list( self.translations = from_container_list(
sense_xml.querySelectorAll("translationContainerList translationContainer")) sense_xml.querySelectorAll("translationContainerList translationContainer"))
for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"): for example_xml in sense_xml.querySelectorAll("exampleContainerList exampleContainer"):
example = Example() example = Example()
example.import_xml(example_xml) example.import_xml(example_xml)
self.examples.append(example) self.examples.append(example)
def merge_labels(self): def merge_labels(self):
return ", ".join(val for _, val in self.labels) return ", ".join(val for _, val in self.labels)
def view(self, model, sense_num): def view(self, model, sense_num):
examples = [example.view(model, self) for example in self.examples] examples = [example.view(model, self) for example in self.examples]
result = h("div.elm-div", {}, [ result = h("div.elm-div", {}, [
h("div.sense-num", {"on": {"click": M.msg(M.ShowSenseMenu, self)}}, str(sense_num + 1)), h("div.sense-num", {"on": {"click": M.msg(M.ShowSenseMenu, self)}}, str(sense_num + 1)),
h("div.sense", {}, [ h("div.sense", {}, [
h("span.sense-label-list", { "on": { "click": M.msg(M.ShowSenseLabelEdit, self) }}, [ 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("span.sense-definition", { "on": { "click": M.msg(M.ShowSenseDefinitionEdit, self) }}, self.definition["indicator"]),
h("div", {}, View.view_translations(self.translations, self, model)), h("div", {}, View.view_translations(self.translations, self, model)),
h("div", {}, examples)])]) h("div", {}, examples)])])
return result return result

View File

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