[backup manager] [fix] hide google drive settings and show proper intro messages

This commit is contained in:
Anand Doshi 2013-05-02 14:14:38 +05:30
parent e97b07e43f
commit 76b3fcdb45
4 changed files with 95 additions and 72 deletions

View File

@ -92,8 +92,7 @@ def backup_to_gdrive():
mimetype = mimetypes.types_map.get("." + ext) or "application/octet-stream" mimetype = mimetypes.types_map.get("." + ext) or "application/octet-stream"
#Compare Local File with Server File #Compare Local File with Server File
param = {} children = drive_service.children().list(folderId=files_folder_id).execute()
children = drive_service.children().list(folderId=files_folder_id, **param).execute()
for child in children.get('items', []): for child in children.get('items', []):
file = drive_service.files().get(fileId=child['id']).execute() file = drive_service.files().get(fileId=child['id']).execute()
if filename == file['title'] and size == int(file['fileSize']): if filename == file['title'] and size == int(file['fileSize']):

View File

@ -1,13 +1,48 @@
cur_frm.cscript.refresh = function(doc) { $.extend(cur_frm.cscript, {
refresh: function() {
cur_frm.disable_save(); cur_frm.disable_save();
if(!(cint(cur_frm.doc.dropbox_access_allowed) ||
cint(cur_frm.doc.gdrive_access_allowed))) {
cur_frm.set_intro(wn._("You can start by selecting backup frequency and \
granting access for sync"));
} else {
var services = {
"dropbox": wn._("Dropbox"),
"gdrive": wn._("Google Drive")
}
var active_services = [];
$.each(services, function(service, label) {
var access_allowed = cint(cur_frm.doc[service + "_access_allowed"]);
var frequency = cur_frm.doc["upload_backups_to_" + service];
if(access_allowed && frequency && frequency !== "Never") {
active_services.push(label + " [" + frequency + "]");
}
});
if(active_services.length > 0) {
cur_frm.set_intro(wn._("Backups will be uploaded to") + ": " +
wn.utils.comma_and(active_services));
} else {
cur_frm.set_intro("");
}
} }
//dropbox },
cur_frm.cscript.allow_dropbox_access = function(doc) {
if (doc.send_notifications_to == '') { validate_send_notifications_to: function() {
msgprint("Please enter email address.") if(!cur_frm.doc.send_notifications_to) {
msgprint(wn._("Please specify") + ": " +
wn._(wn.meta.get_label(cur_frm.doctype, "send_notifications_to")));
return false;
} }
else {
return true;
},
allow_dropbox_access: function() {
if(cur_frm.cscript.validate_send_notifications_to()) {
wn.call({ wn.call({
method: "setup.doctype.backup_manager.backup_dropbox.get_dropbox_authorize_url", method: "setup.doctype.backup_manager.backup_dropbox.get_dropbox_authorize_url",
callback: function(r) { callback: function(r) {
@ -19,25 +54,12 @@ cur_frm.cscript.allow_dropbox_access = function(doc) {
}); });
} }
} }
}) });
}
} }
},
cur_frm.cscript.backup_right_now = function(doc) { allow_gdrive_access: function() {
msgprint("Backing up and uploading. This may take a few minutes.") if(cur_frm.cscript.validate_send_notifications_to()) {
wn.call({
method: "setup.doctype.backup_manager.backup_manager.take_backups_dropbox",
callback: function(r) {
msgprint("Backups taken. Please check your email for the response.")
}
})
}
//gdrive
cur_frm.cscript.allow_gdrive_access = function(doc) {
if (doc.send_notifications_to == '') {
msgprint("Please enter email address.")
}
else {
wn.call({ wn.call({
method: "setup.doctype.backup_manager.backup_googledrive.get_gdrive_authorize_url", method: "setup.doctype.backup_manager.backup_googledrive.get_gdrive_authorize_url",
callback: function(r) { callback: function(r) {
@ -45,23 +67,24 @@ cur_frm.cscript.allow_gdrive_access = function(doc) {
window.open(r.message.authorize_url); window.open(r.message.authorize_url);
} }
} }
}) });
}
} }
},
cur_frm.cscript.validate_gdrive = function(doc) { validate_gdrive: function() {
wn.call({ wn.call({
method: "setup.doctype.backup_manager.backup_googledrive.gdrive_callback", method: "setup.doctype.backup_manager.backup_googledrive.gdrive_callback",
args: { args: {
verification_code: doc.verification_code verification_code: cur_frm.doc.verification_code
}, },
}); });
} },
cur_frm.cscript.upload_backups_to_dropbox = function(doc) { upload_backups_to_dropbox: function() {
cur_frm.save() cur_frm.save();
} },
cur_frm.cscript.upload_backups_to_gdrive = function(doc) { upload_backups_to_gdrive: function() {
cur_frm.save() cur_frm.save();
} },
});

View File

@ -20,8 +20,8 @@ def take_backups_if(freq):
if webnotes.conn.get_value("Backup Manager", None, "upload_backups_to_dropbox")==freq: if webnotes.conn.get_value("Backup Manager", None, "upload_backups_to_dropbox")==freq:
take_backups_dropbox() take_backups_dropbox()
if webnotes.conn.get_value("Backup Manager", None, "upload_backups_to_gdrive")==freq: # if webnotes.conn.get_value("Backup Manager", None, "upload_backups_to_gdrive")==freq:
take_backups_gdrive() # take_backups_gdrive()
@webnotes.whitelist() @webnotes.whitelist()
def take_backups_dropbox(): def take_backups_dropbox():
@ -35,7 +35,7 @@ def take_backups_dropbox():
except Exception: except Exception:
file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)] file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)]
error_message = ("\n".join(file_and_error) + "\n" + webnotes.getTraceback()) error_message = ("\n".join(file_and_error) + "\n" + webnotes.getTraceback())
print error_message webnotes.errprint(error_message)
send_email(False, "Dropbox", error_message) send_email(False, "Dropbox", error_message)
#backup to gdrive #backup to gdrive
@ -51,7 +51,7 @@ def take_backups_gdrive():
except Exception: except Exception:
file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)] file_and_error = [" - ".join(f) for f in zip(did_not_upload, error_log)]
error_message = ("\n".join(file_and_error) + "\n" + webnotes.getTraceback()) error_message = ("\n".join(file_and_error) + "\n" + webnotes.getTraceback())
print error_message webnotes.errprint(error_message)
send_email(False, "Google Drive", error_message) send_email(False, "Google Drive", error_message)
def send_email(success, service_name, error_status=None): def send_email(success, service_name, error_status=None):

View File

@ -1,8 +1,8 @@
[ [
{ {
"creation": "2013-03-15 11:06:59", "creation": "2013-04-30 12:58:38",
"docstatus": 0, "docstatus": 0,
"modified": "2013-03-15 17:27:33", "modified": "2013-05-02 11:42:08",
"modified_by": "Administrator", "modified_by": "Administrator",
"owner": "Administrator" "owner": "Administrator"
}, },
@ -109,6 +109,7 @@
"doctype": "DocField", "doctype": "DocField",
"fieldname": "sync_with_gdrive", "fieldname": "sync_with_gdrive",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 1,
"label": "Sync with Google Drive" "label": "Sync with Google Drive"
}, },
{ {