fix: Refactor Upload Attendance (#17241)

New API frappe.ui.FileUploader
https://github.com/frappe/frappe/pull/7253
This commit is contained in:
Faris Ansari 2019-04-17 09:45:46 +05:30 committed by Suraj Shetty
parent 1ddc123dbf
commit 1cf9fa9662
2 changed files with 11 additions and 22 deletions

View File

@ -29,19 +29,12 @@ erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({
});
},
show_upload: function() {
var me = this;
show_upload() {
var $wrapper = $(cur_frm.fields_dict.upload_html.wrapper).empty();
// upload
frappe.upload.make({
parent: $wrapper,
args: {
method: 'erpnext.hr.doctype.upload_attendance.upload_attendance.upload'
},
no_socketio: true,
sample_url: "e.g. http://example.com/somefile.csv",
callback: function(attachment, r) {
new frappe.ui.FileUploader({
wrapper: $wrapper,
method: 'erpnext.hr.doctype.upload_attendance.upload_attendance.upload',
on_success(file_doc, r) {
var $log_wrapper = $(cur_frm.fields_dict.import_log.wrapper).empty();
if(!r.messages) r.messages = [];
@ -59,10 +52,10 @@ erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({
});
r.messages = ["<h4 style='color:red'>"+__("Import Failed!")+"</h4>"]
.concat(r.messages)
.concat(r.messages);
} else {
r.messages = ["<h4 style='color:green'>"+__("Import Successful!")+"</h4>"].
concat(r.message.messages)
r.messages = ["<h4 style='color:green'>"+__("Import Successful!")+"</h4>"]
.concat(r.message.messages);
}
$.each(r.messages, function(i, v) {
@ -79,11 +72,7 @@ erpnext.hr.AttendanceControlPanel = frappe.ui.form.Controller.extend({
});
}
});
// rename button
$wrapper.find('form input[type="submit"]')
.attr('value', 'Upload and Import')
}
},
})
cur_frm.cscript = new erpnext.hr.AttendanceControlPanel({frm: cur_frm});

View File

@ -116,10 +116,10 @@ def upload():
if not frappe.has_permission("Attendance", "create"):
raise frappe.PermissionError
from frappe.utils.csvutils import read_csv_content_from_uploaded_file
from frappe.utils.csvutils import read_csv_content
from frappe.modules import scrub
rows = read_csv_content_from_uploaded_file()
rows = read_csv_content(frappe.local.uploaded_file)
rows = list(filter(lambda x: x and any(x), rows))
if not rows:
msg = [_("Please select a csv file")]