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:
|
||||
if sense == chosen_sense:
|
||||
translation = Translation.new_empty()
|
||||
translation.make_copy()
|
||||
model.modal = lambda: modals.edit_translation(
|
||||
sense, -1, len(sense.translations), AddTranslation, sense)
|
||||
translation, -1, len(sense.translations), AddTranslation(translation, -1, sense))
|
||||
return
|
||||
|
||||
console.log("Should not be here!")
|
||||
|
|
|
@ -56,7 +56,7 @@ class EditExampleTranslation(Message):
|
|||
|
||||
class AddSense(SimpleEditMessage):
|
||||
def update_model(self, model):
|
||||
sense = self.prop
|
||||
sense = Sense.new_empty()
|
||||
sense.labels = [self.new_text]
|
||||
model.entry.senses.append(sense)
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
empty_doc = __new__(DOMParser()).parseFromString("<empty />", "text/xml")
|
||||
|
||||
|
||||
class Editable:
|
||||
def make_copy(self):
|
||||
# makes an internal copy of self
|
||||
|
@ -25,3 +28,6 @@ class Editable:
|
|||
|
||||
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)]
|
||||
for clusterNum, translation in translations:
|
||||
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):
|
||||
translation = translation_xml.querySelector("translation")
|
||||
self.translation = translation.textContent if translation else ""
|
||||
|
@ -22,8 +25,4 @@ class Translation:
|
|||
self.tags[t_type] = t_value
|
||||
|
||||
|
||||
class NewTranslation(Translation):
|
||||
def __init__(self):
|
||||
self.translation = ""
|
||||
self.tags = {}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user