From c450bd36b0d641a9c18a7778760f1c8b11979c6c Mon Sep 17 00:00:00 2001 From: Thomas Rubini <74205383+ThomasRubini@users.noreply.github.com> Date: Sat, 11 Mar 2023 17:10:10 +0100 Subject: [PATCH] Modify Question table and rename to QuestionType --- truthinquiry/ext/database/dbutils.py | 4 ++-- truthinquiry/ext/database/models.py | 16 +++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/truthinquiry/ext/database/dbutils.py b/truthinquiry/ext/database/dbutils.py index 0bafc84..2de5f48 100644 --- a/truthinquiry/ext/database/dbutils.py +++ b/truthinquiry/ext/database/dbutils.py @@ -51,14 +51,14 @@ def get_npc_random_answer(npc_id:int, qa_type:int) -> Answer : answers = db.session.query(Answer).filter_by(QA_TYPE=qa_type,NPC_ID=npc_id.NPC_ID).all() return random.choice(answers) -def get_random_question(qa_type: int) -> Question : +def get_random_question(qa_type: int) -> QuestionType : """ Returns a random inspector question from a question type :param qa_type: the type of the question :return: a Question object """ - answers = db.session.query(Question).filter_by(QUESTION_TYPE=qa_type).all() + answers = db.session.query(QuestionType).filter_by(QUESTION_TYPE_ID=qa_type).all() return random.choice(answers) def get_trait_from_text(text: str) -> int: diff --git a/truthinquiry/ext/database/models.py b/truthinquiry/ext/database/models.py index 4a5f4b7..73c490e 100644 --- a/truthinquiry/ext/database/models.py +++ b/truthinquiry/ext/database/models.py @@ -42,24 +42,22 @@ class Place(Base): return f"{self.PLACE_ID} {self.NAME_LID}" -class Question(Base): +class QuestionType(Base): """ - Stores questions asked by players + Stores questions types that can be asked by players, e.g "where", "with tho" """ - __tablename__ = "T_QUESTION" - QUESTION_ID = Column(Integer, primary_key=True, comment="ID of this question") - QUESTION_TYPE = Column(Integer, comment="Question type ID, e.g 'when..', 'where..'") + __tablename__ = "T_QUESTION_TYPE" + QUESTION_TYPE_ID = Column(Integer, primary_key=True, comment="ID of this question type.") TEXT_LID = Column(Integer, ForeignKey("T_LOCALE.TEXT_ID"), comment="Question text") LOCALE = relationship("Locale") - def __init__(self, QUESTION_ID, QUESTION_TYPE, TEXT_LID): - self.QUESTION_ID = QUESTION_ID - self.QUESTION_TYPE = QUESTION_TYPE + def __init__(self, QUESTION_TYPE_ID, TEXT_LID): + self.QUESTION_ID = QUESTION_TYPE_ID self.TEXT_LID = TEXT_LID def __str__(self): - return f"{self.QUESTION_ID} {self.QUESTION_TYPE} {self.TEXT_LID}" + return f"{self.QUESTION_ID} {self.QUESTION_TYPE_ID}" class Answer(Base):