def admin_edit_post(charid): cur = g.db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor) cur.execute("select creator, level from chars where charid = %s", (charid,)) if cur.rowcount == 1: row = cur.fetchone() creator = row.creator level = row.level if current_user.uid == creator: check, values = validate_form(current_user, request, charid) if check: try: # change this if values changes index! if level != values[4]: expires = interval(values[4]) if expires == False: return render_template("fail.html", message="Invalid level.") elif expires == None: cur.execute("update chars set expires = null where charid = %s", (charid,)) g.db.commit() else: cur.execute( "update chars set expires = current_timestamp + interval %s where charid = %s", (expires, charid), ) g.db.commit() cur.execute( "update chars set name = %s, password = %s, moves = %s, hitpoints = %s, level = %s, race = %s, char_class = %s, homeland = %s, stat_str = %s, stat_int = %s, stat_wil = %s, stat_dex = %s, stat_con = %s, notes = %s, rent = %s, sex = %s where charid = %s", (values), ) g.db.commit() return redirect(url_for("admin_view_char", charid=charid)) except: return render_template("fail.html", message="Unable to update record.") else: return render_template("fail.html", message=values) else: return render_template("fail.html", message="This is not your character.") else: return render_template("fail.html", message="That character does not exist.")
def admin_renew_char(charid): cur = g.db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor) cur.execute("select creator, level from chars where charid = %s", (charid,)) if cur.rowcount == 1: row = cur.fetchone() if current_user.uid == row.creator: expires = interval(row.level) if expires == False: return render_template("fail.html", message="Couldn't renew character.") elif expires == None: cur.execute("update chars set expires = null where charid = %s", (charid,)) g.db.commit() else: cur.execute( "update chars set expires = current_timestamp + interval %s where charid = %s", (expires, charid) ) g.db.commit() # return render_template("success.html") return redirect(request.referrer or url_for("admin")) else: return render_template("fail.html", message="This is not your character.") else: return render_template("fail.html", message="That character does not exist.")