Commit 7cd46306 authored by Julian Rother's avatar Julian Rother
Browse files

Refactured ical export to use new responsible schema

parent ffad2ba1
......@@ -3,17 +3,21 @@ import icalendar
from werkzeug.datastructures import Headers
from datetime import timedelta, datetime
def export_lectures(lectures, name):
def export_lectures(lectures, responsible, name):
cal = icalendar.Calendar()
cal.add('prodid', '-//Video AG//rwth.video//')
cal.add('version', '1.0')
for l in lectures:
resp = []
for r in responsible:
if r['course_id'] == l['course_id']:
resp.append(r['realname'])
event = icalendar.Event()
event.add('summary', l['course']['short']+': '+l['title'])
event.add('description', '\n\n'.join([s for s in [
l['comment'],
l['internal'],
'Zuständig: '+l['course']['responsible'] if l['course']['responsible'] else ''
'Zuständig: '+', '.join(resp) if resp else ''
] if s]))
event.add('uid', '%i@rwth.video'%l['id'])
event.add('dtstamp', datetime.utcnow())
......@@ -45,12 +49,17 @@ def calperm(func):
return Response("Login required", 401, {'WWW-Authenticate': 'Basic realm="FS-Login required"'})
return decorator
def get_responsible():
return query('''SELECT users.*, responsible.course_id FROM responsible
JOIN users ON users.id = responsible.user_id''')
@app.route('/internal/ical/all')
@calperm
def ical_all():
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')
WHERE NOT norecording AND NOT external ORDER BY time DESC LIMIT 1000'''),
get_responsible(), 'videoag_all.ics')
@app.route('/internal/ical/user/<int:user>')
@calperm
......@@ -61,7 +70,8 @@ def ical_user(user):
JOIN courses ON courses.id = lectures.course_id
JOIN responsible ON responsible.course_id = courses.id
WHERE NOT norecording AND NOT external AND responsible.user_id = ?
ORDER BY time DESC LIMIT 1000''', user),'videoag_%s.ics'%username)
ORDER BY time DESC LIMIT 1000''', user), get_responsible(),
'videoag_%s.ics'%username)
@app.route('/internal/ical/notuser/<int:user>')
@calperm
......@@ -72,11 +82,13 @@ def ical_notuser(user):
JOIN courses ON courses.id = lectures.course_id
LEFT JOIN responsible ON (responsible.course_id = courses.id AND responsible.user_id = ?)
WHERE NOT norecording AND NOT external AND responsible.user_id IS NULL
ORDER BY time DESC LIMIT 1000''', user),'videoag_not_%s.ics'%username)
ORDER BY time DESC LIMIT 1000''', user), get_responsible(),
'videoag_not_%s.ics'%username)
@app.route('/internal/ical/course/<course>')
@calperm
def ical_course(course):
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')
WHERE courses.handle = ? AND NOT norecording AND NOT external ORDER BY time DESC''', course),
get_responsible(), 'videoag_%s.ics'%course)
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