From 79cb3f0596f263c989667864ee905a8df1d8bd9e Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 4 Feb 2021 14:06:09 +0530 Subject: [PATCH] feat: Rename "Custom Script" to "Client Script" * Remove postfix "-Client" from ClientScript.autoname --- frappe/core/doctype/doctype/doctype.json | 2 +- frappe/core/workspace/build/build.json | 7 ++--- .../README.md | 0 .../__init__.py | 0 .../client_script.js} | 2 +- .../client_script.json} | 23 ++++++---------- .../client_script.py} | 4 +-- .../test_client_script.py} | 4 +-- .../customization/customization.json | 17 ++++++++---- frappe/desk/form/meta.py | 2 +- frappe/desk/form/utils.py | 2 +- frappe/model/__init__.py | 2 +- frappe/model/delete_doc.py | 2 +- .../public/js/frappe/form/script_manager.js | 2 +- frappe/public/js/frappe/model/model.js | 2 +- frappe/tests/test_exporter_fixtures.py | 26 +++++++++---------- frappe/utils/fixtures.py | 6 ++--- 17 files changed, 52 insertions(+), 51 deletions(-) rename frappe/custom/doctype/{custom_script => client_script}/README.md (100%) rename frappe/custom/doctype/{custom_script => client_script}/__init__.py (100%) rename frappe/custom/doctype/{custom_script/custom_script.js => client_script/client_script.js} (97%) rename frappe/custom/doctype/{custom_script/custom_script.json => client_script/client_script.json} (86%) rename frappe/custom/doctype/{custom_script/custom_script.py => client_script/client_script.py} (84%) rename frappe/custom/doctype/{custom_script/test_custom_script.py => client_script/test_client_script.py} (65%) diff --git a/frappe/core/doctype/doctype/doctype.json b/frappe/core/doctype/doctype/doctype.json index 569414e98b..3ccd1e7e09 100644 --- a/frappe/core/doctype/doctype/doctype.json +++ b/frappe/core/doctype/doctype/doctype.json @@ -555,7 +555,7 @@ }, { "group": "Customization", - "link_doctype": "Custom Script", + "link_doctype": "Client Script", "link_fieldname": "dt" }, { diff --git a/frappe/core/workspace/build/build.json b/frappe/core/workspace/build/build.json index c4bde55d7f..aefda698b1 100644 --- a/frappe/core/workspace/build/build.json +++ b/frappe/core/workspace/build/build.json @@ -11,6 +11,7 @@ "hide_custom": 0, "icon": "tool", "idx": 0, + "is_default": 0, "is_standard": 1, "label": "Build", "links": [ @@ -163,8 +164,8 @@ { "hidden": 0, "is_query_report": 0, - "label": "Custom Script", - "link_to": "Custom Script", + "label": "Client Script", + "link_to": "Client Script", "link_type": "DocType", "onboard": 0, "only_for": "", @@ -181,7 +182,7 @@ "type": "Link" } ], - "modified": "2021-01-02 14:03:15.029699", + "modified": "2021-02-04 13:48:48.493146", "modified_by": "Administrator", "module": "Core", "name": "Build", diff --git a/frappe/custom/doctype/custom_script/README.md b/frappe/custom/doctype/client_script/README.md similarity index 100% rename from frappe/custom/doctype/custom_script/README.md rename to frappe/custom/doctype/client_script/README.md diff --git a/frappe/custom/doctype/custom_script/__init__.py b/frappe/custom/doctype/client_script/__init__.py similarity index 100% rename from frappe/custom/doctype/custom_script/__init__.py rename to frappe/custom/doctype/client_script/__init__.py diff --git a/frappe/custom/doctype/custom_script/custom_script.js b/frappe/custom/doctype/client_script/client_script.js similarity index 97% rename from frappe/custom/doctype/custom_script/custom_script.js rename to frappe/custom/doctype/client_script/client_script.js index 711e7d1796..21e7334b82 100644 --- a/frappe/custom/doctype/custom_script/custom_script.js +++ b/frappe/custom/doctype/client_script/client_script.js @@ -1,7 +1,7 @@ // Copyright (c) 2016, Frappe Technologies and contributors // For license information, please see license.txt -frappe.ui.form.on('Custom Script', { +frappe.ui.form.on('Client Script', { refresh(frm) { if (frm.doc.dt && frm.doc.script) { frm.add_custom_button(__('Go to {0}', [frm.doc.dt]), diff --git a/frappe/custom/doctype/custom_script/custom_script.json b/frappe/custom/doctype/client_script/client_script.json similarity index 86% rename from frappe/custom/doctype/custom_script/custom_script.json rename to frappe/custom/doctype/client_script/client_script.json index 328b247c49..57e6c68094 100644 --- a/frappe/custom/doctype/custom_script/custom_script.json +++ b/frappe/custom/doctype/client_script/client_script.json @@ -2,7 +2,7 @@ "actions": [], "allow_import": 1, "creation": "2013-01-10 16:34:01", - "description": "Adds a client custom script to a DocType", + "description": "Adds a custom client script to a DocType", "doctype": "DocType", "document_type": "Document", "engine": "InnoDB", @@ -22,9 +22,7 @@ "oldfieldname": "dt", "oldfieldtype": "Link", "options": "DocType", - "reqd": 1, - "show_days": 1, - "show_seconds": 1 + "reqd": 1 }, { "fieldname": "script", @@ -32,35 +30,29 @@ "label": "Script", "oldfieldname": "script", "oldfieldtype": "Code", - "options": "JS", - "show_days": 1, - "show_seconds": 1 + "options": "JS" }, { "fieldname": "sample", "fieldtype": "HTML", "label": "Sample", - "options": "

Custom Script Help

\n

Custom Scripts are executed only on the client-side (i.e. in Forms). Here are some examples to get you started

\n
\n\n// fetch local_tax_no on selection of customer \n// cur_frm.add_fetch(link_field,  source_fieldname,  target_fieldname); \ncur_frm.add_fetch('customer',  'local_tax_no',  'local_tax_no');\n\n// additional validation on dates \nfrappe.ui.form.on('Task',  'validate',  function(frm) {\n    if (frm.doc.from_date < get_today()) {\n        msgprint('You can not select past date in From Date');\n        validated = false;\n    } \n});\n\n// make a field read-only after saving \nfrappe.ui.form.on('Task',  {\n    refresh: function(frm) {\n        // use the __islocal value of doc,  to check if the doc is saved or not\n        frm.set_df_property('myfield',  'read_only',  frm.doc.__islocal ? 0 : 1);\n    } \n});\n\n// additional permission check\nfrappe.ui.form.on('Task',  {\n    validate: function(frm) {\n        if(user=='user1@example.com' && frm.doc.purpose!='Material Receipt') {\n            msgprint('You are only allowed Material Receipt');\n            validated = false;\n        }\n    } \n});\n\n// calculate sales incentive\nfrappe.ui.form.on('Sales Invoice',  {\n    validate: function(frm) {\n        // calculate incentives for each person on the deal\n        total_incentive = 0\n        $.each(frm.doc.sales_team,  function(i,  d) {\n            // calculate incentive\n            var incentive_percent = 2;\n            if(frm.doc.base_grand_total > 400) incentive_percent = 4;\n            // actual incentive\n            d.incentives = flt(frm.doc.base_grand_total) * incentive_percent / 100;\n            total_incentive += flt(d.incentives)\n        });\n        frm.doc.total_incentive = total_incentive;\n    } \n})\n\n
", - "show_days": 1, - "show_seconds": 1 + "options": "

Client Script Help

\n

Client Scripts are executed only on the client-side (i.e. in Forms). Here are some examples to get you started

\n
\n\n// fetch local_tax_no on selection of customer \n// cur_frm.add_fetch(link_field,  source_fieldname,  target_fieldname); \ncur_frm.add_fetch('customer',  'local_tax_no',  'local_tax_no');\n\n// additional validation on dates \nfrappe.ui.form.on('Task',  'validate',  function(frm) {\n    if (frm.doc.from_date < get_today()) {\n        msgprint('You can not select past date in From Date');\n        validated = false;\n    } \n});\n\n// make a field read-only after saving \nfrappe.ui.form.on('Task',  {\n    refresh: function(frm) {\n        // use the __islocal value of doc,  to check if the doc is saved or not\n        frm.set_df_property('myfield',  'read_only',  frm.doc.__islocal ? 0 : 1);\n    } \n});\n\n// additional permission check\nfrappe.ui.form.on('Task',  {\n    validate: function(frm) {\n        if(user=='user1@example.com' && frm.doc.purpose!='Material Receipt') {\n            msgprint('You are only allowed Material Receipt');\n            validated = false;\n        }\n    } \n});\n\n// calculate sales incentive\nfrappe.ui.form.on('Sales Invoice',  {\n    validate: function(frm) {\n        // calculate incentives for each person on the deal\n        total_incentive = 0\n        $.each(frm.doc.sales_team,  function(i,  d) {\n            // calculate incentive\n            var incentive_percent = 2;\n            if(frm.doc.base_grand_total > 400) incentive_percent = 4;\n            // actual incentive\n            d.incentives = flt(frm.doc.base_grand_total) * incentive_percent / 100;\n            total_incentive += flt(d.incentives)\n        });\n        frm.doc.total_incentive = total_incentive;\n    } \n})\n\n
" }, { "default": "0", "fieldname": "enabled", "fieldtype": "Check", - "label": "Enabled", - "show_days": 1, - "show_seconds": 1 + "label": "Enabled" } ], "icon": "fa fa-glass", "idx": 1, "index_web_pages_for_search": 1, "links": [], - "modified": "2020-08-24 21:56:07.719579", + "modified": "2021-02-04 13:57:56.509437", "modified_by": "Administrator", "module": "Custom", - "name": "Custom Script", + "name": "Client Script", "owner": "Administrator", "permissions": [ { @@ -86,6 +78,7 @@ "write": 1 } ], + "sort_field": "modified", "sort_order": "ASC", "track_changes": 1 } \ No newline at end of file diff --git a/frappe/custom/doctype/custom_script/custom_script.py b/frappe/custom/doctype/client_script/client_script.py similarity index 84% rename from frappe/custom/doctype/custom_script/custom_script.py rename to frappe/custom/doctype/client_script/client_script.py index e15819de65..e252e2a750 100644 --- a/frappe/custom/doctype/custom_script/custom_script.py +++ b/frappe/custom/doctype/client_script/client_script.py @@ -5,9 +5,9 @@ import frappe from frappe.model.document import Document -class CustomScript(Document): +class ClientScript(Document): def autoname(self): - self.name = self.dt + "-Client" + self.name = self.dt def on_update(self): frappe.clear_cache(doctype=self.dt) diff --git a/frappe/custom/doctype/custom_script/test_custom_script.py b/frappe/custom/doctype/client_script/test_client_script.py similarity index 65% rename from frappe/custom/doctype/custom_script/test_custom_script.py rename to frappe/custom/doctype/client_script/test_client_script.py index 6947e6060d..de113c1ce7 100644 --- a/frappe/custom/doctype/custom_script/test_custom_script.py +++ b/frappe/custom/doctype/client_script/test_client_script.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import frappe import unittest -# test_records = frappe.get_test_records('Custom Script') +# test_records = frappe.get_test_records('Client Script') -class TestCustomScript(unittest.TestCase): +class TestClientScript(unittest.TestCase): pass diff --git a/frappe/custom/workspace/customization/customization.json b/frappe/custom/workspace/customization/customization.json index 3631914249..cdc3b73366 100644 --- a/frappe/custom/workspace/customization/customization.json +++ b/frappe/custom/workspace/customization/customization.json @@ -10,6 +10,7 @@ "hide_custom": 0, "icon": "customization", "idx": 0, + "is_default": 0, "is_standard": 1, "label": "Customization", "links": [ @@ -81,8 +82,8 @@ "dependencies": "", "hidden": 0, "is_query_report": 0, - "label": "Custom Script", - "link_to": "Custom Script", + "label": "Client Script", + "link_to": "Client Script", "link_type": "DocType", "onboard": 0, "type": "Link" @@ -115,7 +116,7 @@ "type": "Link" } ], - "modified": "2020-12-01 13:38:39.843773", + "modified": "2021-02-04 13:50:35.750463", "modified_by": "Administrator", "module": "Custom", "name": "Customization", @@ -134,8 +135,14 @@ "type": "DocType" }, { - "label": "Custom Script", - "link_to": "Custom Script", + "label": "Client Script", + "link_to": "Client Script", + "type": "DocType" + }, + { + "doc_view": "", + "label": "Server Script", + "link_to": "Server Script", "type": "DocType" } ] diff --git a/frappe/desk/form/meta.py b/frappe/desk/form/meta.py index d5428b1da2..c63da93a33 100644 --- a/frappe/desk/form/meta.py +++ b/frappe/desk/form/meta.py @@ -130,7 +130,7 @@ class FormMeta(Meta): def add_custom_script(self): """embed all require files""" # custom script - custom = frappe.db.get_value("Custom Script", {"dt": self.name, "enabled": 1}, "script") or "" + custom = frappe.db.get_value("Client Script", {"dt": self.name, "enabled": 1}, "script") or "" self.set("__custom_js", custom) diff --git a/frappe/desk/form/utils.py b/frappe/desk/form/utils.py index 4c3bab2e23..395d2b9571 100644 --- a/frappe/desk/form/utils.py +++ b/frappe/desk/form/utils.py @@ -47,7 +47,7 @@ def validate_link(): except Exception as e: error_message = str(e).split("Unknown column '") fieldname = None if len(error_message)<=1 else error_message[1].split("'")[0] - frappe.msgprint(_("Wrong fieldname {0} in add_fetch configuration of custom script").format(fieldname)) + frappe.msgprint(_("Wrong fieldname {0} in add_fetch configuration of custom client script").format(fieldname)) frappe.errprint(frappe.get_traceback()) if fetch_value: diff --git a/frappe/model/__init__.py b/frappe/model/__init__.py index c39a73ccd7..af06696621 100644 --- a/frappe/model/__init__.py +++ b/frappe/model/__init__.py @@ -118,7 +118,7 @@ core_doctypes_list = ( 'Customize Form Field', 'Property Setter', 'Custom Field', - 'Custom Script' + 'Client Script' ) log_types = ( diff --git a/frappe/model/delete_doc.py b/frappe/model/delete_doc.py index 7b29692ad1..d0e0a6fb1a 100644 --- a/frappe/model/delete_doc.py +++ b/frappe/model/delete_doc.py @@ -68,7 +68,7 @@ def delete_doc(doctype=None, name=None, force=0, ignore_doctypes=None, for_reloa check_permission_and_not_submitted(doc) frappe.db.sql("delete from `tabCustom Field` where dt = %s", name) - frappe.db.sql("delete from `tabCustom Script` where dt = %s", name) + frappe.db.sql("delete from `tabClient Script` where dt = %s", name) frappe.db.sql("delete from `tabProperty Setter` where doc_type = %s", name) frappe.db.sql("delete from `tabReport` where ref_doctype=%s", name) frappe.db.sql("delete from `tabCustom DocPerm` where parent=%s", name) diff --git a/frappe/public/js/frappe/form/script_manager.js b/frappe/public/js/frappe/form/script_manager.js index 7ac3673b08..770319ba53 100644 --- a/frappe/public/js/frappe/form/script_manager.js +++ b/frappe/public/js/frappe/form/script_manager.js @@ -176,7 +176,7 @@ frappe.ui.form.ScriptManager = Class.extend({ eval(doctype.__custom_js); } catch(e) { frappe.msgprint({ - title: __('Error in Custom Script'), + title: __('Error in Client Script'), indicator: 'orange', message: '
' + e.stack  + '
' }); diff --git a/frappe/public/js/frappe/model/model.js b/frappe/public/js/frappe/model/model.js index a2e872085e..9ec7b0e931 100644 --- a/frappe/public/js/frappe/model/model.js +++ b/frappe/public/js/frappe/model/model.js @@ -15,7 +15,7 @@ $.extend(frappe.model, { core_doctypes_list: ['DocType', 'DocField', 'DocPerm', 'User', 'Role', 'Has Role', 'Page', 'Module Def', 'Print Format', 'Report', 'Customize Form', - 'Customize Form Field', 'Property Setter', 'Custom Field', 'Custom Script'], + 'Customize Form Field', 'Property Setter', 'Custom Field', 'Client Script'], std_fields: [ {fieldname:'name', fieldtype:'Link', label:__('ID')}, diff --git a/frappe/tests/test_exporter_fixtures.py b/frappe/tests/test_exporter_fixtures.py index a860cc6a96..b8bd94e3e9 100644 --- a/frappe/tests/test_exporter_fixtures.py +++ b/frappe/tests/test_exporter_fixtures.py @@ -12,9 +12,9 @@ class TestDataImportFixtures(unittest.TestCase): def setUp(self): pass - #start test for Custom Script + #start test for Client Script def test_Custom_Script_fixture_simple(self): - fixture = "Custom Script" + fixture = "Client Script" path = frappe.scrub(fixture) + "_original_style.csv" export_csv(fixture, path) @@ -22,7 +22,7 @@ class TestDataImportFixtures(unittest.TestCase): os.remove(path) def test_Custom_Script_fixture_simple_name_equal_default(self): - fixture = ["Custom Script", {"name":["Item-Client"]}] + fixture = ["Client Script", {"name":["Item"]}] path = frappe.scrub(fixture[0]) + "_simple_name_equal_default.csv" export_csv(fixture, path) @@ -30,7 +30,7 @@ class TestDataImportFixtures(unittest.TestCase): os.remove(path) def test_Custom_Script_fixture_simple_name_equal(self): - fixture = ["Custom Script", {"name":["Item-Client"],"op":"="}] + fixture = ["Client Script", {"name":["Item"],"op":"="}] path = frappe.scrub(fixture[0]) + "_simple_name_equal.csv" export_csv(fixture, path) @@ -38,7 +38,7 @@ class TestDataImportFixtures(unittest.TestCase): os.remove(path) def test_Custom_Script_fixture_simple_name_not_equal(self): - fixture = ["Custom Script", {"name":["Item-Client"],"op":"!="}] + fixture = ["Client Script", {"name":["Item"],"op":"!="}] path = frappe.scrub(fixture[0]) + "_simple_name_not_equal.csv" export_csv(fixture, path) @@ -47,7 +47,7 @@ class TestDataImportFixtures(unittest.TestCase): #without [] around the name... def test_Custom_Script_fixture_simple_name_at_least_equal(self): - fixture = ["Custom Script", {"name":"Item-Cli"}] + fixture = ["Client Script", {"name":"Item-Cli"}] path = frappe.scrub(fixture[0]) + "_simple_name_at_least_equal.csv" export_csv(fixture, path) @@ -55,7 +55,7 @@ class TestDataImportFixtures(unittest.TestCase): os.remove(path) def test_Custom_Script_fixture_multi_name_equal(self): - fixture = ["Custom Script", {"name":["Item-Client", "Customer-Client"],"op":"="}] + fixture = ["Client Script", {"name":["Item", "Customer"],"op":"="}] path = frappe.scrub(fixture[0]) + "_multi_name_equal.csv" export_csv(fixture, path) @@ -63,7 +63,7 @@ class TestDataImportFixtures(unittest.TestCase): os.remove(path) def test_Custom_Script_fixture_multi_name_not_equal(self): - fixture = ["Custom Script", {"name":["Item-Client", "Customer-Client"],"op":"!="}] + fixture = ["Client Script", {"name":["Item", "Customer"],"op":"!="}] path = frappe.scrub(fixture[0]) + "_multi_name_not_equal.csv" export_csv(fixture, path) @@ -71,7 +71,7 @@ class TestDataImportFixtures(unittest.TestCase): os.remove(path) def test_Custom_Script_fixture_empty_object(self): - fixture = ["Custom Script", {}] + fixture = ["Client Script", {}] path = frappe.scrub(fixture[0]) + "_empty_object_should_be_all.csv" export_csv(fixture, path) @@ -79,16 +79,16 @@ class TestDataImportFixtures(unittest.TestCase): os.remove(path) def test_Custom_Script_fixture_just_list(self): - fixture = ["Custom Script"] + fixture = ["Client Script"] path = frappe.scrub(fixture[0]) + "_just_list_should_be_all.csv" export_csv(fixture, path) self.assertTrue(True) os.remove(path) - # Custom Script regular expression + # Client Script regular expression def test_Custom_Script_fixture_rex_no_flags(self): - fixture = ["Custom Script", {"name":r"^[i|A]"}] + fixture = ["Client Script", {"name":r"^[i|A]"}] path = frappe.scrub(fixture[0]) + "_rex_no_flags.csv" export_csv(fixture, path) @@ -96,7 +96,7 @@ class TestDataImportFixtures(unittest.TestCase): os.remove(path) def test_Custom_Script_fixture_rex_with_flags(self): - fixture = ["Custom Script", {"name":r"^[i|A]", "flags":"L,M"}] + fixture = ["Client Script", {"name":r"^[i|A]", "flags":"L,M"}] path = frappe.scrub(fixture[0]) + "_rex_with_flags.csv" export_csv(fixture, path) diff --git a/frappe/utils/fixtures.py b/frappe/utils/fixtures.py index a1b4eadbf3..7bad6391cc 100644 --- a/frappe/utils/fixtures.py +++ b/frappe/utils/fixtures.py @@ -38,13 +38,13 @@ def import_custom_scripts(app): "custom_scripts") + os.path.sep + fname) as f: doctype = fname.rsplit(".", 1)[0] script = f.read() - if frappe.db.exists("Custom Script", {"dt": doctype}): - custom_script = frappe.get_doc("Custom Script", {"dt": doctype}) + if frappe.db.exists("Client Script", {"dt": doctype}): + custom_script = frappe.get_doc("Client Script", {"dt": doctype}) custom_script.script = script custom_script.save() else: frappe.get_doc({ - "doctype":"Custom Script", + "doctype":"Client Script", "dt": doctype, "script": script }).insert()