Ejemplo n.º 1
0
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.")
Ejemplo n.º 2
0
def add_char():
    cur = g.db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)

    check, values = validate_form(current_user, request)
    if check:
        try:
            # hopefully i remember to update this if values index changes
            if values[17]:
                cur.execute(
                    "insert into chars (name, password, creator, moves, hitpoints, level, race, char_class, homeland, stat_str, stat_int, stat_wil, stat_dex, stat_con, notes, rent, sex, expires) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, current_timestamp + interval %s) returning charid",
                    (values),
                )
            else:
                cur.execute(
                    "insert into chars (name, password, creator, moves, hitpoints, level, race, char_class, homeland, stat_str, stat_int, stat_wil, stat_dex, stat_con, notes, rent, sex, expires) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) returning charid",
                    (values),
                )
            charid = cur.fetchone().charid
            g.db.commit()
            return redirect(url_for("admin_view_char", charid=charid))
        except:
            return render_template("fail.html", message="Unable to insert record.")
    else:
        return render_template("fail.html", message=values)