Obvious part done. Check why copying example on edit

This commit is contained in:
matic_t 2020-08-27 09:38:40 -07:00
parent a26cbcf4d3
commit f8bd865316
7 changed files with 23 additions and 15 deletions

View File

@ -145,11 +145,8 @@ def export_entry(entry):
def export_sense(doc, sense, sense_xml): def export_sense(doc, sense, sense_xml):
# sense_xml = doc.createElement("sense")
_export_label_list(doc, sense.labels, sense_xml) _export_label_list(doc, sense.labels, sense_xml)
# definition_list = translation.original_xml if translation.original_xml != None else doc.createElement("definitionList")
definition_list = sense_xml.querySelector("definitionList") definition_list = sense_xml.querySelector("definitionList")
if definition_list is None: if definition_list is None:
definition_list = doc.createElement("definitionList") definition_list = doc.createElement("definitionList")

View File

@ -60,7 +60,7 @@ class EditExampleText(Message):
if example.newly_created: if example.newly_created:
example.newly_created = False example.newly_created = False
sense.examples.append(example) sense.examples.append(example)
console.log(example)
idx = 0 idx = 0
for txt in document.getElementsByClassName("example-component-text"): for txt in document.getElementsByClassName("example-component-text"):
example.components[idx].text = txt.value example.components[idx].text = txt.value

View File

@ -63,7 +63,7 @@ class Data:
return None return None
def overwrite_with_copy(self): def overwrite_with_copy(self):
for key, value in dict(self._copy).items(): for key, value in dict(self).items():
# skip functions and _copy # skip functions and _copy
if key == "_copy" or type(value) is None: if key == "_copy" or type(value) is None:
continue continue

View File

@ -11,8 +11,10 @@ class ComponentLexeme(Data):
self.text = "" self.text = ""
self.role = "" self.role = ""
self.no_space = False self.no_space = False
self.original_xml = None
def import_xml(self, xml): def import_xml(self, xml):
self.original_xml = xml.cloneNode(True)
if xml.nodeName == "#text": if xml.nodeName == "#text":
self.text = xml.data self.text = xml.data
self.role = None self.role = None
@ -25,6 +27,7 @@ class ComponentLexeme(Data):
for oth_attr in ["lexeme_id", "lexical_unit_lexeme_id", "slolex", "kol", "sloleks"]: for oth_attr in ["lexeme_id", "lexical_unit_lexeme_id", "slolex", "kol", "sloleks"]:
if xml.hasAttribute(oth_attr): if xml.hasAttribute(oth_attr):
self.other_attributes[oth_attr] = xml.getAttribute(oth_attr) self.other_attributes[oth_attr] = xml.getAttribute(oth_attr)
xml.remove()
def isValid(self): def isValid(self):
return len(self.text) > 0 return len(self.text) > 0
@ -32,7 +35,8 @@ class ComponentLexeme(Data):
def export(self, doc): def export(self, doc):
if self.role is None: if self.role is None:
return doc.createTextNode(self.text) return doc.createTextNode(self.text)
result = doc.createElement("comp") result = self.original_xml if self.original_xml is not None else doc.createElement("comp")
result.setAttribute("role", self.role) result.setAttribute("role", self.role)
result.textContent = self.text result.textContent = self.text

View File

@ -3,14 +3,17 @@ from lib.snabbdom import h
class CorpusExample: class CorpusExample:
def __init__(self): def __init__(self):
self.other_attributes = {} self.other_attributes = {}
self.original_xml = None
def import_xml(self, example_xml): def import_xml(self, example_xml):
for oth_attr in ["example_id", "modified", "lexical_unit_id", "audio"]: for oth_attr in ["example_id", "modified", "lexical_unit_id", "audio"]:
if example_xml.hasAttribute(oth_attr): if example_xml.hasAttribute(oth_attr):
self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr) self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr)
self.original_xml = example_xml
example_xml.remove()
def export(self, doc, modified): def export(self, doc, modified):
result = doc.createElement("corpusExample") result = self.original_xml if self.original_xml is not None else doc.createElement("corpusExample")
if modified: if modified:
result.setAttribute("modified", "true") result.setAttribute("modified", "true")

View File

@ -43,20 +43,19 @@ class Example(Data):
def import_xml(self, example_xml): def import_xml(self, example_xml):
self.translations = from_container_list(example_xml.querySelectorAll("translationContainerList translationContainer")) self.translations = from_container_list(example_xml.querySelectorAll("translationContainerList translationContainer"))
self.original_xml = example_xml.cloneNode(True) self.original_xml = example_xml.cloneNode(True)
if example_xml.hasAttribute("modified"): if example_xml.hasAttribute("modified"):
self.edited = example_xml.getAttribute("modified") == "true" self.edited = example_xml.getAttribute("modified") == "true"
inner_xml = example_xml.querySelector("corpusExample") inner_xml = self.original_xml.querySelector("corpusExample")
if inner_xml is not None: if inner_xml is not None:
self.inner = CorpusExample() self.inner = CorpusExample()
else: else:
inner_xml = example_xml.querySelector("multiwordExample") inner_xml = self.original_xml.querySelector("multiwordExample")
self.inner = MultiwordExample() self.inner = MultiwordExample()
self.inner.import_xml(inner_xml) self.inner.import_xml(inner_xml)
for idx, comp_xml in enumerate(inner_xml.childNodes): for idx, comp_xml in enumerate(self.inner.original_xml.childNodes):
comp = ComponentLexeme() comp = ComponentLexeme()
comp.import_xml(comp_xml) comp.import_xml(comp_xml)
if comp.isValid(): if comp.isValid():

View File

@ -6,8 +6,10 @@ class MultiwordExample:
self.other_attributes = {} self.other_attributes = {}
self.cluster = -1 self.cluster = -1
self.type = None self.type = None
self.original_xml = None
def import_xml(self, example_xml): def import_xml(self, example_xml):
self.original_xml = example_xml.cloneNode(True)
for oth_attr in ["lexical_unit_id", "structure_id", "structureName", "audio", "frequency", "logDice"]: for oth_attr in ["lexical_unit_id", "structure_id", "structureName", "audio", "frequency", "logDice"]:
if example_xml.hasAttribute(oth_attr): if example_xml.hasAttribute(oth_attr):
self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr) self.other_attributes[oth_attr] = example_xml.getAttribute(oth_attr)
@ -16,7 +18,10 @@ class MultiwordExample:
if example_xml.hasAttribute("type"): if example_xml.hasAttribute("type"):
self.type = example_xml.getAttribute("type") self.type = example_xml.getAttribute("type")
example_xml.remove()
@staticmethod @staticmethod
def _determine_cluster_number(example_xml): def _determine_cluster_number(example_xml):
if not example_xml.hasAttribute("cluster"): if not example_xml.hasAttribute("cluster"):
@ -27,8 +32,8 @@ class MultiwordExample:
return cluster return cluster
def export(self, doc, _modified): def export(self, doc, _modified):
result = doc.createElement("multiwordExample") result = self.original_xml if self.original_xml is not None else doc.createElement("multiwordExample")
# result = doc.createElement("multiwordExample")
for key, value in self.other_attributes.items(): for key, value in self.other_attributes.items():
result.setAttribute(key, value) result.setAttribute(key, value)