diff --git a/truthinquiry/ext/database/dbutils.py b/truthinquiry/ext/database/dbutils.py index 2de5f48..f1ce8ba 100644 --- a/truthinquiry/ext/database/dbutils.py +++ b/truthinquiry/ext/database/dbutils.py @@ -11,7 +11,8 @@ def get_text_from_lid(lang: str, lid: int) -> str: :param lid: the locale id the get the text from :return: the text associated to the lang and lid """ - return db.session.query(Locale).filter_by(LANG=lang, TEXT_ID=lid).one().TEXT + texts = db.session.query(Text).filter_by(LANG=lang, TEXT_ID=lid).all() + return random.choice(texts).TEXT def get_random_place() -> Place: """ @@ -58,9 +59,8 @@ def get_random_question(qa_type: int) -> QuestionType : :param qa_type: the type of the question :return: a Question object """ - answers = db.session.query(QuestionType).filter_by(QUESTION_TYPE_ID=qa_type).all() - return random.choice(answers) - + return db.session.query(QuestionType).filter_by(QUESTION_TYPE_ID=qa_type).one() + def get_trait_from_text(text: str) -> int: """ Returns the trait_id from its text value @@ -68,7 +68,7 @@ def get_trait_from_text(text: str) -> int: :param text: the text representation of the trait in any lang :return: the trait_id linked to this text """ - trait_lid = db.session.query(Locale).filter_by(TEXT=text).one().TEXT_ID + trait_lid = db.session.query(Text).filter_by(TEXT=text).one().TEXT_ID return db.session.query(Trait).filter_by(NAME_LID=trait_lid).one().TRAIT_ID def get_trait_from_trait_id(trait_id: int) -> Trait: @@ -81,7 +81,7 @@ def get_trait_from_trait_id(trait_id: int) -> Trait: trait = db.session.query(Trait).filter_by(TRAIT_ID=trait_id).one() return trait -def get_reaction_description(lang, npc_id, trait_id) -> str: +def get_reaction_description(lang, trait_id) -> str: """ Returns the description of the reaction of a given npc in the language specified by the parametter lang diff --git a/truthinquiry/ext/database/models.py b/truthinquiry/ext/database/models.py index 433c7dd..4631aee 100644 --- a/truthinquiry/ext/database/models.py +++ b/truthinquiry/ext/database/models.py @@ -1,6 +1,5 @@ from sqlalchemy import Column, Integer, VARCHAR, Text, ForeignKey -from sqlalchemy.orm import relationship -from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import relationship, declarative_base Base = declarative_base() diff --git a/truthinquiry/logic/game_logic.py b/truthinquiry/logic/game_logic.py index 9e7d773..fd3b8e9 100644 --- a/truthinquiry/logic/game_logic.py +++ b/truthinquiry/logic/game_logic.py @@ -84,7 +84,7 @@ class Game: trait_id = self.reaction_table[npc_id] trait = dbutils.get_trait_from_trait_id(trait_id) npcs[npc_id]["reaction"] = dbutils.get_text_from_lid("FR", trait.NAME_LID) - npcs[npc_id]["description"] = dbutils.get_reaction_description("FR", npc_id, trait.TRAIT_ID) + npcs[npc_id]["description"] = dbutils.get_reaction_description("FR", trait.TRAIT_ID) player_results = data["player"] = {} for member in self.members: player_results[member.username] = member.results @@ -322,4 +322,4 @@ def get_npc_image(npc_id: int): :param npc_id: npc to get the neutral image from :return: the byte representation of the image, none if its not found or not readable """ - return read_image(f"./truthinquiry/static/images/npc/{npc_id}/0.png") + return read_image(f"./truthinquiry/static/images/npc/{npc_id}/0.png") \ No newline at end of file