Commit 7abb816f authored by Andreas Valder's avatar Andreas Valder
Browse files

added ical export (no gui integration), closes #42

parent c7af3eb5
......@@ -28,3 +28,4 @@ LDAP_PORT = 636
#ICAL_URL = ''
ERROR_PAGE = 'static/500.html'
RWTH_IP_RANGES = ['', '', '', '', '2a00:8a60::/32']
from server import *
import icalendar
from werkzeug.datastructures import Headers
from datetime import timedelta
def export_lectures(lectures, name):
cal = icalendar.Calendar()
cal.add('prodid', '-//Video AG//')
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('description', l['internal'])
event.add('comment', l['comment'])
event.add('categories', c['short'])
event.add('dtstart', l['time'])
event.add('location', l['place'])
event.add('dtend', l['time'] + timedelta(minutes=l['duration']))
H = Headers()
H.add_header("Content-Disposition", "inline", filename=name)
return Response(cal.to_ical(), mimetype="text/calendar", headers=H)
def calperm(func):
def decorator(*args, **kwargs):
permission = ismod()
if 'X-Real-IP' in request.headers:
ip = ip_address(request.headers['X-Real-IP'])
for net in config['FSMPI_IP_RANGES']:
if ip in ip_network(net):
permission = True
if permission:
return func(*args, **kwargs)
flash('Diese Funktion ist nur aus dem FSMPI-Netz(für SOGO-Import) oder eingeloggt verfügbar!')
return redirect(url_for('index'))
return decorator
def ical_semester(semester):
return export_lectures(query('SELECT lectures.* FROM lectures JOIN courses ON = lectures.course_id WHERE courses.semester = ? AND lectures.visible = 1', semester),'videoag_semester_'+semester+'.ics')
def ical_all():
return export_lectures(query('SELECT lectures.* FROM lectures lectures.visible = 1', semester),'videoag_all.ics')
def ical_course(course):
return export_lectures(query('SELECT lectures.* FROM lectures JOIN handles ON = lectures.course_id WHERE courses.handle = ? AND lectures.visible = 1', course),'videoag_course_'+course+'.ics')
......@@ -681,3 +681,4 @@ if 'JOBS_API_KEY' in config:
import jobs
import timetable
import chapters
import icalexport
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