feat: add manual import
This commit is contained in:
parent
b77d93d22a
commit
0f1eaee1be
4 changed files with 43 additions and 7 deletions
|
|
@ -17,6 +17,9 @@ frappe.ui.form.on('Package', {
|
|||
};
|
||||
})
|
||||
},
|
||||
import: function(frm) {
|
||||
frm.call("import_from_package");
|
||||
}
|
||||
});
|
||||
|
||||
frappe.ui.form.on('Package DocType', {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@
|
|||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"export_package"
|
||||
"export_package",
|
||||
"import_section",
|
||||
"attach",
|
||||
"import"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
|
|
@ -14,11 +17,28 @@
|
|||
"fieldtype": "Table",
|
||||
"label": "Package",
|
||||
"options": "Package DocType"
|
||||
},
|
||||
{
|
||||
"collapsible": 1,
|
||||
"collapsible_depends_on": "attach",
|
||||
"fieldname": "import_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Import Package"
|
||||
},
|
||||
{
|
||||
"fieldname": "import",
|
||||
"fieldtype": "Button",
|
||||
"label": "Import"
|
||||
},
|
||||
{
|
||||
"fieldname": "attach",
|
||||
"fieldtype": "Attach",
|
||||
"label": "Attach Package"
|
||||
}
|
||||
],
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2020-03-17 16:41:13.542896",
|
||||
"modified": "2020-03-19 22:03:06.012473",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Custom",
|
||||
"name": "Package",
|
||||
|
|
|
|||
|
|
@ -11,9 +11,22 @@ from frappe.model.document import Document
|
|||
from frappe.core.doctype.version.version import get_diff
|
||||
from frappe.utils.file_manager import save_file, get_file
|
||||
from frappe import _
|
||||
from six import string_types
|
||||
|
||||
class Package(Document):
|
||||
pass
|
||||
|
||||
def import_from_package(self):
|
||||
filters = {"attached_to_doctype": "Package", "attached_to_name": "Package"}
|
||||
files = frappe.get_list("File", filters=filters, limit=1, order_by="creation desc")
|
||||
if not files:
|
||||
frappe.msgprint(_("No file attach for Importing."))
|
||||
return
|
||||
|
||||
for f in files:
|
||||
fname, fcontents = get_file(f.name)
|
||||
import_package(fcontents)
|
||||
|
||||
frappe.msgprint(_("Package Imported."))
|
||||
|
||||
@frappe.whitelist()
|
||||
def export_package():
|
||||
|
|
@ -57,10 +70,10 @@ def export_package():
|
|||
def import_package(package=None):
|
||||
"""Import package from JSON"""
|
||||
|
||||
content = json.loads(package)
|
||||
length = len(content)
|
||||
if isinstance(package, string_types):
|
||||
package = json.loads(package)
|
||||
|
||||
for doc in content:
|
||||
for doc in package:
|
||||
modified = doc.pop("modified")
|
||||
overwrite = doc.pop("overwrite")
|
||||
attachments = doc.pop("attachments")
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ def get_date_str(date_obj):
|
|||
|
||||
def get_time_str(timedelta_obj):
|
||||
if isinstance(timedelta_obj, string_types):
|
||||
timedelta_obj = to_timedelta(date_obj)
|
||||
timedelta_obj = to_timedelta(timedelta_obj)
|
||||
|
||||
hours, remainder = divmod(timedelta_obj.seconds, 3600)
|
||||
minutes, seconds = divmod(remainder, 60)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue