cutprogress.py 1.92 KB
Newer Older
1
2
3
from server import *
from datetime import time

4
@register_navbar('Schnittfortschritt User', icon='spinner', iconlib='fa', userendpoint=True, endpoint='cutprogress_user')
5
@register_navbar('Schnittfortschritt', icon='spinner', iconlib='fa')
Andreas Valder's avatar
Andreas Valder committed
6
@app.route('/internal/cutprogress', endpoint="cutprogress")
7
@app.route('/internal/user/<int:user>/cutprogress', endpoint='cutprogress_user')
8
9
@mod_required
def cutprogress(user=None):
Andreas Valder's avatar
Andreas Valder committed
10
	allsemester = query('SELECT DISTINCT semester from courses ORDER BY semester DESC')
11
12
13
14
15
	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:
Andreas Valder's avatar
Andreas Valder committed
16
17
18
19
		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'])
20
		for lecture in course['lectures']:
Andreas Valder's avatar
Andreas Valder committed
21
22
23
24
			lecture['videos'] = query('''
				SELECT videos.path, formats.description as formatdesc, videos.visible FROM videos
				JOIN formats ON (videos.video_format = formats.id)
				WHERE videos.lecture_id = ? AND NOT videos.deleted''', lecture['id'])
25
26
27
28
29
30
31
32
		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)
Andreas Valder's avatar
Andreas Valder committed
33
34
35
36
37
38
39
			maxlecturecount = max(len(course['lectures']), maxlecturecount)
	return render_template('cutprogress.html',
			allsemester=allsemester,
			semester=semester,
			courses=courses,
			maxlecturecount=maxlecturecount,
			user=query('SELECT * FROM users WHERE id = ?', user)[0] if user else None)