Browse Source

add a starting session with each function, not a global variable to fix registered user not found in db bug

master
Kostanjevec 1 month ago
parent
commit
98deb9c9f4
  1. 12
      settings.py

12
settings.py

@ -4,12 +4,20 @@ import json
bp = Blueprint('settings', __name__, url_prefix='/settings')
dbsession = get_session()
def get_settings(user_id):
dbsession = get_session()
"""get settings from db, turns it into a dict and returns it"""
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
if settings_db == "":
#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"])
def save_settings():
dbsession = get_session()
"""takes a dict of settings turns it into json and updates the database with it"""
user_id = session['user_id']

Loading…
Cancel
Save