-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget.py
More file actions
executable file
·113 lines (92 loc) · 3.65 KB
/
get.py
File metadata and controls
executable file
·113 lines (92 loc) · 3.65 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from api.everything import *
from parameters import getCurrentParameters
# https://github.com/micha/resty
# Also, Postman in Chrome
# Also, http://blog.luisrei.com/articles/flaskrest.html
# Also, https://github.com/jpillora/jquery.rest
# For testing: http://unirest.io/python.html
# Also, the unittest library.
# Also for REST: http://restkit.readthedocs.org/en/latest/
@app.route ("/t/<path:path>", methods = ["GET"])
def templates (path):
return render_template (path, username = os.getenv('USER'))
@app.route ("/urcpp/v1/programs/getAll", methods = ["POST"])
def programs_getAll ():
if username != authUser(request.environ):
return { "response": cfg["response"]["badUsername"] }
# This returns the program table
progQ = (Programs.select())
if progQ.exists():
response = { "response" : "OK" }
progs = progQ.select()
response['programs'] = map(m2d, progs)
return jsonify(response)
else:
response = { "response": cfg["response"]["noResults"],
"details": "No results found for all programs." }
return jsonify(response)
@app.route("/urcpp/v1/projects/getTitle/<username>", methods = ["POST"])
def projects_getTitle (username):
if username != os.getenv("USER"):
return { "response": cfg["response"]["badUsername"] }
# Look up the project title for this user.
projQ = (Projects.select()
.join (URCPPFaculty, on = (URCPPFaculty.pID == Projects.pID))
.where (URCPPFaculty.username == username)
.where (URCPPFaculty.corresponding == True)
)
if projQ.exists():
response = { "response" : "OK" }
proj = projQ.get()
response['project'] = m2d(proj)
return jsonify(response)
else:
response = { "response": cfg["response"]["noResults"],
"details": "No results found for project title." }
return jsonify(response)
### Get Narrative ###
@app.route("/urcpp/v1/projects/getNarrative/<username>", methods = ["POST"])
def getNarrative (username):
if username != authUser(request.environ):
return { "response": cfg["response"]["badUsername"] }
applicationCycle = getCurrentParameters().year
knownFiles = os.listdir()
for filenames in knownFiles:
if "narrative" in filenames:
response = {"response": "OK",
"narrative": filenames}
return jsonify(response)
else:
response = { "response": cfg["response"]["noResults"],
"details": "No results found for project Narrative." }
return jsonify(response)
# projQ = (Projects.select()
# .join (URCPPFaculty, on = (URCPPFaculty.pID == Projects.pID))
# .where (URCPPFaculty.username == username)
# .where (URCPPFaculty.corresponding == True)
# )
# if projQ.exists():
# response = { "response" : "OK" }
# proj = projQ.get()
# response['project'] = m2d(proj)
# return jsonify(response)
# else:
# response = { "response": cfg["response"]["noResults"],
# "details": "No results found for project title." }
# return jsonify(response)
###################################################
# JUNK BELOW THIS LINE
@app.route ("/urcpp/v1/faculty/details/<username>", methods = ["POST"])
def getFacultyDetails (username):
if username != authUser(request.environ):
return { "response": cfg["response"]["badUsername"] }
# FIXME: The funny library pushes things through as... form data?
# force is for ignoring headers
# data = request.get_json (force = True)
data = request.form
app.logger.info ("POST gfd: {0} {1}".format(username, data))
response = { "response" : "OK" }
for k in data:
response[k] = data[k]
app.logger.info ("POST gfd: {0} {1}".format(username, data))
return jsonify (response)