-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
193 lines (173 loc) · 9.45 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
import csv
import os
from flask import Flask, render_template, request
app = Flask(__name__, template_folder='.', static_folder='assets', static_url_path='/assets')
def read_csv(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
reader = csv.DictReader(file)
return list(reader)
def nav_for_class(class_name):
if class_name == 's18-ecs188':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Quizzes and reports'},
{'page': 'final_paper.html', 'label': 'Final paper'},
{'page': 'presentations.html', 'label': 'Presentations'}]
elif class_name == 's21-ecs150':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Midterms'},
{'page': 'project.html', 'label': 'Project'}]
elif class_name == 's24-ecs150':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Midterms'},
{'page': 'project.html', 'label': 'Project'}]
elif class_name == 'f24-ecs150':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Midterms'},
{'page': 'project.html', 'label': 'Project'}]
elif class_name == 'w25-ecs150':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Midterms'},
{'page': 'project.html', 'label': 'Project'}]
elif class_name == 'w18-ecs188':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Quizzes and reports'},
{'page': 'final_paper.html', 'label': 'Final paper'},
{'page': 'presentations.html', 'label': 'Presentations'}]
elif class_name == 'f18-ecs189e':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Quizzes'},
{'page': 'project.html', 'label': 'Project'},
{'page': 'homework.html', 'label': 'Homework'}]
elif class_name == 'f19-ecs189e':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Quizzes'},
{'page': 'project.html', 'label': 'Project'},
{'page': 'homework.html', 'label': 'Homework'}]
elif class_name == 'w21-ecs189e':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Quizzes'},
{'page': 'project.html', 'label': 'Project'},
{'page': 'homework.html', 'label': 'Homework'}]
elif class_name == 'w24-ecs189e':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Quizzes'},
{'page': 'project.html', 'label': 'Project'},
{'page': 'homework.html', 'label': 'Homework'}]
elif class_name == 'w18-ecs251':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Quizzes'},
{'page': 'research_project.html', 'label': 'Research project'},
{'page': 'presentations.html', 'label': 'Presentations'}]
elif class_name == 'w19-ecs251':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Quizzes'},
{'page': 'research_project.html', 'label': 'Research project'},
{'page': 'homework.html', 'label': 'Homework'}]
elif class_name == 'w20-ecs251':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Quizzes'},
{'page': 'research_project.html', 'label': 'Research project'},
{'page': 'presentations.html', 'label': 'Lead a lecture'}]
elif class_name == 's19-ecs153':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Quizzes'},
{'page': 'research_project.html', 'label': 'Project'},
{'page': 'homework.html', 'label': 'Homework'}]
elif class_name == 's20-ecs153':
return [{'page': 'index.html', 'label': 'Home'},
{'page': 'grading.html', 'label': 'Grading'},
{'page': 'lectures.html', 'label': 'Lectures'},
{'page': 'quizzes.html', 'label': 'Quizzes'},
{'page': 'research_project.html', 'label': 'Project'},
{'page': 'remote.html', 'label': 'Remote project'},
{'page': 'homework.html', 'label': 'Homework'}]
@app.route('/classes/<class_name>/<page>')
def render_class_page(class_name, page):
if not page or len(page) == 0:
page = 'index.html'
reading_list = read_csv(f'classes/{class_name}/reading_list.csv')
nav = nav_for_class(class_name)
return render_template(f'classes/{class_name}/{page}',
nav_title=class_name.upper(),
page=page,
nav=nav,
reading_list=reading_list)
@app.route('/', defaults={'path': 'main.html'})
@app.route('/<path:path>')
def home(path):
page = path
publication_list = read_csv('home/publications.csv')
def publication_to_listing(publication):
if publication['paper'].startswith('https://'):
url = publication['paper']
else:
url = '/assets/dl/' + publication['paper']
anchor = f'<a href="{url}">'
end_anchor = '</a>'
return publication['publication'].replace('{start_title}', anchor).replace('{end_title}', end_anchor)
publications = [publication_to_listing(x) for x in publication_list]
classes = [
{'title': 'ECS 150', 'quarter': 'Winter 25', 'page': '/classes/w25-ecs150/index.html'}
]
past_classes = [
{'title': 'ECS 150', 'quarter': 'Fall 24', 'page': '/classes/f24-ecs150/index.html'},
{'title': 'ECS 150', 'quarter': 'Spring 24', 'page': '/classes/s24-ecs150/index.html'},
{'title': 'ECS 189e', 'quarter': 'Winter 24', 'page': '/classes/w24-ecs189e/index.html'},
{'title': 'ECS 150', 'quarter': 'Spring 21', 'page': '/classes/s21-ecs150/index.html'},
{'title': 'ECS 189e', 'quarter': 'Winter 21', 'page': '/classes/w21-ecs189e/index.html'},
{'title': 'ECS 153', 'quarter': 'Spring 20', 'page': '/classes/s20-ecs153/index.html'},
{'title': 'ECS 251', 'quarter': 'Winter 20', 'page': '/classes/w20-ecs251/index.html'},
{'title': 'ECS 189e', 'quarter': 'Fall 19', 'page': '/classes/f19-ecs189e/index.html'},
{'title': 'ECS 153', 'quarter': 'Spring 19', 'page': '/classes/s19-ecs153/index.html'},
{'title': 'ECS 251', 'quarter': 'Winter 19', 'page': '/classes/w19-ecs251/index.html'},
{'title': 'ECS 189e', 'quarter': 'Fall 18', 'page': '/classes/f18-ecs189e/index.html'},
{'title': 'ECS 188', 'quarter': 'Spring 18', 'page': '/classes/s18-ecs188/index.html'},
{'title': 'ECS 251', 'quarter': 'Winter 18', 'page': '/classes/w18-ecs251/index.html'},
{'title': 'ECS 188', 'quarter': 'Winter 18', 'page': '/classes/w18-ecs188/index.html'}
]
nav = [
{'page': '/', 'label': 'Home'},
{'page': 'research.html', 'label': 'Research'},
{'page': 'publications.html', 'label': 'Publications'},
{'page': 'teaching.html', 'label': 'Teaching'}
]
return render_template('home/' + page,
classes=classes,
past_classes=past_classes,
publications=publications,
nav_title='Sam King',
nav=nav,
page=page)
@app.route('/robots.txt')
def robots_txt():
return "User-agent: *\nDisallow:"
if __name__ == "__main__":
app.run(debug=True)