THE REST: mostly fixing/changing how tags/labellist stuff works

This commit is contained in:
2019-11-17 21:33:58 +01:00
parent b09a84db06
commit 0c6dcbb2f0
8 changed files with 87 additions and 56 deletions
+12 -23
View File
@@ -1,6 +1,8 @@
from message.message import Message, ClickMessage
import message.common_accessors as common_accessors
from browser import document, window
from model.translation import TAGS, NewTranslation
from model.translation import TAGS, Translation
from model.sense import Sense
def get_translation_location(entry, translation):
@@ -11,24 +13,16 @@ def get_translation_location(entry, translation):
return (si, ci, ti), (sense, cluster)
class EditTranslation(TranslationActionMessage):
def __init__(self, _, prop):
self.translation, self.old_cluster_idx = prop
class EditTranslation(ClickMessage):
def update_model(self, model):
self.translation = self.get_arg(0, Translation)
self.old_cluster_idx = self.get_arg(1, int)
self.translation.translation = document.getElementById("etv").value
self.translation.explanation = document.getElementById("ete").value
for tag in TAGS.keys():
select = document.getElementById("{}-s".format(tag))
other = document.getElementById("{}-o".format(tag))
if other.value:
self.translation.tags[tag] = other.value
elif select.selectedIndex > 0:
self.translation.tags[tag] = select.options[select.selectedIndex].text
else:
if tag in self.translation.tags:
del self.translation.tags[tag]
# common_accessors.label_list_getter()
self.translation.tags = common_accessors.label_list_getter()
new_cluster_idx = int(document.getElementById("cluster-num").value) - 1
self.handle_cluster_change(new_cluster_idx, model)
@@ -97,15 +91,10 @@ class BinTranslation(ClickMessage):
class AddTranslation(EditTranslation):
def __init__(self, _, prop):
self.translation = NewTranslation()
self.old_cluster_idx = -1
self.sense = prop
def handle_cluster_change(self, new_cluster_idx, _):
# we need to cheat here
# sense was actually given in constructor
# sense was actually given in constructor in third place
# we make a dummy cluster, cluster_idx and translation_idx
# we give a correct new_cluster_idx
self.do_cluster_change(self.sense, [None, None], None, None, new_cluster_idx)
self.do_cluster_change(self.get_arg(2, Sense), [None, None], None, None, new_cluster_idx)