-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.py
39 lines (32 loc) · 1.35 KB
/
routes.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
from flask import current_app as app, render_template, redirect, g,request, render_template_string,jsonify,after_this_request,appcontext_pushed
from datetime import datetime as dt
#Local Import
from models import Users,Location,Event,EventType,UserRole
from database import sesh
@app.route("/")
def home():
return render_template("index.html",locations=[loc for loc in Location.query.all()],roles=list(UserRole))
@app.route("/api", methods=["GET", "POST"])
def api():
if request.method == "POST":
r = request.form
print(r)
new_user = Users(name=r.get("name"),email=r.get("email"),pwd=r.get('pass'),func=None,salt="1234")
sesh.add(new_user)
return jsonify(dict(status="OK",request=request.form.items()))
return jsonify(dict(status="OK"))
@app.route("/api/location",methods=["POST"])
def location():
if request.method == "POST":
r = request.form
print(r)
new_location = Location(r.get("locationName"),r.get("streetname"),r.get("streetnumber"),r.get("city"),r.get("country"))
sesh.add(new_location)
print(f"Location {new_location.name} added!")
locs = Location.query.all()
print([loc.name for loc in locs])
return jsonify(dict(request="OK",data=request.form))
@app.teardown_appcontext
def shutdown_session(exception=None):
sesh.flush()
sesh.remove()