-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
398 lines (358 loc) · 13.1 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
from flask import Flask, render_template, send_from_directory, request, redirect, url_for
import os
import psycopg2
# import students
from students import studentRoutes
from Admin import adminRoutes
# import nltk
# import numpy as np
# import pandas as pd
# conn = psycopg2.connect('dbname=postgres')
conn = psycopg2.connect('dbname=group_13 user=group_13 password=p0XvR8Ch4BAGb host=10.17.50.232 port=5432')
cur = conn.cursor()
app = Flask(__name__)
app.register_blueprint(studentRoutes)
app.register_blueprint(adminRoutes)
# app['debug'] = True
# UPLOAD_FOLDER ='./uploads/'
# app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# CONFIG_FOLDER ='./config/'
# app.config['CONFIG_FOLDER'] = CONFIG_FOLDER
# PDF_FOLDER ='./pdfs/'
# app.config['PDF_FOLDER'] = PDF_FOLDER
# app.config['TMP'] = './tmp/'
currentStudentLoginId = "" # the student who is currently logged in
currentProfLoginId = "" # # the instructor who is currently logged in
COID =""
SN = ""
schedule = []
@app.route("/") #main webpage rendering
def main():
return render_template("HomeScreen.html") #the main form
@app.route("/instructorScreen", methods = ["POST"])
def inst():
global currentProfLoginId
global schedule
currentProfLoginId = request.form.get("ProfID")
TC = ""
try:
query1="""
BEGIN;
SELECT * from current_term;
"""
cur.execute(query1)
TC=cur.fetchall()
cur.execute("COMMIT;")
TC=TC[0][0]
except Exception as e:
print(e)
cur.execute("ROLLBACK;")
# schedule = EXECUTE DATABASE QUERY HERE
try:
query="""
BEGIN;
SELECT * from get_instructor_schedule(%s,%s);
""" % (str(currentProfLoginId),str(TC))
cur.execute(query)
schedule=cur.fetchall()
cur.execute("COMMIT;")
except Exception as e:
print (e)
cur.execute("ROLLBACK;")
# try:
# query1="""
# BEGIN;
# SELECT * from current_term;
# """
# cur.execute(query1)
# TC=cur.fetchall()
# cur.execute("COMMIT;")
# TC=TC[0][0]
# except Exception as e:
# print(e)
# # schedule = EXECUTE DATABASE QUERY HERE
# try:
# query="""
# BEGIN;
# SELECT * from get_instructor_schedule(%s,%s);
# """ % (str(currentProfLoginId),str(TC))
# cur.execute(query)
# schedule=cur.fetchall()
# cur.execute("COMMIT;")
# except Exception as e:
# print (e)
return render_template("instructor.html",currentProfLoginId = currentProfLoginId,AddCourseMsg="", requests = [], enrollment = [],addGradeMsg = "", grades = [], room = "", facultyCode = "", schedule = schedule, searchResults=[])
@app.route("/instructorScreen/AddCourse", methods = ["POST"])
def instAC():
# See what is to be done with AddCourseMsg
global currentProfLoginId
global schedule
CID = request.form.get("CID")
TC = ""
# TC = request.form.get("TC")
SN = request.form.get("SN")
LM = request.form.get("LM")
ST = request.form.get("ST")
SC = request.form.get("SC")
RoomReq = request.form.get("RoomReq")
try:
query1="""
BEGIN;
SELECT * from current_term;
"""
cur.execute(query1)
TC=cur.fetchall()
cur.execute("COMMIT;")
TC=TC[0][0]
except Exception as e:
print(e)
cur.execute("ROLLBACK;")
# EXECUTE DATABASE QUERY HERE
try:
query="""
BEGIN;
SELECT add_course_offering('%s',%s,%s,%s,%s,'%s',%s,'%s');
COMMIT;
""" % (str(CID),str(TC),str(SN),str(LM),str(RoomReq),str(ST),str(currentProfLoginId),str(SC))
cur.execute(query)
except Exception as e:
print (e)
cur.execute("ROLLBACK;")
try:
query="""
BEGIN;
SELECT * from get_instructor_schedule(%s,%s);
""" % (str(currentProfLoginId),str(TC))
cur.execute(query)
schedule=cur.fetchall()
cur.execute("COMMIT;")
except Exception as e:
print (e)
cur.execute("ROLLBACK;")
return render_template("instructor.html",currentProfLoginId = currentProfLoginId,AddCourseMsg="", requests = [], enrollment = [],addGradeMsg = "", grades = [], room = "", facultyCode = "", schedule = schedule, searchResults=[])
@app.route("/instructorScreen/Requests", methods = ["POST"])
def instRequests():
# See what is to be done with AddCourseMsg
global currentProfLoginId
global schedule
global COID
global SN
COID = request.form.get("COID")
SN = request.form.get("SN")
requests = [(0,123),(0,1231),(0,13),(0,144),(0,123),(0,1231),(0,13),(0,144),(0,123),(0,1231),(0,13),(0,144)]
# requests = EXECUTE DATABASE QUERY HERE
try:
query="""
BEGIN;
SELECT * from get_pending_requests('%s',%s);
""" % (str(COID),str(SN))
cur.execute(query)
requests = cur.fetchall()
cur.execute("COMMIT;")
except Exception as e:
print (e)
cur.execute("ROLLBACK;")
# print(requests)
return render_template("instructor.html",currentProfLoginId = currentProfLoginId,AddCourseMsg="", requests = requests, enrollment = [],addGradeMsg = "", grades = [], room = "", facultyCode = "", schedule = schedule, searchResults=[])
@app.route("/instructorScreen/ProcessRequests", methods = ["POST"])
def instProcessRequests():
# See what is to be done with AddCourseMsg
global currentProfLoginId
global schedule
global COID
global SN
studentID = request.form.get("studentID")
requests = []
if request.form.get('Accept') == 'Accept':
# a = 2 # dummy line
try:
query="""
BEGIN;
SELECT process_pending_request('%s',%s,%s,%s);
COMMIT;
""" % (str(COID),str('true'),str(SN),str(studentID))
cur.execute(query)
except Exception as e:
print (e)
cur.execute("ROLLBACK;")
else:
# a = 2 # dummy line
try:
query="""
BEGIN;
SELECT process_pending_request('%s',%s,%s,%s);
COMMIT;
""" % (str(COID),str('false'),str(SN),str(studentID))
cur.execute(query)
except Exception as e:
print (e)
cur.execute("ROLLBACK;")
# requests = EXECUTE DATABASE QUERY HERE
try:
query="""
BEGIN;
SELECT * from get_pending_requests('%s',%s);
""" % (str(COID),str(SN))
cur.execute(query)
requests = cur.fetchall()
cur.execute("COMMIT;")
except Exception as e:
print (e)
cur.execute("ROLLBACK;")
return render_template("instructor.html",currentProfLoginId = currentProfLoginId,AddCourseMsg="", requests = requests, enrollment = [],addGradeMsg = "", grades = [], room = "", facultyCode = "", schedule = schedule, searchResults=[])
@app.route("/instructorScreen/Schedule", methods = ["POST"])
def instSchedule():
# See what is to be done with AddCourseMsg
global currentProfLoginId
global schedule
TC=""
# TC = request.form.get("TC")
schedule = []
try:
query1="""
BEGIN;
SELECT * from current_term;
"""
cur.execute(query1)
TC=cur.fetchall()
cur.execute("COMMIT;")
TC=TC[0][0]
except Exception as e:
print(e)
cur.execute("ROLLBACK;")
# schedule = EXECUTE DATABASE QUERY HERE
try:
query="""
BEGIN;
SELECT * from get_instructor_schedule(%s,%s);
""" % (str(currentProfLoginId),str(TC))
cur.execute(query)
schedule=cur.fetchall()
cur.execute("COMMIT;")
except Exception as e:
print (e)
cur.execute("ROLLBACK;")
# print(schedule);
# Will make schedule.html once query is executed and exact form is known
return render_template("instructor.html",currentProfLoginId = currentProfLoginId,AddCourseMsg="", requests = [], enrollment = [],addGradeMsg = "", grades = [], room = "", facultyCode = "", schedule = schedule, searchResults=[])
@app.route("/instructorScreen/enrollment", methods = ["POST"])
def instEnrollments():
# See what is to be done with AddCourseMsg
global currentProfLoginId
global schedule
COID = request.form.get("COID")
SN = request.form.get("SN")
enrollment = ['Aniket','Aarunish','Jai']
# enrollment = EXECUTE DATABASE QUERY HERE
try:
query="""
BEGIN;
SELECT * from get_student_list('%s',%s);
""" % (str(COID),str(SN))
cur.execute(query)
enrollment=cur.fetchall()
cur.execute("COMMIT;")
except Exception as e:
print (e)
cur.execute("ROLLBACK;")
return render_template("instructor.html",currentProfLoginId = currentProfLoginId,AddCourseMsg="", requests = [], enrollment = enrollment,addGradeMsg = "", grades = [], room = "", facultyCode = "", schedule = schedule, searchResults=[])
@app.route("/instructorScreen/addGradeDistribution", methods = ["POST"])
def instAddGD():
# See what is to be done with AddCourseMsg
global currentProfLoginId
global schedule
COID = request.form.get("COID")
SN = request.form.get("SN")
a = request.form.get("a")
ab = request.form.get("ab")
b = request.form.get("b")
bc = request.form.get("bc")
c = request.form.get("c")
d = request.form.get("d")
f = request.form.get("f")
s = request.form.get("s")
u = request.form.get("u")
cr = request.form.get("cr")
n = request.form.get("n")
p = request.form.get("p")
i = request.form.get("i")
nw = request.form.get("nw")
nr = request.form.get("nr")
others = request.form.get("others")
addGradeMsg = "Grade Distribution Updated"
# addGradeMsg = EXECUTE DATABASE QUERY HERE
try:
query="""
BEGIN;
SELECT set_grade_distribution('%s',%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);
COMMIT;
""" % (str(COID),str(SN),str(a),str(ab),str(b),str(bc),str(c),str(d),str(f),str(s),str(u),str(cr),str(n),str(p),str(i),str(nw),str(nr),str(others))
cur.execute(query)
except Exception as e:
print (e)
cur.execute("ROLLBACK;")
addGradeMsg="Error occured while updating"
return render_template("instructor.html",currentProfLoginId = currentProfLoginId,AddCourseMsg="", requests = [], enrollment = [],addGradeMsg = addGradeMsg, grades = [], room = "", facultyCode = "", schedule = schedule, searchResults=[])
@app.route("/instructorScreen/getGradeDistribution", methods = ["POST"])
def instGetGD():
global currentProfLoginId
global schedule
grades = [1,2,3,4,5,6,7,7,8,8,34,2,6,42,6634,24,523]
COID = request.form.get("COID")
SN = request.form.get("SN")
# grades = EXECUTE DATABASE QUERY HER
try:
query="""
BEGIN;
SELECT * from get_grade_distribution('%s',%s);
""" % (str(COID),str(SN))
cur.execute(query)
grades = cur.fetchall()
cur.execute("COMMIT;")
except Exception as e:
print (e)
cur.execute("ROLLBACK;")
return render_template("instructor.html",currentProfLoginId = currentProfLoginId,AddCourseMsg="", requests = [], enrollment = [],addGradeMsg = "", grades = grades, room = "", facultyCode = "", schedule = schedule, searchResults=[])
@app.route("/instructorScreen/room", methods = ["POST"])
def instRoom():
global currentProfLoginId
global schedule
COID = request.form.get("COID")
SN = request.form.get("SN")
output = [('LH121','Narula101')]
# output = EXECUTE DATABASE QUERY HERE
try:
query="""
BEGIN;
SELECT * from get_room_instr('%s',%s);
""" % (str(COID),str(SN))
cur.execute(query)
output=cur.fetchall()
cur.execute("COMMIT;")
except Exception as e:
print (e)
cur.execute("ROLLBACK;")
room = output[0][0]
facultyCode = output[0][1]
return render_template("instructor.html",currentProfLoginId = currentProfLoginId,AddCourseMsg="", requests = [], enrollment = [],addGradeMsg = "", grades = [], room = room, facultyCode = facultyCode, schedule = schedule, searchResults=[])
@app.route("/instructorScreen/searchCourse", methods = ["POST"])
def instsearchCourse():
global currentProfLoginId
global schedule
CName = request.form.get("CName")
searchResults = [(1,"course A"), (2,"Course B"),(1,"course A"), (2,"Course B"),(1,"course A"), (2,"Course B")]
# searchResults = EXECUTE DATABASE QUERY HERE
try:
query="""
BEGIN;
SELECT * from search_course_instructor('%s');
""" % (str(CName))
cur.execute(query)
searchResults=cur.fetchall()
cur.execute("COMMIT;")
except Exception as e:
print (e)
cur.execute("ROLLBACK;")
return render_template("instructor.html",currentProfLoginId = currentProfLoginId,AddCourseMsg="", requests = [], enrollment = [],addGradeMsg = "", grades = [], room = "", facultyCode = "", schedule = schedule, searchResults=searchResults)
if __name__ == '__main__':
app.run(host='127.0.0.1', port=5013)