|
|
|
@ -7,11 +7,23 @@ from model.sense import Sense
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_translation_location(entry, translation):
|
|
|
|
|
for si, sense in enumerate(entry.senses):
|
|
|
|
|
for ci, cluster in enumerate(sense.translations):
|
|
|
|
|
def find_in_clusters(si, clusters):
|
|
|
|
|
for ci, cluster in enumerate(clusters):
|
|
|
|
|
for ti, search_translation in enumerate(cluster):
|
|
|
|
|
if search_translation == translation:
|
|
|
|
|
return (si, ci, ti), (sense, cluster)
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
for si, sense in enumerate(entry.senses):
|
|
|
|
|
res = find_in_clusters(si, sense.translations)
|
|
|
|
|
if res is not None:
|
|
|
|
|
return res
|
|
|
|
|
for example in sense.examples:
|
|
|
|
|
res = find_in_clusters(si, example.translations)
|
|
|
|
|
if res is not None:
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
window.console.log("should not be here...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EditTranslation(DataChgClickMessage):
|
|
|
|
@ -42,23 +54,23 @@ class EditTranslation(DataChgClickMessage):
|
|
|
|
|
# we are done, lets return
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
def do_cluster_change(self, sense, cluster, cidx, tidx, new_cluster_idx):
|
|
|
|
|
def do_cluster_change(self, sense_or_example, cluster, cidx, tidx, new_cluster_idx):
|
|
|
|
|
# remove the translation from the old cluster
|
|
|
|
|
cluster.splice(tidx, 1)
|
|
|
|
|
|
|
|
|
|
# we maybe are creating a new cluster, handle that
|
|
|
|
|
if len(sense.translations) == new_cluster_idx:
|
|
|
|
|
sense.translations.append([self.translation])
|
|
|
|
|
elif len(sense.translations) > new_cluster_idx:
|
|
|
|
|
if len(sense_or_example.translations) == new_cluster_idx:
|
|
|
|
|
sense_or_example.translations.append([self.translation])
|
|
|
|
|
elif len(sense_or_example.translations) > new_cluster_idx:
|
|
|
|
|
# lets append the translation to new cluster
|
|
|
|
|
sense.translations[new_cluster_idx].append(self.translation)
|
|
|
|
|
sense_or_example.translations[new_cluster_idx].append(self.translation)
|
|
|
|
|
else:
|
|
|
|
|
raise ValueError("Bad new cluster idx :(")
|
|
|
|
|
|
|
|
|
|
# we still hols cluster reference, check if empty and remove if necessary
|
|
|
|
|
# we still hold cluster reference, check if empty and remove if necessary
|
|
|
|
|
# we cant do this earlier since indexes change and yeah, fun stuff
|
|
|
|
|
if len(cluster) == 0:
|
|
|
|
|
sense.translations.splice(cidx, 1)
|
|
|
|
|
sense_or_example.translations.splice(cidx, 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MoveRight(DataChgClickMessage):
|
|
|
|
@ -97,5 +109,5 @@ class AddTranslation(EditTranslation):
|
|
|
|
|
# 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.get_arg(2, Sense), [None, None], None, None, new_cluster_idx)
|
|
|
|
|
self.do_cluster_change(self.get_arg(2), [None, None], None, None, new_cluster_idx)
|
|
|
|
|
|
|
|
|
|