cutprogress.py 1.62 KB
Newer Older
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
from server import *
from datetime import time

@app.route('/internal/cutprogress')
@app.route('/internal/users/<int:user>/cutprogress')
@register_navbar('Schnittfortschritt', icon='spinner', iconlib='fa')
@mod_required
def cutprogress(user=None):
	allsemester = query('SELECT DISTINCT semester from courses ORDER BY semester DESC');
	semester = request.values.get('semester', allsemester[0]['semester'])
	coursesraw = query('SELECT courses.id, courses.handle, courses.short FROM courses WHERE semester = ?', semester)
	courses = []
	maxlecturecount = 0
	for course in coursesraw:
		course['lectures'] = query('SELECT lectures.title, lectures.time, lectures.id FROM lectures WHERE lectures.course_id= ? AND NOT lectures.deleted AND NOT lectures.norecording ORDER BY lectures.time', course['id'])
		maxlecturecount = max(len(course['lectures']),maxlecturecount)
		for lecture in course['lectures']:
			lecture['videos'] = query('SELECT videos.path, formats.description as formatdesc FROM videos JOIN formats ON (videos.video_format = formats.id) WHERE videos.lecture_id = ? AND NOT videos.deleted', lecture['id'])
		course['responsible'] = query('''SELECT users.*
				FROM responsible
				JOIN users ON (responsible.user_id = users.id AND responsible.course_id = ?)
				ORDER BY users.realname ASC''', course['id'])
		if len(course['responsible']) == 0:
			course['responsible'] = [{"realname": "Niemand", "id": -1}]
		if not user or user in [ r['id'] for r in course['responsible'] ]:
			courses.append(course)
	return render_template('cutprogress.html', allsemester=allsemester, semester=semester, courses=courses, maxlecturecount=maxlecturecount, user=user)