-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
57 lines (41 loc) · 1.64 KB
/
controller.py
File metadata and controls
57 lines (41 loc) · 1.64 KB
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
57
# -----------------------------------------------------------------------------
# controller.py
# Created by Ingrid Avendano 11/17/13.
# -----------------------------------------------------------------------------
# Contols different views and runs model depending on the view.
# -----------------------------------------------------------------------------
import os
from flask import Flask, render_template, request
import model
# -----------------------------------------------------------------------------
app = Flask(__name__)
app.secret_key = "honeybooboochild"
# -----------------------------------------------------------------------------
# Run main view of website showing no sublinks.
# -----------------------------------------------------------------------------
@app.route("/", methods=["GET"])
def index():
return render_template("index.html")
@app.route("/", methods=["POST"])
def new_logic():
data = request.form["logic-expression"]
# in case an empty expression was passed
if data.strip() == "":
return render_template("index.html")
data = str("f = " + data)
json = model.compile_expr(data)
if json is not None:
return render_template(
"index.html",
expr=data,
display=True,
json=json)
else:
return render_template("index.html", expr="try again")
@app.route("/explain", methods=["GET"])
def explain():
return render_template("explain.html")
# -----------------------------------------------------------------------------
if __name__ == "__main__":
port = int(os.getenv('CIRCUIT_PORT', 5000))
app.run(host='0.0.0.0', port=port)