-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcourses.py
More file actions
executable file
·104 lines (97 loc) · 4.14 KB
/
courses.py
File metadata and controls
executable file
·104 lines (97 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from app.allImports import *
#IMPORT LOGIC FILES
from app.logic import databaseInterface
from app.logic.getAuthUser import AuthorizedUser
from app.logic.getCourses import GetCourses
from app.logic.switch import switch
from app.logic.getAll import GetAll
from app.models import Semesters
@app.route("/courses", methods = ["GET"]) #SET A DEFAULT APP ROUTE
@app.route("/courses/<term>", methods = ["GET"]) #SET A DEFAULT APP ROUTE
def courses(term = 0):
if term == 0:
# Gets the highest term id (201711, 201712, etc)
currentSEID = databaseInterface.grab_current_semester()
else:
# Uses the term passed in via URL
currentSEID = term
current_term = Semesters.get(Semesters.SEID == currentSEID)
#instantiate GetAll object
getAll = GetAll()
#Grab user information
auth = AuthorizedUser()
user = auth.get_user()
user_level = auth.user_level()
#CREATE TWO DEFAULT DICTIONARIES
getCourses = GetCourses(auth)
# we need to get the dictionaries that populate the tables
two_dictionaries = getAll.create_dictionaries(currentSEID)
divisions_to_programs = two_dictionaries[0]
programs_to_courses = two_dictionaries[1]
# MY COURSES SELECT QUERY
my_courses = getCourses.check_for_my_courses(currentSEID)
if my_courses and my_courses.courseMaterials:
print(my_courses.courseMaterials)
my_courses.courseMaterials = list(my_courses.courseMaterials)
print(my_courses.courseMaterials)
# RENDER CORRECT PAGE BASED ON ACCESS LEVEL
for case in switch(user_level):
if case('admin'):
return render_template('courses/admin.html',
cfg = cfg,
my_courses = my_courses,
isAdmin = auth.isAdmin,
divisions_to_programs = divisions_to_programs,
programs_to_courses = programs_to_courses,
current_term = current_term
)
break;
if case('division'):
division_key = user.DID
print(division_key)
return render_template('courses/division.html',
cfg = cfg,
my_courses = my_courses,
division_key = division_key,
divisions_to_programs = divisions_to_programs,
programs_to_courses = programs_to_courses,
current_term = current_term
)
break;
if case('program'):
program_key = user.PID.name
return render_template('courses/program.html',
cfg = cfg,
my_courses = my_courses,
program_key = program_key,
programs_to_courses = programs_to_courses,
current_term = current_term
)
break;
if case('faculty'):
return render_template('courses/faculty.html',
cfg = cfg,
my_courses = my_courses,
current_term = current_term
)
break;
if case():
# TODO: return ERROR
abort(404)
render_template('error.html')
@app.route("/editCourseMaterials/<courseID>", methods = ["POST"])
def editCourseMaterials(courseID):
data = request.form.to_dict(flat=False)
print(courseID)
# courseMaterials = []
# if len(data) >= 0:
# for courseMaterialUsed in data:
# if courseMaterialUsed == "NoneRequired":
# break
# courseMaterials.append(courseMaterialUsed)
course = databaseInterface.get_course_info(courseID)
# print(str(courseMaterials))
course.courseMaterials = data
course.save()
print(course.courseMaterials)
return "", 200