-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
2008 lines (1630 loc) · 79.7 KB
/
main.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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import mysql.connector, random, openai, os
from flask import Flask, flash, session, render_template, redirect, url_for, request, jsonify
from datetime import date
app = Flask('app')
app.secret_key = "pass"
mydb = mysql.connector.connect(
host = "HOST_SQL_HERE", # put your own stuff here
user="username",
password="password",
database="university"
)
# # Create cursor object
# cursor = mydb.cursor()
# Define routes
@app.route('/')
def index():
return render_template('index.html')
@app.route('/login', methods=['GET', 'POST'])
def login():
# mydb = get_mysql_connection()
cursor = mydb.cursor(dictionary=True)
# If the username/password is correct, log them in and redirect them to the home page. Remember to set your session variables!
if request.method == 'POST':
UserID = request.form["UserID"]
upass = request.form["password"]
cursor.execute("SELECT * FROM users WHERE UserID = %s AND passw = %s ",(UserID, upass))
result = cursor.fetchone()
if result:
session["userID"] = result["UserID"]
#session['userid'] = result['UserID']
session['utype'] = result['userType']
session['email'] = result['email']
session["fname"] = result['fName']
session["lname"] = result['lName']
if(result['userType'] == 'GS'):
return render_template("gsPage.html")
if(result['userType'] == 'Faculty'):
return redirect(url_for("faculty"))
if(result['userType'] == 'ADMIN'):
return render_template("sysadmin.html")
# if(result['userType'] == 'Recommender'):
# print("it is a recommender")
return redirect(url_for("recommender"))
if(result['userType'] == 'Applicant'):
return redirect(url_for("applicant"))
if(result['userType'] == 'CAC'):
return redirect(url_for('cac'))
if(result['userType'] == 'Student'):
return redirect(url_for('student'))
if(result['userType'] == 'Alumni'):
return redirect(url_for('alumni'))
# return redirect('/')
# Else, give an error message and redirect them to the same login page
else:
error= "Error: Username and Password Combination not found"
return render_template("login.html",error=error)
return render_template("login.html")
@app.route('/recLogin', methods=['GET', 'POST'])
def recLogin():
cursor = mydb.cursor(dictionary=True)
if request.method == 'POST':
email = request.form['email']
cursor.execute("SELECT * FROM referenceInfo WHERE (referencer1email = (%s) OR referencer2email=(%s) OR referencer3email = (%s))",(email, email, email) )
found = cursor.fetchall()
if found:
session['email'] = email
return redirect(url_for("recommender"))
return render_template("recLogin.html")
@app.route('/alumni',methods=['GET', 'POST'])
def alumni():
return render_template('alumni.html')
openai.api_key = "" # put your own key here
# Set up the GPT-3.5-turbo model
model_engine = "text-davinci-003"
prompt = "You are a chatbot who is implemented in a school management system. Only answer questions related to school, courses, or majors. Be nice, courteous and helpful."
def generate_response(prompt):
response = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
message = response.choices[0].text.strip()
return message
@app.route("/api/chat", methods=["POST"])
def chat():
data = request.get_json()
message = data["message"]
response = generate_response(prompt + "\nUser: " + message)
return jsonify({"message": response})
@app.route('/talk',methods=['GET', 'POST'])
def talk():
return render_template('talk.html')
@app.route('/student',methods=['GET', 'POST'])
def student():
return render_template('studentHome.html')
#log out
@app.route('/logout', methods=['POST'])
def logout():
session.pop('logged_in', None)
session.pop('username', None)
session.pop('userID', None)
session.pop('utype', None)
session.pop('email', None)
session.pop('fname', None)
session.pop('lname', None)
return redirect(url_for('login'))
# if __name__ == '__main__':
# app.run(debug=True)
#route to faculty page
@app.route('/faculty', methods=['GET', 'POST'])
def faculty():
# mydb = get_mysql_connection()
if 'userID' not in session or session['utype'] != 'Faculty':
return redirect('/')
if session['utype'] == 'CAC':
return redirect(url_for('/cac'))
return render_template('faculty.html')
#view the list of appliciations pending
@app.route('/faculty/applications', methods= ['GET', 'POST'])
def viewList():
# mydb = get_mysql_connection()
if session['utype'] != 'Faculty':
return redirect('/')
cursor = mydb.cursor(dictionary=True)
#check if user is logged i
# if 'UserID' not in session:
# print("user not in session")
# return redirect(url_for('/'))
#review 1 received or review 0
cursor.execute("SELECT IDapp FROM ApplicationChecklist WHERE transcriptReceived = 1 AND finaldecisionreceived = 0 AND (isReferenced = 1)")
apps = cursor.fetchall()
return render_template('listOfApplications.html', apps = apps)
#review applications
@app.route('/faculty/applications/<IDapp>', methods= ['GET', 'POST'])
def goReview(IDapp):
mydb = mysql.connector.connect(
host = "group-11.ci6j3qzwmmr9.us-east-1.rds.amazonaws.com",
user="admin",
password="Password11",
database="university"
)
# mydb = get_mysql_connection()
# need to add a redirect
print("before session")
if session['utype'] != 'Faculty':
if session['utype'] != 'CAC':
return redirect('/')
print("after session")
cursor = mydb.cursor(dictionary=True)
print("before post")
if request.method == 'POST':
print("after post")
reviewerID = request.form["reviewerID"] #the faculty reviewer
print("got reviewerID")
reviewerName = request.form["reviewerName"] #name of reviewer
print("got reviewerName ")
#should be including rating 1-4
rating = request.form["rating"] #rating overall
print("got rating")
#referencer 1
refFrom1 = request.form['refFrom1'] #who wrote the letter
print("got refFrom1")
reviewerScore1 = request.form["reviewerScore1"] #rating of letter
print("got reviewerScore1")
isGeneric1 = request.form["isGeneric1"]
print("got isGeneric1")
isCredible1 = request.form["isCredible1"]
print("got isCredible1")
#referencer 2
refFrom2 = request.form['refFrom2'] #who wrote the letter
print("got refFrom2")
reviewerScore2 = request.form["reviewerScore2"] #rating of letter
print("got reviewerScore2")
isGeneric2 = request.form["isGeneric2"]
print("got isGeneric2")
isCredible2 = request.form["isCredible2"]
print("got isCredible2")
#referencer 3
refFrom3 = request.form['refFrom3'] #who wrote the letter
print("got refFrom3")
reviewerScore3 = request.form["reviewerScore3"] #rating of letter
print("got reviewerScore3")
isGeneric3 = request.form["isGeneric3"]
print("got isGeneric3")
isCredible3 = request.form["isCredible3"]
print("gets referencers")
#include comments about applicant deficiency
deficiency = request.form["deficiency"]
print("gets deficiency")
commenting = request.form["commenting"]
print("gets commenting")
print("before if statement")
if(reviewerName == '' or reviewerID == '' or reviewerScore1 == '' or reviewerScore2 == '' or reviewerScore3 == '' or isGeneric1 == '' or isGeneric2 == '' or isGeneric3 == '' or isCredible1 == '' or isCredible2 == '' or isCredible3 == '' or refFrom1 == '' or refFrom2 == '' or refFrom3 == '' or rating == '' or deficiency == ''):
error = "please fill out all forms."
return render_template('reviewer.html', error=error)
else:
print("after if statement")
#ref 1
cursor.execute("INSERT INTO ReviewInfo(IDA, reviewerID, reviewerName, reviewerScore, isGeneric,isCredible, refFrom, rating, deficiency, commenting) VALUES ((%s),(%s),(%s),(%s),(%s), (%s),(%s),(%s),(%s),(%s))", (IDapp, reviewerID, reviewerName, reviewerScore1, isGeneric1, isCredible1, refFrom1, rating, deficiency, commenting))
#ref 2
cursor.execute("INSERT INTO ReviewInfo(IDA, reviewerID, reviewerName, reviewerScore, isGeneric,isCredible, refFrom, rating, deficiency, commenting) VALUES ((%s),(%s),(%s),(%s),(%s), (%s),(%s),(%s),(%s),(%s))", (IDapp, reviewerID, reviewerName, reviewerScore2, isGeneric2, isCredible2, refFrom2, rating, deficiency, commenting))
#ref 3
cursor.execute("INSERT INTO ReviewInfo(IDA, reviewerID, reviewerName, reviewerScore, isGeneric,isCredible, refFrom, rating, deficiency, commenting) VALUES ((%s),(%s),(%s),(%s),(%s), (%s),(%s),(%s),(%s),(%s))", (IDapp, reviewerID, reviewerName, reviewerScore3, isGeneric3, isCredible3, refFrom3, rating, deficiency, commenting))
# cursor.execute("SELECT * FROM ApplicationChecklist WHERE IDapp = (%s)", (IDapp,))
mydb.commit()
cursor.execute("SELECT * FROM checkReview WHERE idAPP = (%s)", (IDapp,))
checkReview = cursor.fetchall()
if not checkReview:
cursor.execute("INSERT INTO checkReview(idAPP, review1received, review2received, review3received) VALUES((%s), (%s), (%s), (%s))", (IDapp, True, False, False))
elif checkReview['review2received'] == 0:
cursor.execute("UPDATE checkReview SET review2received = 1 WHERE idAPP=(%s)",(IDapp,) )
elif checkReview['review3received'] == 0:
cursor.execute("UPDATE checkReview SET review3received = 1 WHERE idAPP=(%s)",(IDapp,) )
mydb.commit()
return redirect(url_for('/faculty'))
#initializing them to see if it works
fname = ''
lname = ''
GREScore = 0
Verbal = 0
Quantitative = 0
GREAdvScore = 0
GREAdvSbj = ''
TOEFL = 0
TOEFLDate = ''
mDegree = ''
mGPA = 0.0
mMajor = ''
mPriorYear = 0
mUni = ''
# cursor = mydb.cursor(dictionary=True)
print(IDapp)
cursor.execute("SELECT * from Applications INNER JOIN PriorDegree ON PriorDegree.AID = Applications.ApplicationID INNER JOIN users ON users.UserID = Applications.userIdent JOIN ApplicationChecklist ON ApplicationID = IDapp JOIN Recommendation ON Recommendation.IDApplication = Applications.applicationID JOIN referenceInfo ON referenceInfo.appID = Recommendation.IDApplication JOIN GRE ON GRE.AppID = referenceInfo.appID WHERE Applications.applicationID = (%s)",(IDapp,) )
reviewApp = cursor.fetchone()
if reviewApp == None:
return redirect('/faculty/applications')
appID = reviewApp['applicationID']
fname = reviewApp['fName']
lname = reviewApp['lName']
studentNum = reviewApp['userIdent']
sem = reviewApp['admissionSem']
appYear = reviewApp['admissionYr']
degreeSought = reviewApp['degreeSought']
interests = reviewApp['interests']
experience = reviewApp['priorWorkExperience']
bDegree = reviewApp['DegreeType']
GPA = reviewApp['GPA']
major = reviewApp['Major']
priorYear = reviewApp['priorYear']
uni = reviewApp['University']
if reviewApp['DegreeType'] == 'Masters' or reviewApp['DegreeType'] == 'MS':
mDegree = reviewApp['DegreeType']
mGPA = reviewApp['GPA']
mMajor = reviewApp['Major']
mPriorYear = reviewApp['priorYear']
mUni = reviewApp['University']
#For some reason, in degreetype for BS/BA this works...
if reviewApp['DegreeType'] == 'BS'or reviewApp['DegreeType'] == 'BA':
bDegree = reviewApp['DegreeType']
GPA = reviewApp['GPA']
major = reviewApp['Major']
priorYear = reviewApp['priorYear']
uni = reviewApp['University']
ref1fname = reviewApp['referencer1fname']
ref1lname = reviewApp['referencer1lname']
ref1title = reviewApp['referencer1title']
ref1aff = reviewApp['referencer1affil']
ref1letter = reviewApp['letter']
ref2fname = reviewApp['referencer2fname']
ref2lname = reviewApp['referencer2lname']
ref2title = reviewApp['referencer2title']
ref2aff = reviewApp['referencer2affil']
ref2letter = reviewApp['letter']
ref3fname = reviewApp['referencer3fname']
ref3lname = reviewApp['referencer3lname']
ref3title = reviewApp['referencer3title']
ref3aff = reviewApp['referencer3affil']
ref3letter = reviewApp['letter']
GREScore = reviewApp['GREScore']
Verbal = reviewApp['Verbal']
Quantitative = reviewApp['Quantitative']
GREAdvScore = reviewApp['GREAdvScore']
GREAdvSbj = reviewApp['GREAdvSbj']
TOEFL = reviewApp['TOEFL']
TOEFLDate = reviewApp['TOEFLDate']
examYear = reviewApp['examYear']
# return render_template("reviewer.html", appID = appID, fn = fname, lname = lname, studentNum=studentNum, sem=sem, appYear = appYear, degreeSought = degreeSought,bDegree = bDegree, GPA = GPA, major = major,priorYear = priorYear,uni = uni, interests = interests, experience=experience, GREScore = GREScore, Verbal = Verbal, Quantitative=Quantitative, GREAdvScore = GREAdvScore, GREAdvSbj= GREAdvSbj, TOEFL=TOEFL, TOEFLDate=TOEFLDate, mDegree=mDegree,mGPA=mGPA,mMajor=mMajor, mPriorYear=mPriorYear, mUni=mUni, ref1fname = ref1fname, ref1lname = ref1lname, ref1title = ref1title, ref1aff = ref1aff, ref1letter = ref1letter,ref2fname = ref2fname, ref2lname = ref2lname, ref2title = ref2title, ref2aff = ref2aff, ref2letter = ref2letter, ref3fname = ref3fname, ref3lname = ref3lname, ref3title = ref3title, ref3aff = ref3aff, ref3letter = ref3letter)
return render_template("reviewer.html", appID = appID, fn = fname, lname = lname, studentNum=studentNum, sem=sem, appYear = appYear, degreeSought = degreeSought,bDegree = bDegree, GPA = GPA, major = major,priorYear = priorYear,uni = uni, interests = interests, experience=experience, GREScore = GREScore, Verbal = Verbal, Quantitative=Quantitative, GREAdvScore = GREAdvScore, GREAdvSbj= GREAdvSbj, TOEFL=TOEFL, TOEFLDate=TOEFLDate, mDegree=mDegree,mGPA=mGPA,mMajor=mMajor, mPriorYear=mPriorYear, mUni=mUni,ref1fname = ref1fname, ref1lname = ref1lname, ref1title = ref1title, ref1aff = ref1aff, ref1letter = ref1letter,ref2fname = ref2fname, ref2lname = ref2lname, ref2title = ref2title, ref2aff = ref2aff, ref2letter = ref2letter, ref3fname = ref3fname, ref3lname = ref3lname, ref3title = ref3title, ref3aff = ref3aff, ref3letter = ref3letter)
mydb = mysql.connector.connect(
host = "group-11.ci6j3qzwmmr9.us-east-1.rds.amazonaws.com",
user="admin",
password="Password11",
database="university"
)
@app.route('/pickstudent', methods=['GET', 'POST'])
def pick_student():
cursor = mydb.cursor()
cursor.execute("SELECT * FROM users WHERE userID NOT IN (SELECT studentID FROM Student)")
students = cursor.fetchall()
cursor.execute("SELECT * FROM users WHERE userType='Faculty'")
advisors = cursor.fetchall()
return render_template('pickstudent.html', students=students, advisors=advisors)
@app.route('/apply-graduation', methods=['GET', 'POST'])
def apply_graduation():
if request.method == 'POST':
# get form data
student_id = request.form['student_id']
graduation_degree = request.form['graduation_degree']
major = request.form['major']
thesis = request.form['thesis']
application_date = date.today()
# insert into database
cur = mydb.cursor()
cur.execute("INSERT INTO GradApplication (student_id, application_date, graduating_status, thesis, graduating_degree) VALUES (%s, %s, %s, %s, %s)", (student_id, application_date, major, thesis, graduation_degree))
mydb.commit()
return redirect(url_for('success'))
else:
return render_template('apply-grad.html')
@app.route('/success')
def success():
return render_template('gradsuccess.html')
@app.route('/grad-applications')
def grad_applications():
mydb = mysql.connector.connect(
host = "group-11.ci6j3qzwmmr9.us-east-1.rds.amazonaws.com",
user="admin",
password="Password11",
database="university"
)
cur = mydb.cursor(dictionary=True)
cur.execute("SELECT * FROM GradApplication")
gradApplications = cur.fetchall()
return render_template('grad-applications.html', gradApplications=gradApplications)
@app.route('/view-grad-applications')
def view_grad_applications():
mydb = mysql.connector.connect(
host = "group-11.ci6j3qzwmmr9.us-east-1.rds.amazonaws.com",
user="admin",
password="Password11",
database="university"
)
cur = mydb.cursor(dictionary=True)
cur.execute("SELECT student_id, graduating_degree, application_date, graduating_status, thesis, metRequirements FROM GradApplication")
grad_applications = cur.fetchall()
cur.close()
return render_template('view-grad-applications.html', grad_applications=grad_applications)
@app.route('/approve-grad-application/<int:application_id>')
def approve_grad_application(application_id):
mydb = mysql.connector.connect(
host = "group-11.ci6j3qzwmmr9.us-east-1.rds.amazonaws.com",
user="admin",
password="Password11",
database="university"
)
cur = mydb.cursor()
cur.execute("UPDATE GradApplication SET isApproved = 1 WHERE student_id = %s", (application_id,))
cur.execute("UPDATE users SET userType= %s WHERE userID = %s", ('Alumni', application_id))
mydb.commit()
return redirect(url_for('view_grad_applications'))
@app.route('/form1', methods=['GET', 'POST'])
def form1():
if request.method == 'POST':
# Get form data
univ_id = request.form['univ-id']
last_name = request.form['last-name']
first_name = request.form['first-name']
degree = request.form['degree']
course_list = []
for i in range(1, 13):
course_dept = request.form.get(f"course-{i}")
course_num = request.form.get(f"courseNumber-{i}")
if course_dept and course_num:
course_list.append(f"{course_dept} {course_num}")
extremely_long_string = ", ".join(course_list)
is_approved = False
# Insert data into database
cnx = mysql.connector.connect(
host = "group-11.ci6j3qzwmmr9.us-east-1.rds.amazonaws.com",
user="admin",
password="Password11",
database="university"
)
cursor = cnx.cursor()
add_form1 = ("INSERT INTO Form1 "
"(UserID, ExtremelyLongString, IsApproved) "
"VALUES (%s, %s, %s)")
data_form1 = (univ_id, extremely_long_string, is_approved)
cursor.execute(add_form1, data_form1)
cnx.commit()
cursor.close()
cnx.close()
# Redirect to success page
return render_template('form1_success.html')
else:
return render_template('form1.html')
db = mysql.connector.connect(
host = "group-11.ci6j3qzwmmr9.us-east-1.rds.amazonaws.com",
user="admin",
password="Password11",
database="university"
)
@app.route('/form1s')
def list_form1s():
cursor = db.cursor()
cursor.execute("SELECT * FROM Form1")
form1s = cursor.fetchall()
return render_template('form1_list.html', form1s=form1s)
@app.route('/update_is_approved', methods=['POST'])
def update_is_approved():
cursor = db.cursor()
form1_id = request.form['form1_id']
is_approved = request.form['is_approved']
cursor.execute("UPDATE Form1 SET IsApproved=1 WHERE UserID=%s", (form1_id,))
db.commit()
return "Form1 updated successfully, return <a href='/faculty'>home</a>."
#return render_template('form1changed.html')
@app.route('/assignadvisor', methods=['POST'])
def assign_advisor():
# Get the student ID and advisor ID from the form data
student_id = request.form['student']
advisor_id = request.form['advisor']
# Update the Student table in the database
cursor = mydb.cursor()
cursor.execute("UPDATE Student SET advisor_id = %s WHERE studentID = %s", (advisor_id, student_id))
mydb.commit()
# Redirect to a confirmation page
return render_template('assignconfirmation.html', student_id=student_id, advisor_id=advisor_id)
@app.route('/search', methods= ['GET', 'POST'])
def searchApp():
# mydb = get_mysql_connection()
if 'userID' not in session:
return redirect('/')
if session['utype'] != 'Faculty':
if session['utype'] != 'CAC':
return redirect('/')
cursor = mydb.cursor(dictionary=True)
if request.method == 'POST':
IDapp = request.form["IDapp"]
cursor.execute("SELECT * FROM Applications WHERE applicationID =(%s)",
(IDapp, ))
result = cursor.fetchone()
if not result:
return redirect(url_for('viewList'))
if result:
return render_template('listOfApplications.html', result=result)
return redirect('/')
@app.route('/GS')
def gsHome():
if(session['utype'] == 'CAC'):
return redirect('/cac')
if session['utype'] != 'GS':
return redirect('/')
return render_template('gsPage.html')
@app.route('/GS/addTranscripts', methods=['GET', 'POST'])
def addTranscripts():
# post will go here
# mydb = get_mysql_connection()
if session['utype'] != 'GS':
return redirect('/')
if request.method == 'POST':
thisID = request.form['id']
cursor = mydb.cursor(buffered=True)
# error check in case multiple applications
cursor.execute("UPDATE ApplicationChecklist SET transcriptReceived = 1 WHERE iduser = (%s)", (thisID,))
mydb.commit()
cursor = mydb.cursor(dictionary=True)
cursor.execute("SELECT fname, lname, UserID FROM users JOIN ApplicationChecklist ON UserID = iduser WHERE transcriptReceived = 0")
apps = cursor.fetchall()
return render_template('addTranscripts.html', applicants = apps)
@app.route('/GS/decide')
def viewDecisions():
# mydb = get_mysql_connection()
if session['utype'] != 'GS':
if session['utype'] != 'CAC':
return redirect('/')
#base info on getting appid, not user id
cursor = mydb.cursor(dictionary=True)
# need to error check decision recieved
# possibly drop application checklists once final decision has been made
cursor.execute("SELECT * FROM users JOIN ApplicationChecklist ON UserID = IDuser WHERE GREIncluded = 1 AND transcriptReceived = 1 AND isReferenced = 1 AND isReviewed= 1 AND finaldecisionreceived = 0")
curApplicants = cursor.fetchall()
return render_template('decideApplicants.html', applicants = curApplicants)
@app.route('/GS/<userData>', methods=['GET', 'POST'])
def decide(userData):
mydb = mysql.connector.connect(
host = "group-11.ci6j3qzwmmr9.us-east-1.rds.amazonaws.com",
user="admin",
password="Password11",
database="university"
)
#cursor = mydb.cursor(dictionary=True)
if session['utype'] != 'GS':
return redirect('/')
print("before post")
if request.method =='POST':
print("after post")
#convert to int
decision = request.form['decision']
comment = request.form['reason']
admissionDate = request.form['admissionDate']
recAdvisor = request.form['recommendedAdvisor']
cursor = mydb.cursor(dictionary=True)
cursor.execute("INSERT INTO DecisionInfo VALUES((%s), (%s), (%s), (%s), (%s), (%s))", (userData, session['userID'],decision,comment,admissionDate,recAdvisor))
cursor.execute("UPDATE ApplicationChecklist SET finaldecisionreceived = 1 WHERE IDapp = (%s)", (userData,))
mydb.commit()
return redirect("/GS/decide")
print("didn't post")
cursor2 = mydb.cursor(dictionary=True)
cursor2.execute("SELECT * FROM ReviewInfo WHERE IDA = (%s)", (userData,))
info = cursor2.fetchall()
cursor2.execute("SELECT * FROM Applications JOIN users ON userIdent = UserID JOIN PriorDegree ON applicationID = AID WHERE applicationID = (%s)", (userData,))
applicant = cursor2.fetchone()
cursor2.fetchall()
cursor2.execute("SELECT * FROM GRE WHERE AppID = (%s)", (applicant['applicationID'],))
gre = cursor2.fetchone()
cursor2.fetchall()
if gre:
return render_template('decideApplicantIndividual.html', information = info, userI = userData, app = applicant, gre=gre)
return render_template('decideApplicantIndividual.html', information = info, userI = userData, app = applicant)
@app.route('/cac')
def cac():
if session['utype'] != 'CAC':
return redirect('/')
return render_template('cacHome.html')
@app.route('/sysadmin')
def admin():
if session['utype'] != 'ADMIN':
return redirect('/')
return render_template('sysadmin.html')
@app.route('/sysadmin/manage', methods=['GET', 'POST'])
def adminManage():
# mydb = get_mysql_connection()
if session['utype'] != 'ADMIN':
return redirect('/')
cursor = mydb.cursor(dictionary=True)
if request.method == 'POST':
deleteEmail = request.form['userEmail']
cursor.execute('DELETE FROM users WHERE email = (%s)', (deleteEmail,))
mydb.commit()
flash("User deleted")
cursor.execute("SELECT * FROM users")
userList = cursor.fetchall()
return render_template('sysManage.html', users = userList)
@app.route('/sysadmin/addFaculty', methods=['GET', 'POST'])
def adminAddFaculty():
# mydb = get_mysql_connection()
if session['utype'] != 'ADMIN':
return redirect('/')
# if method = post
if request.method == 'POST':
# take info and create new faculty member
firstname = request.form['fname']
lastname = request.form['lname']
email = request.form['email']
password = request.form['password']
usertype = request.form['usertype']
primaryaddress = request.form['primaryaddress']
primaryphone = request.form['primaryphone']
ssn = request.form['ssn']
newID = generateUserId()
cursor = mydb.cursor(dictionary=True)
# error check to make sure al forms are filled out
cursor.execute("INSERT INTO users VALUES((%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s),(%s)) ", (newID, email, password, firstname, lastname, usertype, primaryaddress, primaryphone, ssn))
# flash to let admin know that user has been added
mydb.commit()
flash("User " + firstname + " "+ lastname + " has been added")
return render_template('sysAddFaculty.html')
@app.route('/sysadmin/<userData>', methods=['GET', 'POST'])
def adminView(userData):
# mydb = get_mysql_connection()
if session['utype'] != 'ADMIN':
return redirect('/')
# if method post, have recieved confirmation to edit a user
if request.method == 'POST':
change = request.form['proposedChange']
colName = request.form['columnType']
cur = mydb.cursor(dictionary=True)
cur.execute(f"UPDATE users SET fName = (%s) WHERE email = (%s)", (change, userData))
# flash admin that user values were updated
flash("User values have been updateed")
cursor = mydb.cursor(dictionary=True)
cursor.execute("SELECT * FROM users WHERE email = (%s)", (userData,))
currentValues = cursor.fetchone()
return render_template('sysViewUser.html', values = currentValues)
def generateUserId():
# mydb = get_mysql_connection()
cursor = mydb.cursor(dictionary=True)
while(1):
id = str(random.randint(10000000,99999999))
cursor.execute("SELECT * FROM users WHERE UserID = (%s)",(id,))
result = cursor.fetchone()
if not result: #if result does not exist, return the id
return id
@app.route('/recommender', methods=['GET','POST'])
def recommender():
# mydb = get_mysql_connection()
# if session['utype'] != 'Recommender':
# return redirect('/')
cursor = mydb.cursor(dictionary=True)
#cursor.execute("SELECT * FROM Applications JOIN ApplicationChecklist ON applicationID = IDapp WHERE referencer1email = (%s) AND reference1Recieved = 0",(session['email'],))
cursor.execute("SELECT * FROM referenceInfo JOIN checkReference ON referenceInfo.appID = checkReference.idApp JOIN Applications ON referenceInfo.appID = Applications.applicationID WHERE referenceInfo.referencer1email = (%s) AND checkReference.reference1received = 0", (session['email'],))
reference1 = cursor.fetchone()
test = cursor.fetchone()
while test != None:
test = cursor.fetchone()
#cursor.execute("SELECT * FROM Applications JOIN ApplicationChecklist ON applicationID = IDapp WHERE referencer2email = (%s) AND reference2Recieved = 0",(session['email'],))
cursor.execute("SELECT * FROM referenceInfo JOIN checkReference ON referenceInfo.appID = checkReference.idApp JOIN Applications ON referenceInfo.appID = Applications.applicationID WHERE referenceInfo.referencer2email = (%s) AND checkReference.reference2received = 0", (session['email'],))
reference2 = cursor.fetchone()
test = cursor.fetchone()
while test != None:
test = cursor.fetchone()
cursor.execute("SELECT * FROM referenceInfo JOIN checkReference ON referenceInfo.appID = checkReference.idApp JOIN Applications ON referenceInfo.appID = Applications.applicationID WHERE referenceInfo.referencer3email = (%s) AND checkReference.reference3received = 0", (session['email'],))
reference3 = cursor.fetchone()
print("check if it is ref3")
test = cursor.fetchone()
while test != None:
test = cursor.fetchone()
if reference1 != None:
if request.method == 'POST':
rec = request.form['recommendation']
cursor.execute("INSERT INTO Recommendation(referencerfname, referencerlname, letter, IDApplication) VALUES((%s), (%s), (%s), (%s))", (reference1['referencer1fname'], reference1['referencer1lname'], rec, reference1['applicationID']))
cursor.execute("UPDATE checkReference SET reference1received = 1 WHERE idApp = (%s)", (reference1['applicationID'],))
mydb.commit()
return redirect("/")
cursor.execute("SELECT * FROM users WHERE UserID = (%s)", (reference1['userIdent'],))
applicant = cursor.fetchone()
return render_template("recommender.html", fname = applicant['fName'], lname = applicant['lName'])
elif reference2 != None:
if request.method == 'POST':
rec = request.form['recommendation']
cursor.execute("INSERT INTO Recommendation(referencerfname, referencerlname, letter, IDApplication) VALUES((%s), (%s), (%s), (%s))", (reference2['referencer2fname'], reference2['referencer2lname'], rec, reference2['applicationID']))
cursor.execute("UPDATE checkReference SET reference2received = 1 WHERE IDapp = (%s)", (reference2['applicationID'],))
mydb.commit()
return redirect("/")
cursor.execute("SELECT * FROM users WHERE UserID = (%s)", (reference2['userIdent'],))
applicant = cursor.fetchone()
return render_template("recommender.html")
elif reference3 != None:
print(reference3)
if request.method == 'POST':
rec = request.form['recommendation']
cursor.execute("INSERT INTO Recommendation(referencerfname, referencerlname, letter, IDApplication) VALUES((%s), (%s), (%s), (%s))", (reference3['referencer3fname'], reference3['referencer3lname'], rec, reference3['applicationID']))
cursor.execute("UPDATE checkReference SET reference3received = 1 WHERE IDapp = (%s)", (reference3['applicationID'],))
mydb.commit()
return redirect("/")
cursor.execute("SELECT * FROM users WHERE UserID = (%s)", (reference3['userIdent'],))
applicant = cursor.fetchone()
return render_template("recommender.html")
print("reaches here")
return redirect('/')
def generateAppID():
# mydb = get_mysql_connection()
cursor = mydb.cursor(dictionary=True)
while(1):
id = str(random.randint(10000000,99999999))
cursor.execute("SELECT * FROM Applications WHERE applicationID = (%s)",(id,))
result = cursor.fetchone()
if not result: #if result does not exist, return the id
return id
@app.route('/applicant/',methods=['GET','POST'])
def applicant():
# mydb = get_mysql_connection()
if 'userID' not in session or session['utype'] != 'Applicant':
return redirect('/')
cursor = mydb.cursor(dictionary=True)
userid = session["userID"]
#check status of application
cursor.execute("SELECT * FROM ApplicationChecklist WHERE transcriptReceived = 1 AND isReviewed = 1 AND isReferenced = 1 AND finaldecisionreceived=1 AND isCompleted=1 AND IDuser = (%s)", (userid,))
decisionMade = cursor.fetchall()
cursor.execute("SELECT * FROM ApplicationChecklist WHERE transcriptReceived = 1 AND (isReviewed = 0 OR finaldecisionreceived = 0) AND isReferenced = 1 AND isCompleted =1 AND IDuser = (%s)", (userid,))
completed = cursor.fetchall()
cursor.execute("SELECT * FROM ApplicationChecklist WHERE (transcriptReceived = 0 OR isReferenced = 0 OR isCompleted = 0) AND IDuser = (%s)", (userid,))
incomplete = cursor.fetchall()
if decisionMade:
print("decision ready to be viewed")
status = "A Decision Has Been Made. Please Check on your Portal"
elif completed:
print("complete:")
print(completed)
status = "Application Complete and Under Review/No Decision Yet"
elif incomplete:
print("incomplete")
print(incomplete)
status = "Application Incomplete - materials missing"
else:
status = "Status Currently Not Available"
#check if application has at least one reference
cursor.execute("SELECT * FROM checkReference JOIN ApplicationChecklist ON ApplicationChecklist.IDapp = checkReference.idApp WHERE (reference1received=1 OR reference2received=1 OR reference3received=1) AND IDuser=(%s)", (userid,))
refReceived = cursor.fetchall()
if refReceived:
cursor.execute("UPDATE ApplicationChecklist SET isReferenced=1 WHERE IDuser=(%s)",(userid,))
mydb.commit()
#check if application is complete and ready to review
#for doctoral
cursor.execute("SELECT * FROM ApplicationChecklist JOIN Applications ON ApplicationChecklist.IDapp = Applications.applicationID WHERE degreeSought=1 AND GREIncluded=1 AND transcriptReceived=1 AND isReferenced=1 AND IDuser =(%s)", (userid,))
foundD = cursor.fetchall()
#for masters
cursor.execute("SELECT * FROM ApplicationChecklist JOIN Applications ON ApplicationChecklist.IDapp = Applications.applicationID WHERE degreeSought=0 AND transcriptReceived=1 AND isReferenced=1 AND IDuser =(%s)", (userid,))
foundM = cursor.fetchall()
if foundD:
cursor.execute("UPDATE ApplicationChecklist SET isCompleted=1 WHERE IDuser=(%s)",(userid,))
mydb.commit()
elif foundM:
cursor.execute("UPDATE ApplicationChecklist SET isCompleted=1 WHERE IDuser=(%s)",(userid,))
mydb.commit()
#check if application has at least one review
cursor.execute("SELECT * FROM checkReview JOIN ApplicationChecklist ON ApplicationChecklist.IDapp = checkReview.idAPP WHERE (review1received=1 OR review2received=1 OR review3received=1) AND IDuser=(%s)", (userid,))
revReceived = cursor.fetchall()
if revReceived:
cursor.execute("UPDATE ApplicationChecklist SET isReviewed=1 WHERE IDuser=(%s)",(userid,))
mydb.commit()
cursor.execute("SELECT * FROM ApplicationChecklist WHERE IDuser = %s",(userid,))
result = cursor.fetchall()
cursor.execute("SELECT * FROM Applications WHERE userIdent = %s ORDER BY applicationID ASC",(userid,))
data = cursor.fetchall()
required = []
if data:
for i in data:
if(i["degreeSought"] == 1):
required.append("YES")
if(i["degreeSought"] == 0):
required.append("NO")
if result:
return render_template("applicant.html",all=zip(result,required), status=status)
else:
return render_template("applicant.html",all=zip(result,required), status =status)
# UNUSED CODE. ABSOLUTELY WORTHLESS BUT IN HERE IN CASE WE WANT TO MAKE A MODIFIED APPLICATIONS PAGE.
@app.route('/applications/', methods =['GET','POST'])
def applications():
# mydb = get_mysql_connection()
if session['utype'] != 'Applicant':
return redirect('/')
cursor = mydb.cursor(dictionary=True)
userid = session["userid"]
cursor.execute("SELECT * FROM ApplicationChecklist WHERE IDuser = %s ORDER BY IDapp ASC",(userid,))
result = cursor.fetchall()
cursor.execute("SELECT * FROM Applications WHERE userIdent = %s ORDER BY applicationID ASC",(userid,))
data = cursor.fetchall()
required = []
if data:
for i in data:
if(i["degreeSought"] == 1):
required.append("YES")
if(i["degreeSought"] == 0):
required.append("NO")
if result:
return render_template("applications.html",result=result,required=required)
else:
return render_template("applications.html",result=result,required=required)
@app.route('/applications/editgre/<aid>/<uid>',methods=['GET','POST'])
def greAddEdit(aid,uid):
# mydb = get_mysql_connection()
error = None
# If the username/password is correct, log them in and redirect them to the home page. Remember to set your session variables!
if request.method == 'GET':
# connection = sqlite3.connect('myDatabase.db')
# connection.row_factory = sqlite3.Row
# c = connection.cursor()
return render_template('gre.html',error=error,aid=aid,uid=uid)
if request.method == 'POST':
c = mydb.cursor(buffered=True,dictionary=True)
greverbal = request.form["greverbal"]
grequantitative = request.form["grequantitative"]
gretotal = greverbal+grequantitative
greascore = request.form["greascore"]
greasubject = request.form["greasubject"]
toefl = request.form["toefl"]
toefldate= request.form["toefl"]
greyear = request.form["greyear"]
if(greverbal == '' or grequantitative == '' or greascore == '' or greasubject == '' or toefl == '' or toefldate == '' or greyear == '' ) :
error = "please fill out all forms."
return render_template('gre.html', error=error,aid=aid,uid=uid)
c.execute("SELECT * FROM GRE WHERE AppID=(%s) AND UI=(%s)",(aid,uid))
data = c.fetchone()
if data:
c.execute("DELETE FROM GRE WHERE AppID=(%s) AND UI=(%s)",(aid,uid))
mydb.commit()
c.execute("INSERT INTO GRE (AppID,UI,GREScore,Verbal,Quantitative,GREAdvScore,GREAdvSbj,TOEFL,TOEFLDate,examYear) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) ", (
aid,
uid,
gretotal,
greverbal,
grequantitative,
greascore,
greasubject,
toefl,
toefldate,
greyear
))
mydb.commit()
t = True
c.execute(
"UPDATE ApplicationChecklist SET GREIncluded=(%s) WHERE IDapp = (%s)", (
t,aid
))
c.execute(
"UPDATE Applications SET GREInclude=(%s) WHERE applicationID = (%s)", (
gretotal,aid
))
c.execute("SELECT * FROM GRE WHERE AppID=(%s) AND UI=(%s)",(aid,uid))
data = c.fetchone()