diff --git a/res/main.less b/res/main.less index 057dbd2..364e5d9 100644 --- a/res/main.less +++ b/res/main.less @@ -169,11 +169,14 @@ .explanations:not(:empty) { font-style: italic; - &:before { - content: '['; - } - &:after { - content: ']'; + &:not(.solo) { + &:before { + content: '['; + } + + &:after { + content: ']'; + } } } diff --git a/src/export.py b/src/export.py index b4f99cd..4fe19d8 100644 --- a/src/export.py +++ b/src/export.py @@ -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)) - - translation_xml.appendChild(explanationList) + 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") diff --git a/src/message/translation_edit.py b/src/message/translation_edit.py index 55820be..33c5f74 100644 --- a/src/message/translation_edit.py +++ b/src/message/translation_edit.py @@ -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() diff --git a/src/model/__init__.py b/src/model/__init__.py index 11bc8b3..2f9785f 100644 --- a/src/model/__init__.py +++ b/src/model/__init__.py @@ -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 diff --git a/src/model/entry.py b/src/model/entry.py index dee3b39..f656388 100644 --- a/src/model/entry.py +++ b/src/model/entry.py @@ -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") diff --git a/src/model/explanation.py b/src/model/explanation.py index 1495207..3a3db81 100644 --- a/src/model/explanation.py +++ b/src/model/explanation.py @@ -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 diff --git a/src/model/sense.py b/src/model/sense.py index a1d51e2..52bbd61 100644 --- a/src/model/sense.py +++ b/src/model/sense.py @@ -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 - + diff --git a/src/model/translation.py b/src/model/translation.py index 6bf94bd..fe9a286 100644 --- a/src/model/translation.py +++ b/src/model/translation.py @@ -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