From d50edf9b63af31c50449b00e37656bd40507082b Mon Sep 17 00:00:00 2001
From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com>
Date: Sat, 18 Mar 2023 15:47:44 +0100
Subject: [PATCH 1/3] add option for new npc
---
truthinquiry/templates/admin/index.html | 2 ++
1 file changed, 2 insertions(+)
diff --git a/truthinquiry/templates/admin/index.html b/truthinquiry/templates/admin/index.html
index 26aaffc..fd722fb 100644
--- a/truthinquiry/templates/admin/index.html
+++ b/truthinquiry/templates/admin/index.html
@@ -10,4 +10,6 @@
Barron
Machin
+
+ Nouveau
From 25851dc8a34a5a5ff55a604fb897bebf95a3944b Mon Sep 17 00:00:00 2001
From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com>
Date: Sat, 18 Mar 2023 15:48:07 +0100
Subject: [PATCH 2/3] add backrefs to models
---
truthinquiry/ext/database/models.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/truthinquiry/ext/database/models.py b/truthinquiry/ext/database/models.py
index c53a8e7..5c16f5d 100644
--- a/truthinquiry/ext/database/models.py
+++ b/truthinquiry/ext/database/models.py
@@ -15,7 +15,7 @@ class Text(Base):
LID = Column(Integer, ForeignKey("T_LOCALE.LID"), comment="Reference to the locale that this text provides")
LANG = Column(VARCHAR(2), comment="lang ID of the text value in this row, e.g FR, EN, ES")
TEXT = Column(Text, comment="Actual text stored")
- LOCALE = relationship("Locale")
+ LOCALE = relationship("Locale", backref='TEXTS')
def __init__(self, TEXT_ID, LID, LANG, TEXT):
self.TEXT_ID = TEXT_ID
@@ -104,7 +104,7 @@ class Answer(Base):
NPC_ID = Column(Integer, ForeignKey("T_NPC.NPC_ID"), primary_key=True, comment="ID of the NPC that will say this answer")
TEXT_LID = Column(Integer, ForeignKey("T_LOCALE.LID"), comment="Text of the answer")
LOCALE = relationship("Locale")
- NPC = relationship("Npc")
+ NPC = relationship("Npc", backref="ANSWERS")
def __init__(self, QUESTION_TYPE_ID, NPC_ID, TEXT_LID):
self.QUESTION_TYPE_ID = QUESTION_TYPE_ID
From 92c6d089e790ef878f2e2570134ea25133e1618b Mon Sep 17 00:00:00 2001
From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com>
Date: Sat, 18 Mar 2023 15:48:08 +0100
Subject: [PATCH 3/3] add back office npc view
---
truthinquiry/routes/routes_admin.py | 30 ++++++++++++++++++++++++++-
truthinquiry/templates/admin/npc.html | 18 ++++++++++++++++
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/truthinquiry/routes/routes_admin.py b/truthinquiry/routes/routes_admin.py
index d2085ab..7f12e71 100644
--- a/truthinquiry/routes/routes_admin.py
+++ b/truthinquiry/routes/routes_admin.py
@@ -1,14 +1,42 @@
import flask
+from truthinquiry.ext.database.models import *
+from truthinquiry.ext.database.fsa import db
+
routes_admin = flask.Blueprint("admin", __name__)
+def get_or_empty(obj, key):
+ if obj == None:
+ return ""
+ else:
+ return getattr(obj, key)
+
+
+
+
@routes_admin.route("/")
def index():
return flask.render_template("admin/index.html")
@routes_admin.route("/npc/")
def npc(npc_id):
- return flask.render_template("admin/npc.html")
+ if npc_id == "new":
+ return flask.render_template("admin/npc.html", npc={})
+ else:
+ npc_obj = db.session.get(Npc, npc_id)
+
+ npc_answers = []
+ for answer_type in npc_obj.ANSWERS:
+ answer_list = [answer.TEXT for answer in answer_type.LOCALE.TEXTS]
+ npc_answers.append(answer_list)
+
+ npc_dict = {
+ "name": npc_obj.LOCALE.TEXTS[0].TEXT,
+ "img": npc_obj.NPC_ID,
+ "answers": npc_answers,
+ }
+
+ return flask.render_template("admin/npc.html", npc=npc_dict)
@routes_admin.route("/questions")
def questions():
diff --git a/truthinquiry/templates/admin/npc.html b/truthinquiry/templates/admin/npc.html
index 1583b05..336e5bd 100644
--- a/truthinquiry/templates/admin/npc.html
+++ b/truthinquiry/templates/admin/npc.html
@@ -1 +1,19 @@
go Back
+
+
+
+
+ Answers:
+ {%for answer_type in npc.get("answers") or []%}
+
+ {%endfor%}
+
+
+