-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontroller.py
More file actions
70 lines (56 loc) · 1.91 KB
/
Copy pathcontroller.py
File metadata and controls
70 lines (56 loc) · 1.91 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
58
59
60
61
62
63
64
65
66
67
68
69
70
from flask import Flask, render_template, request
import scheme_interpreter.lis as lis
import js_parser.js_parser as js_parser
import database.db as db
import os
app = Flask(__name__)
app.secret_key = "thisisasecret"
app.config["DEBUG"] = os.environ.get("DEBUG", False)
@app.route("/")
def index():
html = render_template("index.html")
return html
@app.route("/get_json", methods=["POST"])
def code_submitted():
# return JSON to ajax call -- code input by user
print request.form.get("user_input")
user_input = request.form.get("user_input").strip()
if not user_input:
print 'NO USER INPUT'
return None
elif user_input[0] == '(': # if Scheme program
json_object = lis.format_json(user_input)
else: # try JavaScript
json_object = js_parser.format_json(user_input)
return json_object
@app.route("/get_db_code/<code_id>")
def get_db_code(code_id):
# return JSON to ajax call -- code from database
code_object = db.s.query(db.Code).filter_by(id=code_id).one()
code = code_object.code
return code
@app.route("/save_to_db", methods=["POST"])
def save_to_db():
print request.form.get("user_input")
user_input = request.form.get("user_input").strip()
if not user_input:
print 'NO USER INPUT'
else:
success = db.new_code(user_input)
if success:
return "Share your code with http://visualispy.herokuapp.com/code/%r." % success
else:
return "Sorry, an error occurred."
@app.route("/code/<int:code_id>")
def display_db_code(code_id):
# return JSON to ajax call -- code from database
code_object = db.s.query(db.Code).filter_by(id=code_id).one()
code = code_object.code
html = render_template("index.html", code=code)
return html
@app.route("/about")
def about():
html = render_template("about.html")
return html
if __name__ == "__main__":
app.run(debug=True)