-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
1331 lines (988 loc) · 59.5 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
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 csv
import os
import shutil
import sqlite3
import zipfile
from collections import Counter
from datetime import datetime, timedelta
from flask import (Flask, jsonify, redirect, render_template, request,
send_file, url_for)
import import_csv_from_redcap
app = Flask(__name__)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 300
# Replace with your SQLite database file path
db_path = 'student_intern_data/student_intern_data.db'
@app.route('/email_intake/<int:intake_id>', methods=['GET'])
def email_intake(intake_id):
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute('SELECT * FROM Intakes WHERE id = ?',(intake_id,))
intake = cursor.fetchall()[0]
intake_name = intake[1]
intake_science_start_date = intake[3]
intake_engit_start_date = intake[4]
# Retrieve student data from the database
cursor.execute('SELECT * FROM Statuses')
statuses = cursor.fetchall()
status_of_students_to_filter = [10,11,12,13] # from quick review to Interviewed by non-RCP supervisor
current_statuses_list = [row[1] for row in statuses if row[0] in status_of_students_to_filter]
# Retrieve student data from the database
# Prepare the SQL query with a placeholder for the statuses filter
query = '''
SELECT intern_id, full_name, email, course
FROM Students
WHERE intake = ? AND status IN ({})
'''.format(','.join(['?'] * len(current_statuses_list)))
# Execute the query with the statuses list
cursor.execute(query, [intake_name] + current_statuses_list )
students = cursor.fetchall()
student_emails = {'science':[],'engit':[]}
for student in students:
email = student[2]
course = student[3]
if course == 'Science':
student_emails['science'].append(email)
if course == 'Engineering and IT':
student_emails['engit'].append(email)
science_student_emails = ",".join(x for x in student_emails['science'])
engit_student_emails = ",".join(x for x in student_emails['engit'])
science_start_date_object = datetime.strptime(intake_science_start_date, '%Y-%m-%d').date()
engit_start_date_object = datetime.strptime(intake_engit_start_date, '%Y-%m-%d').date()
table_rows = create_email_intake_table_rows(science_start_date_object,engit_start_date_object)
print(table_rows)
return render_template('email_intake.html', intake=intake, science_student_emails=science_student_emails, engit_student_emails=engit_student_emails, table_rows= table_rows)
@app.route('/links/', methods=['GET'])
def links():
return render_template('links.html')
# Allocating students projects
@app.route('/assigned_projects/', methods=['GET', 'PUT'])
def assigned_projects():
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
try:
if request.method == 'GET':
# Fetch the projects from the Projects table
cursor.execute('SELECT id, name FROM Projects ORDER BY status ASC, name ASC' )
projects = cursor.fetchall()
print(projects)
cursor.execute('SELECT name FROM Intakes where status = "new"')
intake_current = cursor.fetchall()[0][0]
cursor.execute('SELECT intern_id, full_name, project, pronouns, status, cover_letter_projects FROM Students WHERE intake = ?',(intake_current,))
students = cursor.fetchall()
cursor.execute('SELECT * FROM Statuses')
statuses = cursor.fetchall()
status_of_students_to_filter = [3,4,5,6,7,8,9,10,11,12,13,14]
current_statuses_list = [row[1] for row in statuses if row[0] in status_of_students_to_filter]
# Retrieve student data from the database
# Prepare the SQL query with a placeholder for the statuses filter
query = '''
SELECT intern_id, full_name, project, pronouns, status, cover_letter_projects,pre_internship_summary_recommendation_internal
FROM Students
WHERE intake = ? AND status IN ({}) ORDER BY status desc, pre_internship_summary_recommendation_internal asc
'''.format(','.join(['?'] * len(current_statuses_list)))
# Execute the query with the statuses list
cursor.execute(query, [intake_current] + current_statuses_list)
students = cursor.fetchall()
print(students)
# Close the database connection
cursor.close()
conn.close()
return render_template('Assigned_projects.html', projects=projects, students=students)
elif request.method == 'PUT':
# Handle the AJAX request for updating the student's project assignment
data = request.get_json()
intern_id = data['internId']
new_project_id = data['projectId']
# Update the student's project assignment in the database
cursor.execute('UPDATE Students SET project = ? WHERE intern_id = ?', (new_project_id, intern_id))
conn.commit()
# Close the database connection
cursor.close()
conn.close()
return jsonify({'status': 'success', 'message': 'Project assignment updated successfully'})
except Exception as e:
# Handle any errors
return jsonify({'status': 'error', 'message': str(e)}), 500
# Route to handle the AJAX request for updating the student's project assignment
@app.route('/update_project_assignment', methods=['PUT'])
def update_project_assignment():
try:
data = request.get_json()
intern_id = data['internId']
new_project_id = data['projectId']
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
# Update the student's project assignment in the database
cursor.execute('UPDATE Students SET project = ? WHERE intern_id = ?', (new_project_id, intern_id))
conn.commit()
# Close the database connection
cursor.close()
conn.close()
return jsonify({'status': 'success', 'message': 'Project assignment updated successfully'})
except Exception as e:
# Handle any errors
return jsonify({'status': 'error', 'message': str(e)}), 500
# Generic Pre Internship Evaluation Per Student
@app.route('/submit_student_evaluation', methods=['POST'])
def submit_student_evaluation():
# Retrieve data from the form
student_id = request.form.get('intern_id')
status = request.form.get('status')
pronunciation = request.form.get('pronunciation')
remote_internship = request.form.get('remote_internship')
code_of_conduct = request.form.get('code_of_conduct')
facilitator_follower = request.form.get('facilitator_follower')
listener_or_talker = request.form.get('listener_or_talker')
thinker_brainstormer = request.form.get('thinker_brainstormer')
cover_letter_projects = request.form.get('cover_letter_projects')
why_applied = request.form.get('why_applied')
projects_recommended = request.form.get('projects_recommended')
Overall_External = request.form.get('Overall_External')
Overall_Internal = request.form.get('Overall_Internal')
learn_quickly_technical = request.form.get('learn_quickly_technical')
learn_domain_concepts = request.form.get('learn_domain_concepts')
Enthusiastic = request.form.get('Enthusiastic')
Experience = request.form.get('Experience')
Written_application = request.form.get('Written_Application')
Phone_interview = request.form.get('Phone_Interview')
#Communication = request.form.get('Written_Application')
Adaptability = request.form.get('Adaptability')
summary_tech_skills = request.form.get('summary_tech_skills')
summary_experience = request.form.get('summary_experience')
extra_notes = request.form.get('extra_notes')
Communication = f"{Written_application} {Phone_interview}"
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
# Update Students Evaluation data in the Students table
cursor.execute('''
UPDATE Students
SET status = ?,
pronunciation = ?,
cover_letter_projects = ?,
pre_internship_summary_recommendation_external = ?,
pre_internship_summary_recommendation_internal = ?,
pre_internship_technical_rating = ?,
pre_internship_learning_quickly = ?,
pre_internship_enthusiasm = ?,
pre_internship_experience = ?,
pre_internship_communication = ?,
pre_internship_adaptable = ?,
summary_tech_skills = ?,
extra_notes = ?,
summary_experience = ?,
remote_internship = ?,
code_of_conduct = ?,
facilitator_follower = ?,
listener_or_talker = ?,
thinker_brainstormer = ?,
why_applied = ?,
projects_recommended = ?
WHERE intern_id = ?
''', (status,pronunciation, cover_letter_projects, Overall_External, Overall_Internal,learn_quickly_technical, learn_domain_concepts, Enthusiastic, Experience, Communication, Adaptability, summary_tech_skills, extra_notes, summary_experience, remote_internship, code_of_conduct, facilitator_follower, listener_or_talker, thinker_brainstormer, why_applied, projects_recommended, student_id))
# Commit the changes and close the database connection
conn.commit()
conn.close()
# Redirect to the student's evaluation page in standardized vocabulary
return redirect(url_for('pre_int_st_evaluation', intern_id=student_id))
@app.route('/pre_int_st_evaluation/<int:intern_id>', methods=['GET'])
def pre_int_st_evaluation(intern_id):
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
# Retrieve the student's details from the database
cursor.execute('SELECT * FROM Students WHERE intern_id = ?', (intern_id,))
student = cursor.fetchone()
# Close the database connection
conn.close()
pronoun = student[2]
# Split the pronoun into multiple parts using the '/' delimiter
#he/him/his or she/her or they/them/their
pronoun_parts = pronoun.split('/')
# Assign pronoun1, pronoun2, and pronoun3 based on the pronoun_parts
pronoun1 = pronoun_parts[0].strip()
pronoun2 = pronoun_parts[1].strip() if len(pronoun_parts) > 1 else ""
# Find matching PDF files
attachments_dir = 'student_intern_data/attachments'
matching_files = []
for filename in os.listdir(attachments_dir):
if filename.startswith(str(intern_id)) and filename.lower().endswith('.pdf'):
matching_files.append(filename)
statuses = get_statuses() # Retrieve the list of statuses from the database
return render_template('pre_int_st_evaluation.html', student=student, pronoun1=pronoun1, pronoun2=pronoun2,statuses=statuses, matching_files=matching_files)
@app.route('/student_evaluation/<int:intern_id>', methods=['GET'])
def student_evaluation(intern_id):
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
# Retrieve the feedback data from the Students table
cursor.execute('SELECT * FROM Students')
st_eval = cursor.fetchall()
# Close the database connection
conn.close()
return render_template('student_evaluation.html', st_eval=st_eval)
# Generic Post Internship Evaluation Per Student
# Submit Feedback Route
@app.route('/submit_feedback', methods=['POST'])
def submit_feedback():
# Retrieve the feedback data from the request form
student_id = request.form.get('intern_id')
adaptability = request.form.get('adaptability')
learn_technical = request.form.get('learn_technical')
learn_conceptual = request.form.get('learn_conceptual')
collaborative = request.form.get('collaborative')
ambiguity = request.form.get('ambiguity')
complexity = request.form.get('complexity')
my_reaction = request.form.get('my_reaction')
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
# Update the feedback data in the Students table
cursor.execute('''
UPDATE Students
SET post_internship_adaptability = ?,
post_internship_learn_technical = ?,
post_internship_learn_conceptual = ?,
post_internship_collaborative = ?,
post_internship_ambiguity = ?,
post_internship_complexity = ?,
post_internship_summary_rating_external = ?
WHERE intern_id = ?
''', (adaptability, learn_technical, learn_conceptual, collaborative, ambiguity, complexity, my_reaction, student_id))
# Commit the changes and close the database connection
conn.commit()
conn.close()
# Redirect to the student's details page
return redirect(url_for('feedback_table', intern_id=student_id))
# feedback
@app.route('/feedback/<int:intern_id>', methods=['GET'])
def feedback(intern_id):
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
# Retrieve the student's details from the database
cursor.execute('SELECT * FROM Students WHERE intern_id = ?', (intern_id,))
student = cursor.fetchone()
# Close the database connection
conn.close()
# Retrieve the pronoun from the database
pronoun = student[2]
# Split the pronoun into multiple parts using the '/' delimiter
pronoun_parts = pronoun.split('/')
# Assign pronoun1, pronoun2 based on the pronoun_parts
pronoun1 = pronoun_parts[0].strip()
pronoun2 = pronoun_parts[1].strip() if len(pronoun_parts) > 1 else ""
return render_template(
'feedback.html',
student=student,
pronoun1=pronoun1,
pronoun2=pronoun2
)
@app.route('/feedback_table/<int:intern_id>', methods=['GET'])
def feedback_table(intern_id):
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
# Retrieve the feedback data from the Students table
cursor.execute('SELECT * FROM Students')
students = cursor.fetchall()
# Close the database connection
conn.close()
return render_template('feedback_table.html', students=students)
@app.route('/download_key_attributes')
def download_key_attributes():
data = request.args.getlist('student_ids')
values = data[0].split(',')
student_ids = [int(value) for value in values]
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
cursor.execute('SELECT full_name, pronunciation, project, status, mobile, email, start_date, end_date, hours_per_week, pronouns, pre_internship_summary_recommendation_internal FROM Students WHERE intern_id IN ({})'.format(','.join('?' for _ in student_ids)), student_ids)
students = cursor.fetchall()
# Create a temporary directory to store the files
temp_dir = 'student_intern_data/attachments/tmp'
try:
os.makedirs(temp_dir)
except Exception:
pass
# Get the current datetime
now = datetime.now()
formatted_datetime = now.strftime("%Y-%m-%d-%H:%M:%S")
# Create the CSV file inside the temporary directory
csv_path = os.path.join(temp_dir, formatted_datetime+'_student_data.csv')
with open(csv_path, 'w') as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(['Full Name', 'Pronunciation','Project','Status','Phone', 'Email', 'Start Date', 'End Date', 'Hours per Week','Pronouns','Summary pre-internship'])
for student in students:
# Retrieve student data from the database
# Write the student data to the CSV file
csv_writer.writerow(student)
return send_file(csv_path, as_attachment=True)
def get_statuses():
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute('SELECT name FROM Statuses')
statuses = [row[0] for row in cursor.fetchall()]
conn.close()
return statuses
def get_intakes():
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute('SELECT name FROM Intakes')
intakes = [row[0] for row in cursor.fetchall()]
conn.close()
return intakes
def get_all_intakes():
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute('SELECT * FROM Intakes')
intakes = [row for row in cursor.fetchall()]
conn.close()
return intakes
def get_all_projects():
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute('SELECT * FROM projects')
projects = [row for row in cursor.fetchall()]
conn.close()
return projects
def get_projects():
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute('SELECT id, name FROM Projects')
projects = [{'id': row[0], 'name': row[1]} for row in cursor.fetchall()]
conn.close()
return projects
def get_student_by_id(intern_id):
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute('SELECT * FROM Students WHERE intern_id = ?', (intern_id,))
student = cursor.fetchone()
conn.close()
return student
def update_student(intern_id, data):
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
cursor.execute('UPDATE Students SET github_username = ?, full_name = ?, pronouns = ?, status = ?, email = ?, wehi_email = ?, mobile = ?, course = ?, course_major = ?, intake = ?, project = ?, start_date = ?, end_date = ?, hours_per_week = ?, cover_letter_projects = ?, pronunciation = ?, post_internship_summary_rating_internal = ? WHERE intern_id = ?',
(data['github_username'], data['full_name'], data['pronouns'], data['status'], data['email'], data['wehi_email'], data['mobile'], data['course'], data['course_major'], data['intake'], data['project'], data['start_date'], data['end_date'], data['hours_per_week'], data['cover_letter_projects'],data['pronunciation'],data['post_internship_summary_rating_internal'], intern_id))
conn.commit()
conn.close()
@app.route('/edit_student/<int:intern_id>', methods=['GET', 'POST'])
def edit_student(intern_id):
if request.method == 'POST':
# Handle form submission and update the student record in the database
print(request.form)
data = {
'full_name': request.form['full_name'],
'pronouns': request.form['pronouns'],
'status': request.form['status'],
'email': request.form['email'],
'wehi_email': request.form['wehi_email'],
'mobile': request.form['mobile'],
'course': request.form['course'],
'course_major': request.form['course_major'],
'github_username': request.form['github_username'],
'intake': request.form['intake'],
'project': request.form['project'],
'start_date': request.form['start_date'],
'end_date': request.form['end_date'],
'hours_per_week': request.form['hours_per_week'],
'pronunciation': request.form['pronunciation'],
'post_internship_summary_rating_internal': request.form['post_internship_summary_rating_internal'],
'cover_letter_projects': request.form['cover_letter_projects'],
}
update_student(intern_id, data) # Update the student record in the database
# Redirect to the student details page after updating
# Get the referrer URL
referrer = request.referrer
return redirect(referrer)
else:
# Retrieve the student record from the database based on the intern_id
# Pass the student record, statuses, intakes, and projects to the edit.html template
student = get_student_by_id(intern_id)
statuses = get_statuses() # Retrieve the list of statuses from the database
intakes = get_intakes() # Retrieve the list of intakes from the database
projects = get_projects() # Retrieve the list of projects from the database
return render_template('edit.html', student=student, statuses=statuses, intakes=intakes, projects=projects)
@app.route('/share_students/<int:project_id>')
def share_students(project_id):
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
cursor.execute('SELECT name FROM Intakes where status = "new"')
intake_current = cursor.fetchall()[0][0]
# Retrieve student data from the database
cursor.execute('SELECT * FROM Statuses')
statuses = cursor.fetchall()
if project_id == 0:
status_of_students_to_filter = [3,4,5,6] # from quick review to Interviewed by non-RCP supervisor
current_statuses_list = [row[1] for row in statuses if row[0] in status_of_students_to_filter]
# Retrieve student data from the database
# Prepare the SQL query with a placeholder for the statuses filter
query = '''
SELECT intern_id, full_name, email, mobile, intake, course, course_major , cover_letter_projects, pronunciation, summary_tech_skills, summary_experience, pre_internship_summary_recommendation_external, pre_internship_technical_rating || ' ' || pre_internship_learning_quickly || ' ' || pre_internship_enthusiasm || ' ' || pre_internship_experience || ' ' || pre_internship_communication || ' ' || pre_internship_adaptable AS student_details, github_username
FROM Students
WHERE intake = ? AND status IN ({})
'''.format(','.join(['?'] * len(current_statuses_list)))
# Execute the query with the statuses list
cursor.execute(query, [intake_current] + current_statuses_list )
else:
status_of_students_to_filter = [8,9,10,11,12,13] # from quick review to Interviewed by non-RCP supervisor
current_statuses_list = [row[1] for row in statuses if row[0] in status_of_students_to_filter]
cursor.execute('SELECT * FROM Projects where id = ?',(project_id,))
project = cursor.fetchall()[0][1]
print(project)
query = '''
SELECT intern_id, full_name, email, mobile, intake, course, course_major, cover_letter_projects, pronunciation,
summary_tech_skills, summary_experience, pre_internship_summary_recommendation_external,
pre_internship_technical_rating || ' ' || pre_internship_learning_quickly || ' ' || pre_internship_enthusiasm ||
' ' || pre_internship_experience || ' ' || pre_internship_communication || ' ' || pre_internship_adaptable AS student_details,
github_username
FROM Students
WHERE intake = ? AND project = ? AND status IN ({})
'''.format(','.join(['?'] * len(current_statuses_list)))
# Execute the query with the statuses list, intake, and project as parameters
cursor.execute(query, [intake_current, project] + current_statuses_list)
students = cursor.fetchall()
# Create a temporary directory to store the files
temp_dir = 'student_intern_data/attachments/tmp'
try:
os.makedirs(temp_dir)
except Exception:
pass
# Create the CSV file inside the temporary directory
csv_path = os.path.join(temp_dir, 'share_student_data.csv')
print(csv_path)
with open(csv_path, 'w') as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(['ID', 'Full Name', 'Email','Phone', 'Intake', 'Faculty', 'Course', 'Interested in Projects','Pronunciation','Tech Skills','Experience','Summary of Student','Details of Student','github username'])
for student in students:
# Write the student data to the CSV file
csv_writer.writerow(student)
# Create the ZIP file
zip_path = 'student_intern_data/attachments/share_student_applications_temp.zip'
with zipfile.ZipFile(zip_path, 'w') as zip_file:
# Add the PDF files for each student to the ZIP file
for student in students:
intern_id = student[0]
# Get all PDF files starting with the intern_id
matching_files = [filename for filename in os.listdir('student_intern_data/attachments') if filename.startswith(str(intern_id)) and filename.lower().endswith('.pdf')]
# Copy the matching PDF files to the temporary directory
for file in matching_files:
file_path = os.path.join('student_intern_data/attachments', file)
dest_path = os.path.join(temp_dir, file)
shutil.copy(file_path, dest_path)
# Create a zip file of the other files
with zipfile.ZipFile(zip_path, 'w') as zip_file:
for folder_name, _, file_names in os.walk(temp_dir):
for file_name in file_names:
file_path = os.path.join(folder_name, file_name)
zip_file.write(file_path, os.path.basename(file_path))
# Remove the temporary directory
shutil.rmtree(temp_dir)
# Close the database connection
conn.close()
# Get today's date
today = datetime.now()
# Format the date as YYYY-mm-dd
formatted_date = today.strftime("%Y-%m-%d")
# Serve the ZIP file for download
if project_id == 0:
return send_file(zip_path, as_attachment=True, download_name=formatted_date+'_student_applications.zip')
else:
return send_file(zip_path, as_attachment=True, download_name=formatted_date+'_student_applications_'+project+'.zip')
@app.route('/download_contracts_and_applications')
def download_contracts_and_applications():
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
# Retrieve students with status '09 Signed contract' from the database
cursor.execute('SELECT intern_id, full_name FROM Students WHERE status = ?', ('09 Signed contract',))
students = cursor.fetchall()
# Create a temporary directory to store the files
temp_dir = 'student_intern_data/attachments/tmp'
try:
os.makedirs(temp_dir)
except Exception:
pass
# Create the CSV file inside the temporary directory
csv_path = os.path.join(temp_dir, 'student_data.csv')
with open(csv_path, 'w') as csv_file:
csv_writer = csv.writer(csv_file)
csv_writer.writerow(['Full Name', 'Phone', 'Email', 'Faculty', 'Start Date', 'End Date', 'Hours per Week'])
for student in students:
# Retrieve student data from the database
cursor.execute('SELECT full_name, mobile, email, course, start_date, end_date, hours_per_week FROM Students WHERE intern_id = ?', (student[0],))
student_data = cursor.fetchone()
# Write the student data to the CSV file
csv_writer.writerow(student_data)
# Create the ZIP file
zip_path = 'student_intern_data/attachments/contract_downloads_temp.zip'
with zipfile.ZipFile(zip_path, 'w') as zip_file:
# Add the PDF files for each student to the ZIP file
for student in students:
intern_id = student[0]
# Get all PDF files starting with the intern_id
matching_files = [filename for filename in os.listdir('student_intern_data/attachments') if filename.startswith(str(intern_id)) and filename.lower().endswith('.pdf')]
# Copy the matching PDF files to the temporary directory
for file in matching_files:
file_path = os.path.join('student_intern_data/attachments', file)
dest_path = os.path.join(temp_dir, file)
shutil.copy(file_path, dest_path)
# Create a zip file of the other files
with zipfile.ZipFile(zip_path, 'w') as zip_file:
for folder_name, _, file_names in os.walk(temp_dir):
for file_name in file_names:
file_path = os.path.join(folder_name, file_name)
zip_file.write(file_path, os.path.basename(file_path))
# Remove the temporary directory
shutil.rmtree(temp_dir)
# Close the database connection
conn.close()
# Get today's date
today = datetime.now()
# Format the date as YYYY-mm-dd
formatted_date = today.strftime("%Y-%m-%d")
# Serve the ZIP file for download
return send_file(zip_path, as_attachment=True, download_name=formatted_date+'_contract_files.zip')
@app.route('/import_redcap', methods=['GET', 'POST'])
def import_redcap():
today = datetime.now()
import_dir = 'student_intern_data/import/archive'
if request.method == 'POST':
print(request.files)
csv_file = request.files['csv_file']
if csv_file:
filename = csv_file.filename
csv_file_path = os.path.join(import_dir, filename)
csv_file.save(csv_file_path)
zip_file = request.files['zip_file']
if zip_file:
filename = zip_file.filename
zip_file_path = os.path.join(import_dir, filename)
zip_file.save(zip_file_path)
import_csv_from_redcap.read_csv_file(csv_file_path,zip_file_path)
# Get the referrer URL
referrer = request.referrer
# Redirect back to the previous page
return redirect(referrer)
return render_template('import_redcap.html')
@app.route('/upload_signed_contract/<int:intern_id>/<string:full_name>', methods=['GET', 'POST'])
def upload_signed_contract(intern_id, full_name):
attachments_dir = 'student_intern_data/attachments'
if request.method == 'POST':
file = request.files['file']
if file:
# Save the file to the attachments directory with the desired filename
filename = str(intern_id)+"_"+full_name.replace(" ", "_").title()+"_signed_contract.pdf"
file.save(os.path.join(attachments_dir, filename))
# Get the referrer URL
referrer = request.referrer
# Redirect back to the previous page
return redirect(referrer)
return render_template('upload_signed_contract.html', intern_id=intern_id, full_name=full_name)
@app.route('/new_intake_unavailable')
def index_new_intake_unavailable():
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
cursor.execute('SELECT * FROM Projects')
projects = cursor.fetchall()
cursor.execute('SELECT name FROM Intakes where status = "new"')
intake_current = cursor.fetchall()[0][0]
# Retrieve student data from the database
cursor.execute('SELECT * FROM Statuses')
statuses = cursor.fetchall()
status_of_students_to_filter = [15,16,17,18,19,20,21]
current_statuses_list = [row[1] for row in statuses if row[0] in status_of_students_to_filter]
# Retrieve student data from the database
# Prepare the SQL query with a placeholder for the statuses filter
query = '''
SELECT intern_id, full_name, email, pronunciation, project, intake, course, status, post_internship_summary_rating_internal, wehi_email, mobile
FROM Students
WHERE intake = ? AND status IN ({})
'''.format(','.join(['?'] * len(current_statuses_list)))
# Execute the query with the statuses list
cursor.execute(query, [intake_current] + current_statuses_list)
students = cursor.fetchall()
# Close the database connection conn.close()
title_of_page = "New Intake Unavailable"
return render_template('index.html', students=students,statuses=statuses,title_of_page=title_of_page,projects=projects)
@app.route('/new_intake')
def index_new_intake():
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
cursor.execute('SELECT * FROM Projects')
projects = cursor.fetchall()
cursor.execute('SELECT name FROM Intakes where status = "new"')
intake_current = cursor.fetchall()[0][0]
# Retrieve student data from the database
cursor.execute('SELECT * FROM Statuses')
statuses = cursor.fetchall()
status_of_students_to_filter = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]
current_statuses_list = [row[1] for row in statuses if row[0] in status_of_students_to_filter]
# Retrieve student data from the database
# Prepare the SQL query with a placeholder for the statuses filter
query = '''
SELECT intern_id, full_name, email, pronunciation, project, intake, course, status, post_internship_summary_rating_internal, pronouns,pre_internship_summary_recommendation_internal, wehi_email, mobile
FROM Students
WHERE intake = ? AND status IN ({})
'''.format(','.join(['?'] * len(current_statuses_list)))
# Execute the query with the statuses list
cursor.execute(query, [intake_current] + current_statuses_list)
students = cursor.fetchall()
# Close the database connection conn.close()
title_of_page = "New Intake All"
return render_template('index.html', students=students,statuses=statuses,title_of_page=title_of_page,projects=projects)
@app.route('/outstanding')
def index_outstanding():
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
cursor.execute('SELECT * FROM Projects')
projects = cursor.fetchall()
cursor.execute('SELECT name FROM Intakes where status = "new"')
intake_current = cursor.fetchall()[0][0]
# Retrieve student data from the database
cursor.execute('SELECT * FROM Statuses')
statuses = cursor.fetchall()
status_of_students_to_filter = [1,2,3,4,5,6]
current_statuses_list = [row[1] for row in statuses if row[0] in status_of_students_to_filter]
# Retrieve student data from the database
# Prepare the SQL query with a placeholder for the statuses filter
query = '''
SELECT intern_id, full_name, email, pronunciation, project, intake, course, status, post_internship_summary_rating_internal, pronouns,pre_internship_summary_recommendation_internal, wehi_email, mobile
FROM Students
WHERE intake = ? AND status IN ({}) ORDER BY status ASC
'''.format(','.join(['?'] * len(current_statuses_list)))
# Execute the query with the statuses list
cursor.execute(query, [intake_current] + current_statuses_list)
students = cursor.fetchall()
# Close the database connection
conn.close()
title_of_page = "New Intake WIP"
return render_template('index.html', students=students,statuses=statuses,title_of_page=title_of_page,projects=projects)
@app.route('/current')
def index_current():
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
# Retrieve student data from the database
cursor.execute('SELECT * FROM Statuses')
statuses = cursor.fetchall()
cursor.execute('SELECT * FROM Projects')
projects = cursor.fetchall()
status_of_students_current = [10,11,12,13]
current_statuses_list = [row[1] for row in statuses if row[0] in status_of_students_current]
# Retrieve student data from the database
# Prepare the SQL query with a placeholder for the statuses filter
query = '''
SELECT intern_id, full_name, email, pronunciation, project, intake, course, status, post_internship_summary_rating_internal, pronouns,pre_internship_summary_recommendation_internal, wehi_email, mobile
FROM Students
WHERE status IN ({})
'''.format(','.join(['?'] * len(current_statuses_list)))
# Execute the query with the statuses list
cursor.execute(query, current_statuses_list)
students = cursor.fetchall()
# Close the database connection
conn.close()
title_of_page = "Currently Signed Students"
return render_template('index.html', students=students,statuses=statuses,title_of_page=title_of_page,projects=projects)
@app.route('/')
def index():
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
# Retrieve student data from the database
cursor.execute('SELECT intern_id, full_name, email, pronunciation, project, intake, course, status, post_internship_summary_rating_internal, pronouns,pre_internship_summary_recommendation_internal, wehi_email, mobile FROM Students')
students = cursor.fetchall()
cursor.execute('SELECT * FROM Projects')
projects = cursor.fetchall()
# Retrieve student data from the database
cursor.execute('SELECT * FROM Statuses')
statuses = cursor.fetchall()
# Close the database connection
conn.close()
title_of_page = "All Students"
return render_template('index.html', students=students,statuses=statuses,title_of_page=title_of_page,projects=projects)
# Route to serve the file from a different directory
@app.route('/view_docs/<path:filename>')
def view_docs(filename):
directory = 'student_intern_data/attachments/' # Replace with the actual directory path
filepath = directory + '/' + filename
return send_file(filepath, as_attachment=True)
@app.route('/view/<int:intern_id>')
def student(intern_id):
# Connect to the SQLite database
conn = sqlite3.connect('student_intern_data/student_intern_data.db')
cursor = conn.cursor()
# Retrieve student data from the database
cursor.execute('SELECT * FROM Students WHERE intern_id = ?', (intern_id,))
student = cursor.fetchone()
# Close the database connection
conn.close()
# Find matching PDF files
attachments_dir = 'student_intern_data/attachments'
matching_files = []
for filename in os.listdir(attachments_dir):
if filename.startswith(str(intern_id)) and filename.lower().endswith('.pdf'):
matching_files.append(filename)
# Pass matching_files to the template
return render_template('view.html', student=student, matching_files=matching_files)
@app.route('/change_post_internship_rating', methods=['POST'])
def change_post_internship_rating():
data = request.get_json()
student_ids = data.get('student_ids', [])
new_project = data.get('new_post_internship_rating', '')
# Convert student IDs to integers
student_ids = [int(id) for id in student_ids]
# Call the change_student_project function
change_post_internship_rating(student_ids, new_project)
# Redirect back to the index page
return redirect('/')
@app.route('/change_project', methods=['POST'])
def change_project():
data = request.get_json()
student_ids = data.get('student_ids', [])
new_project = data.get('new_project', '')