Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Item:
- def __init__(self, row):
- self.ver = row['ver']
- self.manu = row['manu']
- self.model = row['model']
- class ItemDatabase:
- def __init__(self, conn):
- self.conn = conn
- def push(self, item):
- query = """INSERT INTO pg_equipment (ver, manu, model) VALUES (%s, %s, %s)"""
- curs = self.conn.cursor(cursor_factory=RealDictCursor)
- curs.execute(query, (item.ver, item.manu, item.model))
- def pull(self, ver=None, manu=None, make=None, model=None):
- query = """SELECT * from pg_equipment"""
- curs = self.conn.cursor(cursor_factory=RealDictCursor)
- curs.execute(
- query,
- dict(
- ver=ver,
- manu=manu,
- model=model,
- ))
- rows = curs.fetchall()
- if rows:
- return [Item(row) for row in rows]
- return None
- app = Flask(__name__)
- @app.route('/', methods=["GET", "POST"])
- def home():
- if request.form:
- new_item = Item(request.form)
- conn = connect()
- item = ItemDatabase(conn).push(new_item)
- conn.commit()
- return render_template("input.html")
- @app.route('/view', methods=["GET", "POST"])
- def view():
- conn = connect()
- items = ItemDatabase(conn).pull()
- conn.commit()
- return render_template("view.html", items=items)
- if __name__ == "__main__":
- app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement