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

Andreas Valder's avatar
Andreas Valder committed
4
5
6
7
8
9
@register_navbar('Schnittfortschritt User', icon='spinner', iconlib='fa', userendpoint=True)
@app.route('/internal/user/<int:user>/cutprogress')
@mod_required
def cutprogress_user(user):
	return cutprogress(user)

10
@register_navbar('Schnittfortschritt', icon='spinner', iconlib='fa')
Andreas Valder's avatar
Andreas Valder committed
11
@app.route('/internal/cutprogress', endpoint="cutprogress")
12
13
14
15
16
17
18
19
20
21
@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'])
		for lecture in course['lectures']:
22
			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'])
23
24
25
26
27
28
29
30
		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)
31
			maxlecturecount = max(len(course['lectures']),maxlecturecount)
Andreas Valder's avatar
Andreas Valder committed
32
	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)