adapted code to new models
This commit is contained in:
parent
d07a61c2a0
commit
666bb079db
@ -28,27 +28,27 @@ def bulk_export():
|
||||
data["questions"]["withwho"]["text"] = []
|
||||
data["questions"]["where"] = {}
|
||||
data["questions"]["where"]["text"] = []
|
||||
for question in session.query(Question).all():
|
||||
question_list = data["questions"]["where"]["text"] if question.QUESTION_TYPE == 0 else data["questions"]["withwho"]["text"]
|
||||
for text in session.query(Locale).filter_by(TEXT_ID=question.TEXT_LID).all():
|
||||
for question in session.query(QuestionType).all():
|
||||
question_list = data["questions"]["where"]["text"] if question.QUESTION_TYPE_ID == 0 else data["questions"]["withwho"]["text"]
|
||||
for text in session.query(Text).filter_by(LID=question.TEXT_LID).all():
|
||||
question_list.append({text.LANG : text.TEXT})
|
||||
|
||||
traits = data["traits"] = {}
|
||||
for trait in session.query(Trait).all():
|
||||
current_trait = traits[trait.TRAIT_ID] = {}
|
||||
current_trait["name"] = {}
|
||||
for text in session.query(Locale).filter_by(TEXT_ID=trait.NAME_LID):
|
||||
for text in session.query(TEXT).filter_by(LID=trait.NAME_LID):
|
||||
current_trait["name"][text.LANG] = text.TEXT
|
||||
|
||||
current_trait["description"] = {}
|
||||
for text in session.query(Locale).filter_by(TEXT_ID=trait.DESC_LID):
|
||||
for text in session.query(TEXT).filter_by(LID=trait.DESC_LID):
|
||||
current_trait["description"][text.LANG] = text.TEXT
|
||||
|
||||
npcs = data["npcs"] = {}
|
||||
for npc in session.query(Npc).all():
|
||||
current_npc = npcs[npc.NPC_ID] = {}
|
||||
current_npc["name"] = {}
|
||||
for text in session.query(Locale).filter_by(TEXT_ID=npc.NAME_LID):
|
||||
for text in session.query(TEXT).filter_by(LID=npc.NAME_LID):
|
||||
current_npc["name"][text.LANG] = text.TEXT
|
||||
|
||||
#TODO reactions
|
||||
@ -57,7 +57,7 @@ def bulk_export():
|
||||
current_npc["answers"]["withwho"] = []
|
||||
for answer in session.query(Answer).filter_by(NPC_ID=npc.NPC_ID):
|
||||
answer_list = current_npc["answers"]["where"] if answer.QA_TYPE == 0 else current_npc["answers"]["withwho"]
|
||||
for text in session.query(Locale).filter_by(TEXT_ID=answer.TEXT_LID):
|
||||
for text in session.query(TEXT).filter_by(LID=answer.TEXT_LID):
|
||||
answer_list.append({text.LANG: text.TEXT})
|
||||
return data
|
||||
|
||||
|
@ -18,19 +18,21 @@ Base.metadata.create_all(engine)
|
||||
class LocaleManager():
|
||||
def __init__(self):
|
||||
self.used_lids = [0]
|
||||
[self.used_lids.append(locale.TEXT_ID) for locale in session.query(Locale).all()]
|
||||
[self.used_lids.append(locale.LID) for locale in session.query(Locale).all()]
|
||||
|
||||
def get_unused_lid(self):
|
||||
new_lid = max(self.used_lids) + 1
|
||||
self.used_lids.append(new_lid)
|
||||
return new_lid
|
||||
|
||||
def get_used_lids(self):
|
||||
return self.used_lids[1:]
|
||||
|
||||
|
||||
def bulk_import(data):
|
||||
|
||||
# Data list that will be commited to the db
|
||||
LID_LIST = []
|
||||
TEXT_LIST = []
|
||||
TRAIT_LIST = []
|
||||
REACTION_LIST = []
|
||||
QUESTIONS_LIST = []
|
||||
@ -47,24 +49,24 @@ def bulk_import(data):
|
||||
|
||||
# Where type questions
|
||||
|
||||
question_type_zero = Question(0, 0, getid())
|
||||
question_type_zero = QuestionType(0, getid())
|
||||
QUESTIONS_LIST.append(question_type_zero)
|
||||
|
||||
question_type_one = Question(0, 1, getid())
|
||||
QUESTIONS_LIST.append(question_type_zero)
|
||||
question_type_one = QuestionType(1, getid())
|
||||
QUESTIONS_LIST.append(question_type_one)
|
||||
|
||||
questions = data["questions"]
|
||||
# handle where type quetions
|
||||
for question in questions["where"]["text"]:
|
||||
lang = list(question.keys())[0]
|
||||
text = list(question.values())[0]
|
||||
LID_LIST.append(Locale(question_type_zero.TEXT_LID, lang, text))
|
||||
TEXT_LIST.append(Text(0,question_type_zero.TEXT_LID, lang, text))
|
||||
|
||||
# handle with who type quetions
|
||||
for question in questions["withwho"]["text"]:
|
||||
lang = list(question.keys())[0]
|
||||
text = list(question.values())[0]
|
||||
LID_LIST.append(Locale(question_type_zero.TEXT_LID, lang, text))
|
||||
TEXT_LIST.append(Text(0,question_type_one.TEXT_LID, lang, text))
|
||||
|
||||
# Traits
|
||||
traits = data["traits"]
|
||||
@ -73,24 +75,25 @@ def bulk_import(data):
|
||||
new_trait = Trait(0,getid(), getid())
|
||||
|
||||
for lang in trait["name"]:
|
||||
LID_LIST.append(Locale(new_trait.NAME_LID,
|
||||
TEXT_LIST.append(Text(0,new_trait.NAME_LID,
|
||||
lang, trait["name"][lang]))
|
||||
trait_names[trait["name"][lang]] = new_trait.TRAIT_ID
|
||||
|
||||
for lang in trait["description"]:
|
||||
LID_LIST.append(Locale(new_trait.DESC_LID, lang,
|
||||
TEXT_LIST.append(Text(0,new_trait.DESC_LID, lang,
|
||||
trait["description"][lang]))
|
||||
|
||||
TRAIT_LIST.append(new_trait)
|
||||
|
||||
# Npcs
|
||||
npcs = data["npcs"]
|
||||
npcid = 1
|
||||
for npc in npcs.values():
|
||||
new_npc = Npc(0, getid())
|
||||
new_npc = Npc(npcid, getid())
|
||||
|
||||
# handle the names
|
||||
for lang in npc["name"]:
|
||||
LID_LIST.append(Locale(new_npc.NAME_LID, lang, npc["name"][lang]))
|
||||
TEXT_LIST.append(Text(0,new_npc.NAME_LID, lang, npc["name"][lang]))
|
||||
|
||||
# TODO handle reactions
|
||||
"""
|
||||
@ -100,28 +103,33 @@ def bulk_import(data):
|
||||
REACTION_LIST.append(new_reaction) """
|
||||
|
||||
for question_type in npc["answers"]:
|
||||
question_type_id = 0 if question_type == "where" else 1
|
||||
question_type_id = question_type_zero.QUESTION_TYPE_ID if question_type == "where" else question_type_one.QUESTION_TYPE_ID
|
||||
|
||||
new_answer = Answer(0, question_type_id, new_npc.NPC_ID, getid())
|
||||
new_answer = Answer(question_type_id, new_npc.NPC_ID, getid())
|
||||
ANSWER_LIST.append(new_answer)
|
||||
|
||||
for answer in npc["answers"][question_type]:
|
||||
lang = list(answer.keys())[0]
|
||||
text = list(answer.values())[0]
|
||||
LID_LIST.append(Locale(new_answer.TEXT_LID, lang, text))
|
||||
TEXT_LIST.append(Text(0,new_answer.TEXT_LID, lang, text))
|
||||
|
||||
NPC_LIST.append(new_npc)
|
||||
npcid += 1
|
||||
|
||||
# rooms
|
||||
rooms = data["rooms"]
|
||||
for room in rooms.values():
|
||||
new_room = Place(0,getid())
|
||||
for lang in room:
|
||||
LID_LIST.append(Locale(new_room.NAME_LID, lang, room[lang]))
|
||||
TEXT_LIST.append(Text(0,new_room.NAME_LID, lang, room[lang]))
|
||||
ROOMS_LIST.append(new_room)
|
||||
|
||||
for text in LID_LIST:
|
||||
print("Locale : "+str(text))
|
||||
for lid in lm.get_used_lids():
|
||||
print("lid :"+ str(lid))
|
||||
session.add(Locale(lid));
|
||||
|
||||
for text in TEXT_LIST:
|
||||
print("Text : "+str(text))
|
||||
session.add(text)
|
||||
session.commit()
|
||||
|
||||
@ -155,8 +163,6 @@ def bulk_import(data):
|
||||
session.add(room)
|
||||
session.commit()
|
||||
|
||||
|
||||
|
||||
file = open("bulk_data.yml", "r")
|
||||
|
||||
bulk_import(yaml.load(file, yaml.Loader))
|
||||
|
Loading…
Reference in New Issue
Block a user