ensure that curiouscat avi is always loaded

This commit is contained in:
Lynne Megido 2018-11-12 13:00:31 +10:00
parent 79cb6ffa54
commit 6f40492a35
Signed by: lynnesbian
GPG key ID: FB7B970303ACE499

14
web.py
View file

@ -55,12 +55,14 @@ def home():
if 'acct' in session:
if 'cc' not in session:
session['cc'] = "None"
if session['cc'] == "None":
if session['cc'] == "None" or 'ccavi' not in session:
#every time home is rendered without cc being set
c.execute("SELECT cc FROM `data` WHERE client_id LIKE %s AND instance LIKE %s", (session['client_id'], session['instance']))
cc = c.fetchone()[0]
if cc != '':
session['cc'] = cc
c.execute("SELECT cc, ccavi FROM `data` WHERE client_id LIKE %s AND instance LIKE %s", (session['client_id'], session['instance']))
cc = c.fetchone()
if cc[0] != '':
session['cc'] = cc[0]
session['ccavi'] = cc[1]
if 'last_avi_update' not in session or session['last_avi_update'] + (24 * 60 * 60) < time.time():
#avatars haven't been updated for over 24 hours, update them now
@ -75,7 +77,7 @@ def home():
c.execute("UPDATE data SET avi = %s, ccavi = %s WHERE client_id LIKE %s AND instance LIKE %s", (session['avi'], session['ccavi'], session['client_id'], session['instance']))
else:
c.execute("UPDATE data SET avi = %s WHERE client_id LIKE %s AND instance LIKE %s", (session['avi'], session['client_id'], session['instance']))
return render_template("home.html")
return render_template("home.html", mabg="background-image:url('{}')".format(session['avi']), ccbg="background-image:url('{}')".format(session['ccavi']))
else:
return redirect(url_for('main'))