[FIX] backup restoration, works almost 60% of the time

bzr revid: xmo@openerp.com-20110801144728-zh1d6nqpf19i6x7p
This commit is contained in:
Xavier Morel 2011-08-01 16:47:28 +02:00
parent 0fd884d234
commit 68cb923ec6
4 changed files with 24 additions and 27 deletions

View File

@ -6,6 +6,7 @@
'js' : [
"static/lib/datejs/date-en-US.js",
"static/lib/jquery/jquery-1.5.2.js",
"static/lib/jquery.form/jquery.form.js",
"static/lib/jquery.validate/jquery.validate.js",
"static/lib/jquery.ba-bbq/jquery.ba-bbq.js",
"static/lib/jquery.contextmenu/jquery.contextmenu.r2.packed.js",

View File

@ -206,20 +206,23 @@ class Database(openerpweb.Controller):
return {'error': e.faultCode, 'title': 'Backup Database'}
return {'error': 'Could not drop database !', 'title': 'Backup Database'}
@openerpweb.jsonrequest
def restore_db(self, req, fields):
password, db, filename = operator.itemgetter(
'restore_pwd', 'new_db', 'value')(
dict(map(operator.itemgetter('name', 'value'), fields)))
@openerpweb.httprequest
def restore_db(self, req, db_file, restore_pwd, new_db):
response = None
try:
data = base64.encodestring(filename.file.read())
return req.session.proxy("db").restore(password, db, data)
data = base64.encodestring(db_file.file.read())
response = simplejson.dumps(
req.session.proxy("db").restore(restore_pwd, new_db, data))
except xmlrpclib.Fault, e:
if e.faultCode and e.faultCode.split(':')[0] == 'AccessDenied':
return {'error': e.faultCode, 'title': 'Restore Database'}
return {'error': 'Could not restore database !', 'title': 'Restore Database'}
response = simplejson.dumps({'error': e.faultCode, 'title': 'Restore Database'})
if not response:
response = simplejson.dumps({'error': 'Could not restore database !', 'title': 'Restore Database'})
cherrypy.response.headers['Content-Type'] = 'application/json'
cherrypy.response.headers['Content-Length'] = len(response)
return response
@openerpweb.jsonrequest
def change_password_db(self, req, fields):
old_password, new_password = operator.itemgetter(

View File

@ -842,21 +842,14 @@ openerp.base.Database = openerp.base.Controller.extend({
self.$option_id.find("form[name=restore_db_form]").validate({
submitHandler: function (form) {
var fields = $(form).serializeArray();
self.rpc("/base/database/restore_db", {'fields': fields}, function(result) {
if (!result.error) {
self.notification.notify("Restore Database", "You restored your database");
} else {
$('<div>').dialog({
modal: true,
title: result.title,
buttons: {
Ok: function() {
$(this).dialog("close");
}
}
}).html(result.error);
$(form).ajaxSubmit({
url: '/base/database/restore_db',
type: 'POST',
dataType: 'json',
resetForm: true,
success: function () {
// TODO: ui manipulations
// note: response objects don't work
}
});
}

View File

@ -192,7 +192,7 @@
<table align="center" class="db_option_table">
<tr>
<td><label for="restore_db">File:</label></td>
<td><input type="file" name="restore_db" class="required"
<td><input type="file" name="db_file" class="required"
autofocus="autofocus"/></td>
</tr>
<tr>