diff --git a/importer.py b/importer.py index feaae51deb5cca11918f8bfb2e56cbb7d64127b1..88bd07000bb0f5f5816ccb7a860fb22068f3fb3f 100755 --- a/importer.py +++ b/importer.py @@ -1,12 +1,9 @@ from server import * -@app.route('/import/<source>/<int:id>', methods=['GET', 'POST']) +@app.route('/import/<int:id>', methods=['GET', 'POST']) @mod_required def import_from(source=None, id=None): - if source != "campus": - return "Unknown source", 404 - courses = query('SELECT * FROM courses WHERE id = ?', id)[0] lectures = query('SELECT * FROM lectures WHERE course_id = ?', courses['id']) @@ -83,7 +80,7 @@ def import_from(source=None, id=None): e['time'] = datetime.strptime("%s %s"%(k,j['start']) ,fmt) e['duration'] = int((datetime.strptime("%s %s"%(k,j['end']) ,fmt) - e['time']).seconds/60) e['place'] = query("SELECT name FROM places WHERE (campus_name = ?) OR ((NOT campus_name) AND name = ?)",j['place'],j['place'])[0]['name']; - e['exists'] = len(query("SELECT id from lectures WHERE (time = ?) and (duration = ?) and (place = ?) and (course_id = ?)",e['time'],e['duration'],e['place'],id)) > 0 + e['exists'] = query("SELECT count(id) as c from lectures WHERE (time = ?) and (duration = ?) and (place = ?) and (course_id = ?)",e['time'],e['duration'],e['place'],id)[0]['c'] > 0 events.append(e) # it is pared. @@ -92,12 +89,25 @@ def import_from(source=None, id=None): except ImportError: flash('python-lxml not found, campus import will not work.') - uniqevents = [] + uniqueevents = [] for i in events: seen = False - for j in events: + for j in uniqueevents: seen = (i['place'] == j['place']) and (i['time'] == j['time']) and (i['duration'] == j['duration']) - if not seen: - uniqevents.append(i) + if seen: + break + if (not seen) and (not i['exists']): + i['type'] = 'import' + uniqueevents.append(i) + + for i in lectures: + i['hascampusmapping'] = False + for j in uniqueevents: + i['hascampusmapping'] = (i['place'] == j['place']) and (i['time'] == j['time']) and (i['duration'] == j['duration']) + if i['hascampusmapping']: + break + if not i['hascampusmapping']: + i['type'] = 'lecture' + uniqueevents.append(i) - return render_template('import_campus.html', course=courses, lectures=lectures, import_campus=import_campus, events=uniqevents) + return render_template('import_campus.html', course=courses, import_campus=import_campus, events=uniqueevents) diff --git a/templates/course_id.html b/templates/course_id.html index c023a5f9b22b73347e48939ebd958254883b68a7..4e2433ce007b6c0a05389aec3ca36766e6287701 100644 --- a/templates/course_id.html +++ b/templates/course_id.html @@ -31,7 +31,7 @@ </div> <div class="panel panel-default"> <div class="panel-heading"> - <h1 class="panel-title">Videos{% if ismod() %} <a class="btn btn-default" style="margin-right: 5px;" href="todo">Neuer Termin</a><a class="btn btn-default" style="margin-right: 5px;" href="{{url_for('import_from', source="campus", id=course['id'])}}">Campus Import</a>{% endif %}</h1> + <h1 class="panel-title">Videos{% if ismod() %} <a class="btn btn-default" style="margin-right: 5px;" href="todo">Neuer Termin</a><a class="btn btn-default" style="margin-right: 5px;" href="{{url_for('import_from', id=course['id'])}}">Campus Import</a>{% endif %}</h1> </div> <ul class="list-group lectureslist"> {% for l in lectures %} diff --git a/templates/import_campus.html b/templates/import_campus.html index 5a5b0366c2e2eb767e18ea367dd87cd7e40120eb..c37be8d8c3ad394e607f6ef90bb7069673e8522d 100644 --- a/templates/import_campus.html +++ b/templates/import_campus.html @@ -1,4 +1,4 @@ -{% from 'macros.html' import preview %} +{% from 'macros.html' import valuedeletebtn %} {% extends "base.html" %} {% block content %} <div class="panel-group"> @@ -60,9 +60,37 @@ <h1 class="panel-title">Fehlende Termine:</h1> </div> <ul class="list-group-item"> - {% for i in events if not i.exists %} - <li class="list-group-item"> - {{i|pprint}} + {% for i in events|sort(attribute='time') %} + <li class="list-group-item row"> + <span class="col-xs-3"> + Time: {{i.time}} + </span> + <span class="col-xs-2"> + Duration: {{i.duration}} + </span> + <span class="col-xs-3"> + Place: {{i.place}} + </span> + <span class="col-xs-3"> + {% if (i.type == 'lecture') %} + <p> + {{i.comment}} + </p> + <p> + {{i.internal}} + </p> + {% endif%} + </span> + <span class="col-xs-1"> + <span class="pull-right"> + {% if (i.type == 'lecture') and (not i.hascampusmapping) %} + {{ valuedeletebtn(['lectures',i.id,'deleted']) }} + {% endif%} + {% if (i.type == 'import') and (not i.exists) %} + anlegen + {% endif%} + </span> + </span> </li> {% endfor %} </ul>