feat: rename to package

This commit is contained in:
Himanshu Warekar 2020-03-14 11:59:13 +05:30 committed by Saurabh
parent 846594d6c8
commit b3f45bd81c
9 changed files with 82 additions and 72 deletions

View file

@ -3,7 +3,7 @@ from frappe import _
def get_data():
return [
{
{
"label": _("Form Customization"),
"icon": "fa fa-glass",
"items": [
@ -57,9 +57,9 @@ def get_data():
},
{
"type": "doctype",
"label": _("Custom Tags"),
"name": "Tag Category",
"description": _("Add your own Tag Categories")
"label": _("Package"),
"name": "Package",
"description": _("Import and Export Packages.")
}
]
}

View file

@ -1,18 +1,18 @@
// Copyright (c) 2020, Frappe Technologies and contributors
// For license information, please see license.txt
frappe.ui.form.on('Manage Customization', {
frappe.ui.form.on('Package', {
refresh: function(frm) {
frappe.realtime.on("exporting_progress", (data) => {
if (data.progress !== data.total) {
frappe.realtime.on("exporting_package", (data) => {
if (data.progress !== (data.total-1)) {
frm.dashboard.show_progress("Exporting", data.progress / data.total * 100, __("{0}", [data.message]));
} else {
frm.dashboard.hide_progress();
}
});
frappe.realtime.on("importing_progress", (data) => {
if (data.progress !== data.total) {
frappe.realtime.on("importing_package", (data) => {
if (data.progress !== (data.total-1)) {
frm.dashboard.show_progress("Importing", data.progress / data.total * 100, __("{0}", [data.message]));
} else {
frm.dashboard.hide_progress();
@ -21,11 +21,11 @@ frappe.ui.form.on('Manage Customization', {
},
export: function(frm) {
frappe.call({
method: 'frappe.custom.doctype.manage_customization.manage_customization.export_customizations',
method: 'frappe.custom.doctype.package.package.export_package',
callback: function(r) {
if (r.message) {
const args = {
cmd: 'frappe.custom.doctype.manage_customization.manage_customization.export_customizations',
cmd: 'frappe.custom.doctype.package.package.download_package',
data: r.message.data
};
open_url_post(frappe.request.url, args, true);
@ -35,9 +35,9 @@ frappe.ui.form.on('Manage Customization', {
},
import: function(frm) {
frappe.call({
method: 'frappe.custom.doctype.manage_customization.manage_customization.import_customizations',
method: 'frappe.custom.doctype.package.package.import_package',
callback: function() {
frappe.msgprint(__("Customizations Imported."));
frappe.msgprint(__("Package Imported."));
}
});
}

View file

@ -1,58 +1,58 @@
{
"actions": [],
"creation": "2020-03-01 23:21:17.394500",
"creation": "2020-03-14 11:20:14.850552",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"sb_00",
"export_customization",
"export_package",
"export",
"sb_01",
"import_customization",
"import_package",
"import"
],
"fields": [
{
"fieldname": "export_customization",
"fieldtype": "Table",
"label": "Customizations to Export",
"options": "Customization Export"
},
{
"fieldname": "sb_00",
"fieldtype": "Section Break",
"label": "Export Customizations"
"label": "Export Package"
},
{
"fieldname": "sb_01",
"fieldtype": "Section Break",
"label": "Import Customizations"
},
{
"fieldname": "import_customization",
"fieldtype": "Attach",
"label": "Attach"
},
{
"depends_on": "export_customization",
"depends_on": "export_package",
"fieldname": "export",
"fieldtype": "Button",
"label": "Export"
},
{
"depends_on": "import_customization",
"fieldname": "sb_01",
"fieldtype": "Section Break",
"label": "Import Package"
},
{
"depends_on": "import_package",
"fieldname": "import",
"fieldtype": "Button",
"label": "Import"
},
{
"fieldname": "export_package",
"fieldtype": "Table",
"label": "Package",
"options": "Package DocType"
},
{
"fieldname": "import_package",
"fieldtype": "Attach",
"label": "Attach"
}
],
"issingle": 1,
"links": [],
"modified": "2020-03-13 17:14:00.382402",
"modified": "2020-03-14 11:52:58.221081",
"modified_by": "Administrator",
"module": "Custom",
"name": "Manage Customization",
"name": "Package",
"owner": "Administrator",
"permissions": [
{
@ -64,6 +64,16 @@
"role": "System Manager",
"share": 1,
"write": 1
},
{
"create": 1,
"delete": 1,
"email": 1,
"print": 1,
"read": 1,
"role": "All",
"share": 1,
"write": 1
}
],
"quick_entry": 1,

View file

@ -7,17 +7,17 @@ import frappe
from frappe.model.document import Document
import json
class ManageCustomization(Document):
class Package(Document):
pass
@frappe.whitelist()
def export_customizations():
"""Export fixtures as JSON"""
def export_package():
"""Export package as JSON"""
export_customizations_doc = frappe.get_single("Manage Customization")
customizations = []
package_doc = frappe.get_single("Package")
package = []
for doctype in export_customizations_doc.export_customization:
for doctype in package_doc.export_package:
filters, or_filters = {}, {}
if doctype.get("filters"):
@ -28,36 +28,36 @@ def export_customizations():
docs = frappe.get_all(doctype.get("document_type"), filters=filters, or_filters=or_filters)
length = len(docs)
for idx, doc in enumerate(docs):
frappe.publish_realtime("exporting_progress", dict(progress=idx, total=length, message=doctype.get("document_type")), user=frappe.session.user)
customizations.append(frappe.get_doc(doctype.get("document_type"), doc.name).as_dict())
frappe.publish_realtime("exporting_package", dict(progress=idx, total=length, message=doctype.get("document_type")), user=frappe.session.user)
package.append(frappe.get_doc(doctype.get("document_type"), doc.name).as_dict())
return frappe._dict({
"data": post_process(customizations)
"data": post_process(package)
})
@frappe.whitelist()
def import_customizations():
"""Import fixtures as JSON"""
def import_package():
"""Import package from JSON"""
import_file = frappe.get_all("File", filters={
"attached_to_doctype": "Manage Customization",
"attached_to_name": "Manage Customization"
package_file = frappe.get_all("File", filters={
"attached_to_doctype": "Package",
"attached_to_name": "Package"
}, limit=1, order_by="creation desc")
if not import_file:
if not package_file:
return
content = json.loads(frappe.get_doc("File", import_file[0].name).get_content())
content = json.loads(frappe.get_doc("File", package_file[0].name).get_content())
length = len(content)
for idx, doc in enumerate(content.get("message").get("data")):
frappe.publish_realtime("exporting_progress", dict(progress=idx, total=length, message=doc.get("doctype")), user=frappe.session.user)
frappe.publish_realtime("importing_package", dict(progress=idx, total=length, message=doc.get("doctype")), user=frappe.session.user)
frappe.get_doc(doc).insert(ignore_permissions=True, ignore_if_duplicate=True)
def post_process(customizations):
def post_process(package):
del_keys = ('modified_by', 'creation', 'owner', 'idx', 'name', 'modified', 'docstatus')
for doc in customizations:
for doc in package:
for key in del_keys:
if key in doc:
del doc[key]
@ -71,12 +71,12 @@ def post_process(customizations):
if key in child:
del child[key]
return customizations
return package
@frappe.whitelist()
def download_customization_json():
def download_package():
data = frappe._dict(frappe.local.form_dict)
frappe.response['filename'] = 'Customizations.json'
frappe.response['filename'] = 'Package.json'
frappe.response['filecontent'] = data.get("data")
frappe.response['content_type'] = 'application/json'
frappe.response['type'] = 'download'

View file

@ -6,5 +6,5 @@ from __future__ import unicode_literals
# import frappe
import unittest
class TestManageCustomization(unittest.TestCase):
class TestPackage(unittest.TestCase):
pass

View file

@ -1,6 +1,6 @@
{
"actions": [],
"creation": "2020-03-12 14:51:09.260025",
"creation": "2020-03-14 11:20:42.875446",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
@ -20,33 +20,33 @@
"options": "DocType",
"reqd": 1
},
{
"fieldname": "sb_00",
"fieldtype": "Section Break"
},
{
"fieldname": "filters",
"fieldtype": "Code",
"in_list_view": 1,
"label": "Filters"
},
{
"fieldname": "cb_00",
"fieldtype": "Column Break"
},
{
"fieldname": "or_filters",
"fieldtype": "Code",
"in_list_view": 1,
"label": "Or Filters"
},
{
"fieldname": "sb_00",
"fieldtype": "Section Break"
},
{
"fieldname": "cb_00",
"fieldtype": "Column Break"
}
],
"istable": 1,
"links": [],
"modified": "2020-03-13 16:53:15.214275",
"modified": "2020-03-14 11:20:42.875446",
"modified_by": "Administrator",
"module": "Custom",
"name": "Customization Export",
"name": "Package DocType",
"owner": "Administrator",
"permissions": [],
"quick_entry": 1,

View file

@ -6,5 +6,5 @@ from __future__ import unicode_literals
# import frappe
from frappe.model.document import Document
class CustomizationExport(Document):
class PackageDocType(Document):
pass