support for multiple sense definitions

This commit is contained in:
Ozbolt Menegatti 2020-01-14 20:59:15 +01:00
parent dcb4840f2a
commit 404bafdae3
5 changed files with 16 additions and 12 deletions

View File

@ -90,10 +90,11 @@ def export_sense(doc, sense):
definition_list = doc.createElement("definitionList")
sense_xml.appendChild(definition_list)
definition = doc.createElement("definition")
definition.textContent = sense.definition
definition.setAttribute("type", "indicator")
definition_list.appendChild(definition)
for typ, text in sense.definition.items():
definition = doc.createElement("definition")
definition.textContent = text
definition.setAttribute("type", typ)
definition_list.appendChild(definition)
translation_container_list = doc.createElement("translationContainerList")
sense_xml.appendChild(translation_container_list)

View File

@ -48,14 +48,14 @@ class EditExampleTranslation(Message):
class AddSense(Message):
def update_model(self, model):
sense = Sense.new_empty()
sense.definition = "New Sense"
sense.definition = {"indicator": "New Sense"}
model.entry.senses.append(sense)
class EditSenseDefinition(QuestionMessage):
def update_model(self, model):
sense = self.get_arg(0, Sense)
sense.definition = self.new_text
sense.definition["indicator"] = self.new_text
class EditComment(QuestionMessage):

View File

@ -6,9 +6,11 @@ from model.tags import import_label_list
class Sense(Editable):
def __init__(self, sense_xml):
definition = sense_xml.querySelector("definitionList definition")
self.definition = {}
for definition in sense_xml.querySelectorAll("definitionList definition"):
key = definition.getAttribute("type")
self.definition[key] = definition.textContent
self.definition = definition.textContent if definition else ""
self.labels = import_label_list("sense > labelList label", sense_xml)
self.examples = [Example(example_xml) for example_xml in
sense_xml.querySelectorAll("exampleContainerList exampleContainer")]

View File

@ -47,7 +47,7 @@ def edit_entry_labels(entry):
def edit_sense_definition(sense):
return modal_template(question("Edit sense definition", sense.definition), "Sense definition", message.EditSenseDefinition(sense))
return modal_template(question("Edit sense definition", sense.definition["indicator"]), "Sense definition", message.EditSenseDefinition(sense))
def edit_comment(comment):
@ -60,8 +60,9 @@ def edit_example(example):
def do_chosen_examples(example_list, entry):
options = []
for sense in entry.senses:
options.append(h("option", {}, sense.merge_labels()))
for idx, sense in enumerate(entry.senses):
text = "{}: {}".format(idx, sense.definition["indicator"])
options.append(h("option", {}, text))
content = [
h("span", {}, "Choose sense for examples"),

View File

@ -87,7 +87,7 @@ class View:
h("div.sense", {}, [
h("span.sense-label-list", { "on": { "click": msg(ShowSenseLabelEdit(sense)) }}, [
h("span.sense-label", {}, clean_label(slabel)) for _, slabel in sense.labels ]),
h("span.sense-definition", { "on": { "click": msg(ShowSenseDefinitionEdit(sense)) }}, sense.definition),
h("span.sense-definition", { "on": { "click": msg(ShowSenseDefinitionEdit(sense)) }}, sense.definition["indicator"]),
h("div", {}, View.view_translations(sense.translations, sense, model)),
h("div", {}, examples)])])