Commit 211e2dee authored by Julian Rother's avatar Julian Rother
Browse files

Cleaned up course caching (?) mess in ical exporter

parent 5c36d6f3
......@@ -7,25 +7,18 @@ def export_lectures(lectures, name):
cal = icalendar.Calendar()
cal.add('prodid', '-//Video AG//rwth.video//')
cal.add('version', '1.0')
courses = {};
for l in lectures:
event = icalendar.Event()
if not l['course_id'] in courses:
courses[l['course_id']] = query('SELECT * from courses WHERE id = ?',l['course_id'])[0]
c = courses[l['course_id']]
event.add('summary', c['short']+' : '+l['title'])
event.add('summary', l['course']['short']+' : '+l['title'])
event.add('description', l['internal'])
event.add('uid', 'lecture_'+str(l['id'])+'@rwth.video')
event.add('comment', l['comment'])
event.add('dtstamp', datetime.utcnow())
event.add('categories', c['short'])
event.add('categories', l['course']['short'])
event.add('dtstart', l['time'])
event.add('location', l['place'])
event.add('dtend', l['time'] + timedelta(minutes=l['duration']))
cal.add_component(event)
H = Headers()
H.add_header("Content-Disposition", "inline", filename=name)
return Response(cal.to_ical(), mimetype="text/calendar", headers=H)
......@@ -49,10 +42,13 @@ def calperm(func):
@app.route('/internal/ical/all')
@calperm
def ical_all():
return export_lectures(query('''SELECT lectures.* FROM lectures JOIN courses ON courses.id = lectures.course_id
return export_lectures(query('''SELECT lectures.*, "course" AS sep, courses.*
FROM lectures JOIN courses ON courses.id = lectures.course_id
WHERE NOT norecording AND NOT external ORDER BY time DESC LIMIT 1000'''),'videoag_all.ics')
@app.route('/internal/ical/course/<course>')
@calperm
def ical_course(course):
return export_lectures(query('SELECT lectures.* FROM lectures JOIN courses ON courses.id = lectures.course_id WHERE courses.handle = ? AND NOT norecording AND NOT external ORDER BY time DESC', course),'videoag_course_'+course+'.ics')
return export_lectures(query('''SELECT lectures.*, "course" AS sep, courses.*
FROM lectures JOIN courses ON courses.id = lectures.course_id
WHERE courses.handle = ? AND NOT norecording AND NOT external ORDER BY time DESC''', course),'videoag_course_'+course+'.ics')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment