diff --git a/importer.py b/importer.py index 36866ce94dd8a69cd0a709c70abc2293dee9390f..f98381fde70aceb70f33a25956cfb79ce3231158 100755 --- a/importer.py +++ b/importer.py @@ -81,7 +81,6 @@ def import_from(source=None, id=None): 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['title'] = i['type'] - 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 events.append(e) # it is parsed. @@ -91,24 +90,19 @@ def import_from(source=None, id=None): flash('python-lxml not found, campus import will not work.') uniqueevents = [] - for i in events: - seen = False + for i in events + lectures: + unique = False + exists = False for j in uniqueevents: - seen = (i['place'] == j['place']) and (i['time'] == j['time']) and (i['duration'] == j['duration']) - if seen: + unique = (i['place'] == j['place']) and (i['time'] == j['time']) and (i['duration'] == j['duration']) + if unique: break - if (not seen) and (not i['exists']): - i['type'] = 'import' - uniqueevents.append(i) - - for i in lectures: - i['hascampusmapping'] = False - for j in events: - i['hascampusmapping'] = (i['place'] == j['place']) and (i['time'] == j['time']) and (i['duration'] == j['duration']) - if i['hascampusmapping']: + for j in lectures: + exists = (i['place'] == j['place']) and (i['time'] == j['time']) and (i['duration'] == j['duration']) + if exists: break - if not i['hascampusmapping']: - i['type'] = 'lecture' + if (not unique) and (not exists): + i['type'] = 'import' uniqueevents.append(i) return render_template('import_campus.html', course=courses, import_campus=import_campus, events=uniqueevents) diff --git a/server.py b/server.py index 5a579c03e46a2b3ae680ed5c40027d4dbcdebc56..e0a7e2704565b133bcf504f74cdbab008ce656f1 100755 --- a/server.py +++ b/server.py @@ -258,6 +258,7 @@ def edit(prefix="", ignore=[]): if key in ignore: continue key = prefix+key + print (key,val) table, id, column = key.split('.', 2) assert table in tabs assert column in tabs[table][2] diff --git a/static/moderator.js b/static/moderator.js index 11ec07fe40729edea0ecd45b6f30244f2a9673f9..d71a1f7dfb8817cc4c9137f9f00cf8603c5064ee 100644 --- a/static/moderator.js +++ b/static/moderator.js @@ -66,6 +66,13 @@ var moderatorinterface = { if (confirm('Realy delete this?')) { moderatorinterface.set($(src).data('path'),1,true); } + }, + gethttp: function (url){ + $.ajax({ + method: "GET", + url: url, + dataType: "text", + }) } }; diff --git a/templates/import_campus.html b/templates/import_campus.html index cb727be101ee9f79fba8c598b494fdb3741032c0..3240907f378a18c060308c0c9222f19ccd715e67 100644 --- a/templates/import_campus.html +++ b/templates/import_campus.html @@ -57,7 +57,7 @@ </div> <div class="panel panel-default"> <div class="panel-heading"> - <h1 class="panel-title">Fehlende Termine:</h1> + <h1 class="panel-title">Fehlende Termine: <button class="pull-right btn btn-default" onclick="$('.newlecture').click()">alle anlagen</button></h1> </div> <ul class="list-group-item"> {% for i in events|sort(attribute='time') %} @@ -86,11 +86,11 @@ </span> <span class="col-xs-1"> <span class="pull-right"> - {% if (i.type == 'lecture') and (not i.hascampusmapping) %} + {% if (i.type == 'lecture') %} {{ valuedeletebtn(['lectures',i.id,'deleted']) }} {% endif%} - {% if (i.type == 'import') and (not i.exists) %} - anlegen + {% if (i.type == 'import') %} + <button class="btn btn-default newlecture" onclick="moderatorinterface.gethttp('{{ url_for('new_lecture', courseid=course.id, time=i.time, title=i.title, place=i.place) }}')">anlegen</a> {% endif%} </span> </span>