elif flag == 'backup':
db = kw.get('db')
password = kw.get('password')
-
- res = req.session.proxy("db").dump(password, db)
- if res:
- cherrypy.response.headers['Content-Type'] = "application/data"
- cherrypy.response.headers['Content-Disposition'] = 'filename="' + db + '.dump"'
- return base64.decodestring(res)
+ try:
+ res = req.session.proxy("db").dump(password, db)
+ if res:
+ cherrypy.response.headers['Content-Type'] = "application/data"
+ cherrypy.response.headers['Content-Disposition'] = 'filename="' + db + '.dump"'
+ return base64.decodestring(res)
+ except Exception:
+ return {'error': 'Could not create backup !'}
elif flag == 'restore':
filename = kw.get('filename')
db = kw.get('db')
password = kw.get('password')
- data = base64.encodestring(filename.file.read())
- return req.session.proxy("db").restore(password, db, data)
+ try:
+ if filename:
+ data = base64.encodestring(filename.file.read())
+ return req.session.proxy("db").restore(password, db, data)
+ except Exception:
+ return {'error': 'Could not restore database !'}
elif flag == 'change_password':
old_password = kw.get('old_password')
self.rpc("/base/session/db_operation", {'flag': 'backup', 'db': db, 'password': password},
function(result) {
if (result && !result.error) {
- self.notification.notify("Backup has been created for the database: '" + db + "'");
+ self.notification.notify("Backup Database", "Backup has been created for the database: '" + db + "'");
+ } else if (result.error) {
+ self.notification.notify("Backup Database", result.error);
}
});
});
self.rpc("/base/session/db_operation", {'flag': 'restore', 'db': db, 'password': password, 'new_db': new_db},
function(result) {
if (result && !result.error) {
- self.notification.notify("You restored your database as: '" + new_db + "'");
+ self.notification.notify("Restore Database", "You restored your database as: '" + new_db + "'");
+ } else if (result.error) {
+ self.notification.notify("Restore Database", result.error);
}
});
});
self.rpc("/base/session/db_operation", {'flag': 'change_password', 'old_password': old_pwd, 'new_password': new_pwd, 'confirm_password': confirm_pwd},
function(result) {
if (result && !result.error) {
- self.notification.notify("Password has been changed successfully");
+ self.notification.notify("Changed Password", "Password has been changed successfully");
}
});
});