use text utility methods when possible
This commit is contained in:
parent
25e29d5c33
commit
135c91ad19
@ -57,7 +57,7 @@ class Locale(Base):
|
|||||||
texts.append(text)
|
texts.append(text)
|
||||||
return texts
|
return texts
|
||||||
|
|
||||||
def get_text(self, lang, auto_create):
|
def get_text(self, lang, auto_create=False):
|
||||||
for text in self.TEXTS:
|
for text in self.TEXTS:
|
||||||
if text.LANG == lang:
|
if text.LANG == lang:
|
||||||
return text
|
return text
|
||||||
|
@ -6,10 +6,12 @@ from truthinquiry.ext.database.fsa import db
|
|||||||
|
|
||||||
routes_admin = flask.Blueprint("admin", __name__)
|
routes_admin = flask.Blueprint("admin", __name__)
|
||||||
|
|
||||||
|
DEFAULT_LANG = "FR"
|
||||||
|
|
||||||
@routes_admin.route("/")
|
@routes_admin.route("/")
|
||||||
def index():
|
def index():
|
||||||
npcs_objs = db.session.query(Npc).all()
|
npcs_objs = db.session.query(Npc).all()
|
||||||
npcs_dicts = [{"id": npc_obj.NPC_ID, "name": npc_obj.NAME_LOCALE.TEXTS[0].TEXT} for npc_obj in npcs_objs]
|
npcs_dicts = [{"id": npc_obj.NPC_ID, "name": npc_obj.NAME_LOCALE.get_text(DEFAULT_LANG).TEXT} for npc_obj in npcs_objs]
|
||||||
return flask.render_template("admin/index.html", npcs=npcs_dicts)
|
return flask.render_template("admin/index.html", npcs=npcs_dicts)
|
||||||
|
|
||||||
@routes_admin.route("/npc/<npc_id>")
|
@routes_admin.route("/npc/<npc_id>")
|
||||||
@ -26,7 +28,7 @@ def npc(npc_id):
|
|||||||
|
|
||||||
npc_dict = {
|
npc_dict = {
|
||||||
"id": npc_obj.NPC_ID,
|
"id": npc_obj.NPC_ID,
|
||||||
"name": npc_obj.NAME_LOCALE.TEXTS[0].TEXT,
|
"name": npc_obj.NAME_LOCALE.get_text(DEFAULT_LANG).TEXT,
|
||||||
"img": npc_obj.NPC_ID,
|
"img": npc_obj.NPC_ID,
|
||||||
"answers": npc_answers,
|
"answers": npc_answers,
|
||||||
}
|
}
|
||||||
@ -35,7 +37,7 @@ def npc(npc_id):
|
|||||||
|
|
||||||
@routes_admin.route("/questions")
|
@routes_admin.route("/questions")
|
||||||
def questions():
|
def questions():
|
||||||
lang = "FR"
|
lang = DEFAULT_LANG
|
||||||
|
|
||||||
results = db.session.execute(
|
results = db.session.execute(
|
||||||
select(QuestionType, Text)
|
select(QuestionType, Text)
|
||||||
@ -61,12 +63,16 @@ def questions():
|
|||||||
|
|
||||||
@routes_admin.route("/places")
|
@routes_admin.route("/places")
|
||||||
def places():
|
def places():
|
||||||
|
lang = DEFAULT_LANG
|
||||||
|
|
||||||
places_objs = db.session.query(Place).all()
|
places_objs = db.session.query(Place).all()
|
||||||
places_dicts = [{"id": place_obj.PLACE_ID, "name": place_obj.NAME_LOCALE.TEXTS[0].TEXT} for place_obj in places_objs]
|
places_dicts = [{"id": place_obj.PLACE_ID, "name": place_obj.NAME_LOCALE.get_text(lang).TEXT} for place_obj in places_objs]
|
||||||
return flask.render_template("admin/places.html", places=places_dicts)
|
return flask.render_template("admin/places.html", places=places_dicts)
|
||||||
|
|
||||||
@routes_admin.route("/traits")
|
@routes_admin.route("/traits")
|
||||||
def traits():
|
def traits():
|
||||||
|
lang = DEFAULT_LANG
|
||||||
|
|
||||||
traits_objs = db.session.query(Trait).all()
|
traits_objs = db.session.query(Trait).all()
|
||||||
traits_dicts = [{"id": trait_obj.TRAIT_ID, "name": trait_obj.NAME_LOCALE.TEXTS[0].TEXT, "desc": trait_obj.DESC_LOCALE.TEXTS[0].TEXT} for trait_obj in traits_objs]
|
traits_dicts = [{"id": trait_obj.TRAIT_ID, "name": trait_obj.NAME_LOCALE.get_text(lang).TEXT, "desc": trait_obj.DESC_LOCALE.get_text(lang).TEXT} for trait_obj in traits_objs]
|
||||||
return flask.render_template("admin/traits.html", traits=traits_dicts)
|
return flask.render_template("admin/traits.html", traits=traits_dicts)
|
||||||
|
@ -57,8 +57,8 @@ def set_traits():
|
|||||||
# modify
|
# modify
|
||||||
db_trait = list(filter(lambda db_trait: db_trait.TRAIT_ID == int(input_trait["id"]), db_traits))[0]
|
db_trait = list(filter(lambda db_trait: db_trait.TRAIT_ID == int(input_trait["id"]), db_traits))[0]
|
||||||
|
|
||||||
db.session.delete(db_trait.NAME_LOCALE.TEXTS[0])
|
db.session.delete(db_trait.NAME_LOCALE.get_text(input_lang))
|
||||||
db.session.delete(db_trait.DESC_LOCALE.TEXTS[0])
|
db.session.delete(db_trait.DESC_LOCALE.get_text(input_lang))
|
||||||
db_trait.NAME_LOCALE.TEXTS = [Text(None, None, input_lang, input_trait["name"])]
|
db_trait.NAME_LOCALE.TEXTS = [Text(None, None, input_lang, input_trait["name"])]
|
||||||
db_trait.DESC_LOCALE.TEXTS = [Text(None, None, input_lang, input_trait["desc"])]
|
db_trait.DESC_LOCALE.TEXTS = [Text(None, None, input_lang, input_trait["desc"])]
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ def set_places():
|
|||||||
# modify
|
# modify
|
||||||
db_place = list(filter(lambda db_place: db_place.PLACE_ID == int(input_place["id"]), db_places))[0]
|
db_place = list(filter(lambda db_place: db_place.PLACE_ID == int(input_place["id"]), db_places))[0]
|
||||||
|
|
||||||
db.session.delete(db_place.NAME_LOCALE.TEXTS[0])
|
db.session.delete(db_place.NAME_LOCALE.get_text(input_lang))
|
||||||
|
|
||||||
db_place.NAME_LOCALE.TEXTS = [Text(None, None, input_lang, input_place["name"])]
|
db_place.NAME_LOCALE.TEXTS = [Text(None, None, input_lang, input_place["name"])]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user