add a starting session with each function, not a global variable to fix registered user not found in db bug
parent
520f38e0d6
commit
98deb9c9f4
12
settings.py
12
settings.py
|
@ -4,12 +4,20 @@ import json
|
||||||
|
|
||||||
|
|
||||||
bp = Blueprint('settings', __name__, url_prefix='/settings')
|
bp = Blueprint('settings', __name__, url_prefix='/settings')
|
||||||
dbsession = get_session()
|
|
||||||
|
|
||||||
def get_settings(user_id):
|
def get_settings(user_id):
|
||||||
|
dbsession = get_session()
|
||||||
"""get settings from db, turns it into a dict and returns it"""
|
"""get settings from db, turns it into a dict and returns it"""
|
||||||
|
|
||||||
user = dbsession.query(User).get(user_id)
|
user = dbsession.query(User).get(user_id)
|
||||||
|
#tu rešujejo none user bug, ki se pojavi, ko na novo reg user, ni zazznan v querryju
|
||||||
|
# zdaj imamo problem clasha med globalno in lokalno spremenljivko "dbsession"
|
||||||
|
if user == None:
|
||||||
|
print("user je bil none")
|
||||||
|
dbsession = get_session()
|
||||||
|
user = dbsession.query(User).get(user_id)
|
||||||
|
print("User je: ", user)
|
||||||
|
|
||||||
settings_db = user.settings
|
settings_db = user.settings
|
||||||
if settings_db == "":
|
if settings_db == "":
|
||||||
#userji se zaenkrat generirajo brez settingsov aka empty string, zato dodamo te defaulte
|
#userji se zaenkrat generirajo brez settingsov aka empty string, zato dodamo te defaulte
|
||||||
|
@ -27,6 +35,8 @@ def get_settings(user_id):
|
||||||
|
|
||||||
@bp.route("/save_settings", methods=["GET", "POST"])
|
@bp.route("/save_settings", methods=["GET", "POST"])
|
||||||
def save_settings():
|
def save_settings():
|
||||||
|
dbsession = get_session()
|
||||||
|
|
||||||
"""takes a dict of settings turns it into json and updates the database with it"""
|
"""takes a dict of settings turns it into json and updates the database with it"""
|
||||||
|
|
||||||
user_id = session['user_id']
|
user_id = session['user_id']
|
||||||
|
|
Loading…
Reference in New Issue