-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudents.py
117 lines (92 loc) · 4.17 KB
/
students.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
from flask import jsonify, request, Blueprint
from flask_jwt_extended import get_jwt_identity, jwt_required
from src.schemas import coursesSchema, studentsSchema
from src.database import Student, User, RolesEnum
from src.utils import (
ExtractCourses, checkCseCoreCourses, checkCseLabRequirements, checkApprovedExperience,
checkFinalYearProject, checkIndeCourses, checkMathRequirements,
checkScienceRequirements, checkEnglishRequirements, checkElectives
)
students = Blueprint("students", __name__, url_prefix="/api/students/")
@students.get('/')
@jwt_required()
def getAllStudents():
id = get_jwt_identity()
user = User.query.filter_by(id=id).first()
if user.role != RolesEnum.STAFF:
return {'error' : 'unauthorized'}, 401
students = Student.query.order_by('AUBNet_id').all()
return jsonify(studentsSchema.dump(students)), 200
@students.get('/<AUBNet_id>/taken-courses')
@jwt_required()
def getTakenCourses(AUBNet_id):
id = get_jwt_identity()
user = User.query.filter_by(id=id).first()
if user.role != RolesEnum.STAFF:
return {'error' : 'unauthorized'}, 401
student = Student.query.filter_by(AUBNet_id=AUBNet_id).first()
if student is None:
return {'error' : AUBNet_id + ' doesn\'t exist'}, 404
return jsonify(coursesSchema.dump(student.taken_courses)), 200
@students.get('/me/taken-courses')
@jwt_required()
def getTakenCoursesByMe():
id = get_jwt_identity()
user = User.query.filter_by(id=id).first()
if user.role != RolesEnum.STUDENT:
return {'error' : 'unauthorized'}, 401
return jsonify({'courses': [course.name for course in user.student.taken_courses]}), 200
@students.post('/me/transcript-upload')
@jwt_required()
def uploadTranscript():
id = get_jwt_identity()
user = User.query.filter_by(id=id).first()
if user.role != RolesEnum.STUDENT:
return {'error' : 'unauthorized'}, 401
if 'file' not in request.files:
return {'error' : '\'file\' key missing'}, 400
if request.files['file'].name == '':
return {'error' : 'no transcript uploaded'}, 400
if not request.files['file'].filename.lower().endswith('.pdf'):
return {'error' : 'only pdf files are allowed'}, 400
return ExtractCourses(user.student, request.files['file'])
@students.get('/me/graduation-requirements-examination')
@jwt_required()
def checkGraduationRequirements():
id = get_jwt_identity()
user = User.query.filter_by(id=id).first()
if user.role != RolesEnum.STUDENT:
return {'error' : 'unauthorized'}, 401
student = user.student
response = {}
checkCseCoreCourses(student=student, response=response)
checkCseLabRequirements(student=student, response=response)
checkApprovedExperience(student=student, response=response)
checkFinalYearProject(student=student, response=response)
checkIndeCourses(student=student, response=response)
checkMathRequirements(student=student, response=response)
checkScienceRequirements(student=student, response=response)
checkEnglishRequirements(student=student, response=response)
checkElectives(student=student, response=response)
return response, 200
@students.get('/<AUBNet_id>/graduation-requirements-examination')
@jwt_required()
def checkGraduationRequirementsByStaff(AUBNet_id):
id = get_jwt_identity()
user = User.query.filter_by(id=id).first()
if user.role != RolesEnum.STAFF:
return {'error' : 'unauthorized'}, 401
student = Student.query.filter_by(AUBNet_id=AUBNet_id).first()
if student is None:
return {'error' : AUBNet_id + ' doesn\'t exist'}, 404
response = {}
checkCseCoreCourses(student=student, response=response)
checkCseLabRequirements(student=student, response=response)
checkApprovedExperience(student=student, response=response)
checkFinalYearProject(student=student, response=response)
checkIndeCourses(student=student, response=response)
checkMathRequirements(student=student, response=response)
checkScienceRequirements(student=student, response=response)
checkEnglishRequirements(student=student, response=response)
checkElectives(student=student, response=response)
return response, 200