deletion of backups

This commit is contained in:
Ilya Zverev 2015-03-27 11:16:00 +03:00
parent 3a5754868e
commit ade400c610
3 changed files with 32 additions and 2 deletions

View file

@ -341,8 +341,23 @@ def backup_list():
result = []
for res in cur:
result.append({ 'timestamp': res[0], 'text': res[0], 'count': res[1] })
# todo: count number of different objects for the last one
return jsonify(backups=result)
@app.route('/backdelete')
def backup_delete():
if config.READONLY:
abort(405)
ts = request.args.get('timestamp')
cur = g.conn.cursor()
cur.execute('SELECT count(1) from {} where backup = %s;'.format(config.BACKUP), (ts,))
(count,) = cur.fetchone()
if count <= 0:
return jsonify(status='no such timestamp')
cur.execute('DELETE FROM {} WHERE backup = %s;'.format(config.BACKUP), (ts,))
g.conn.commit()
return jsonify(status='ok')
@app.route('/josm')
def make_osm():
xmin = request.args.get('xmin')

View file

@ -1,5 +1,5 @@
# passed to flask.Debug
DEBUG = True
DEBUG = False
# if the main table is read-only
READONLY = False
# main table name

View file

@ -650,8 +650,16 @@ function updateBackupList(data) {
var a = document.createElement('a');
a.href = '#';
a.onclick = (function(id, name) { return function() { bBackupRestore(id); return false } })(b['timestamp']);
list.append(a, $('<br>'));
$(a).text(b['text'] + ' (' + b['count'] + ')');
if( i > 0 ) {
var d = document.createElement('a');
d.href = '#';
d.onclick = (function(id, name) { return function() { bBackupDelete(id); return false } })(b['timestamp']);
$(d).text('[x]');
list.append(a, document.createTextNode(' '), d, $('<br>'));
} else {
list.append(a, $('<br>'));
}
}
}
@ -671,3 +679,10 @@ function bBackupRestore(timestamp) {
$('#backup_list').text('');
$('#backup_restoring').css('display', 'block');
}
function bBackupDelete(timestamp) {
$.ajax(server + '/backdelete', {
data: { 'timestamp': timestamp }
});
bBackupCancel();
}