Merge pull request #4207 from rmehta/rename-tool
[feature] rename via console merge with frappe/frappe#1349
This commit is contained in:
commit
99ba924303
@ -21,7 +21,7 @@ frappe.ui.form.on("Rename Tool", {
|
|||||||
select_doctype: frm.doc.select_doctype
|
select_doctype: frm.doc.select_doctype
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
frm.get_field("rename_log").$wrapper.html(r.message);
|
frm.get_field("rename_log").$wrapper.html(r.message.join("<br>"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
|
||||||
|
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.model.rename_doc import bulk_rename
|
||||||
|
|
||||||
class RenameTool(Document):
|
class RenameTool(Document):
|
||||||
pass
|
pass
|
||||||
@ -20,37 +20,13 @@ def get_doctypes():
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def upload(select_doctype=None, rows=None):
|
def upload(select_doctype=None, rows=None):
|
||||||
from frappe.utils.csvutils import read_csv_content_from_attached_file
|
from frappe.utils.csvutils import read_csv_content_from_attached_file
|
||||||
from frappe.model.rename_doc import rename_doc
|
|
||||||
|
|
||||||
if not select_doctype:
|
if not select_doctype:
|
||||||
select_doctype = frappe.form_dict.select_doctype
|
select_doctype = frappe.form_dict.select_doctype
|
||||||
|
|
||||||
if not frappe.has_permission(select_doctype, "write"):
|
if not frappe.has_permission(select_doctype, "write"):
|
||||||
raise frappe.PermissionError
|
raise frappe.PermissionError
|
||||||
|
|
||||||
if not rows:
|
|
||||||
rows = read_csv_content_from_attached_file(frappe.get_doc("Rename Tool", "Rename Tool"))
|
rows = read_csv_content_from_attached_file(frappe.get_doc("Rename Tool", "Rename Tool"))
|
||||||
if not rows:
|
|
||||||
frappe.throw(_("Please select a valid csv file with data"))
|
|
||||||
|
|
||||||
max_rows = 500
|
return bulk_rename(select_doctype, rows=rows)
|
||||||
if len(rows) > max_rows:
|
|
||||||
frappe.throw(_("Maximum {0} rows allowed").format(max_rows))
|
|
||||||
|
|
||||||
rename_log = []
|
|
||||||
for row in rows:
|
|
||||||
# if row has some content
|
|
||||||
if len(row) > 1 and row[0] and row[1]:
|
|
||||||
try:
|
|
||||||
if rename_doc(select_doctype, row[0], row[1]):
|
|
||||||
rename_log.append(_("Successful: ") + row[0] + " -> " + row[1])
|
|
||||||
frappe.db.commit()
|
|
||||||
else:
|
|
||||||
rename_log.append(_("Ignored: ") + row[0] + " -> " + row[1])
|
|
||||||
except Exception, e:
|
|
||||||
rename_log.append("<span style='color: RED'>" + \
|
|
||||||
_("Failed: ") + row[0] + " -> " + row[1] + "</span>")
|
|
||||||
rename_log.append("<span style='margin-left: 20px;'>" + repr(e) + "</span>")
|
|
||||||
frappe.db.rollback()
|
|
||||||
|
|
||||||
return rename_log
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user