-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
56 lines (47 loc) · 1.59 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from flask import Flask, render_template, request, redirect
from models import *
from forms import MemberCreateForm
from flask_wtf.csrf import CSRFProtect
app = Flask(__name__)
csrf = CSRFProtect(app)
app.secret_key = "hnjvshfipu89hiuoabhakldshvjklahrguihuilhu"
# @app.before_request
# def db_connect():
# #db is pulled from models in * import
# db.get_conn() #connection
#
# @app.teardown_request
# def db_disconnect():
# if not db.is_closed():
# db.close()
def create_tables():
try:
db.create_tables([Language, Member, Workshop], safe=True)
except OperationalError as e:
print("Tables already exist")
@app.route("/")
def index():
return "Hi Hackbu! <a href='/create'>Create member</a>"
@app.route("/create", methods=["GET", "POST"])
def create_member():
if request.method == "POST":
print(request.form)
try:
with db.transaction():
member = Member.create(name=request.form["name"],
checked_in=True if request.form["checked_in"]=="y" else False
)
return redirect("/members")
except Exception as e:
print(e)
form = MemberCreateForm()
return render_template("create_member.html", form=form)
@app.route("/members")
def list_members():
members = Member.select()
return render_template("list_members.html", members=members)
if __name__ == "__main__":
# if you create new tables, make sure to create them from the command line
# from app import *
create_tables()
app.run(debug=True)