WIP: new way for making empty objects (sense, translation,...)
This commit is contained in:
parent
14655bd6cf
commit
3cfcef6253
|
@ -98,8 +98,10 @@ class ShowAddTranslation(GenericShowModal):
|
||||||
|
|
||||||
for sense in model.entry.senses:
|
for sense in model.entry.senses:
|
||||||
if sense == chosen_sense:
|
if sense == chosen_sense:
|
||||||
|
translation = Translation.new_empty()
|
||||||
|
translation.make_copy()
|
||||||
model.modal = lambda: modals.edit_translation(
|
model.modal = lambda: modals.edit_translation(
|
||||||
sense, -1, len(sense.translations), AddTranslation, sense)
|
translation, -1, len(sense.translations), AddTranslation(translation, -1, sense))
|
||||||
return
|
return
|
||||||
|
|
||||||
console.log("Should not be here!")
|
console.log("Should not be here!")
|
||||||
|
|
|
@ -56,7 +56,7 @@ class EditExampleTranslation(Message):
|
||||||
|
|
||||||
class AddSense(SimpleEditMessage):
|
class AddSense(SimpleEditMessage):
|
||||||
def update_model(self, model):
|
def update_model(self, model):
|
||||||
sense = self.prop
|
sense = Sense.new_empty()
|
||||||
sense.labels = [self.new_text]
|
sense.labels = [self.new_text]
|
||||||
model.entry.senses.append(sense)
|
model.entry.senses.append(sense)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
empty_doc = __new__(DOMParser()).parseFromString("<empty />", "text/xml")
|
||||||
|
|
||||||
|
|
||||||
class Editable:
|
class Editable:
|
||||||
def make_copy(self):
|
def make_copy(self):
|
||||||
# makes an internal copy of self
|
# makes an internal copy of self
|
||||||
|
@ -25,3 +28,6 @@ class Editable:
|
||||||
|
|
||||||
self._copy = None
|
self._copy = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def new_empty(cls):
|
||||||
|
return cls(empty_doc)
|
||||||
|
|
|
@ -24,11 +24,3 @@ class Sense(Editable):
|
||||||
self.translations = [[] for _ in range(max_num_cluster)]
|
self.translations = [[] for _ in range(max_num_cluster)]
|
||||||
for clusterNum, translation in translations:
|
for clusterNum, translation in translations:
|
||||||
self.translations[clusterNum - 1].append(translation)
|
self.translations[clusterNum - 1].append(translation)
|
||||||
|
|
||||||
|
|
||||||
class NewSense(Sense):
|
|
||||||
def __init__(self):
|
|
||||||
self.translations = []
|
|
||||||
self.labels = []
|
|
||||||
self.definition = []
|
|
||||||
self.examples= []
|
|
||||||
|
|
|
@ -6,7 +6,10 @@ TAGS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Translation:
|
from model.editable import Editable
|
||||||
|
|
||||||
|
|
||||||
|
class Translation(Editable):
|
||||||
def __init__(self, translation_xml):
|
def __init__(self, translation_xml):
|
||||||
translation = translation_xml.querySelector("translation")
|
translation = translation_xml.querySelector("translation")
|
||||||
self.translation = translation.textContent if translation else ""
|
self.translation = translation.textContent if translation else ""
|
||||||
|
@ -22,8 +25,4 @@ class Translation:
|
||||||
self.tags[t_type] = t_value
|
self.tags[t_type] = t_value
|
||||||
|
|
||||||
|
|
||||||
class NewTranslation(Translation):
|
|
||||||
def __init__(self):
|
|
||||||
self.translation = ""
|
|
||||||
self.tags = {}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user