From e662047f26df9c0824459cea66a44a529b4cf4c6 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Fri, 11 Sep 2020 16:00:25 +0530 Subject: [PATCH] fix: Web Template - Disable standard web template form in production - Prevent standard web template creation in production - Set type for all templates --- .../doctype/web_template/web_template.js | 8 ++++++-- .../doctype/web_template/web_template.py | 18 +++++++++++++----- .../full_width_image/full_width_image.json | 5 +++-- frappe/website/web_template/hero/hero.json | 7 ++++--- .../hero_with_right_image.json | 5 +++-- .../web_template/markdown/markdown.json | 5 +++-- .../section_with_cards/section_with_cards.json | 5 +++-- .../section_with_collapsible_content.json | 5 +++-- .../section_with_cta/section_with_cta.json | 5 +++-- .../section_with_embed/section_with_embed.json | 7 ++++--- .../section_with_features.json | 7 ++++--- .../section_with_image/section_with_image.json | 5 +++-- .../section_with_image_grid.json | 5 +++-- .../section_with_small_cta.json | 5 +++-- .../section_with_tabs/section_with_tabs.json | 5 +++-- .../split_section_with_image.json | 5 +++-- .../web_template/testimonial/testimonial.json | 5 +++-- 17 files changed, 67 insertions(+), 40 deletions(-) diff --git a/frappe/website/doctype/web_template/web_template.js b/frappe/website/doctype/web_template/web_template.js index aacfd485bb..99dc02bfbb 100644 --- a/frappe/website/doctype/web_template/web_template.js +++ b/frappe/website/doctype/web_template/web_template.js @@ -2,7 +2,11 @@ // For license information, please see license.txt frappe.ui.form.on('Web Template', { - // refresh: function(frm) { + refresh(frm) { + if (!frappe.boot.developer_mode && frm.doc.standard) { + frm.disable_form(); + } - // } + frm.toggle_display('standard', frappe.boot.developer_mode); + } }); diff --git a/frappe/website/doctype/web_template/web_template.py b/frappe/website/doctype/web_template/web_template.py index cd5e19bbf2..ed228ac7e4 100644 --- a/frappe/website/doctype/web_template/web_template.py +++ b/frappe/website/doctype/web_template/web_template.py @@ -6,11 +6,19 @@ from __future__ import unicode_literals import frappe import os from frappe.model.document import Document -from frappe.modules.export_file import export_to_files, create_folder, get_module_path, scrub_dt_dn +from frappe.modules.export_file import ( + export_to_files, + create_folder, + get_module_path, + scrub_dt_dn, +) class WebTemplate(Document): def validate(self): + if not frappe.conf.developer_mode and self.standard: + frappe.throw(_("Cannot create standard Web Template")) + for field in self.fields: if not field.fieldname: field.fieldname = frappe.scrub(field.label) @@ -23,9 +31,9 @@ class WebTemplate(Document): def create_template_file(self): if self.standard: folder = create_folder("Website", self.doctype, self.name, False) - path = os.path.join(folder, frappe.scrub(self.name) + '.html') + path = os.path.join(folder, frappe.scrub(self.name) + ".html") if not os.path.exists(path): - open(path, 'w').close() + open(path, "w").close() def render(self, values): return get_rendered_template(self.name, values) @@ -38,11 +46,11 @@ def get_rendered_template(web_template, values): dt, dn = scrub_dt_dn("Web Template", web_template) scrubbed = frappe.scrub(web_template) full_path = os.path.join("frappe", module_path, dt, dn, scrubbed + ".html") - root_app_path = os.path.abspath(os.path.join(frappe.get_app_path('frappe'), '..')) + root_app_path = os.path.abspath(os.path.join(frappe.get_app_path("frappe"), "..")) template = os.path.relpath(full_path, root_app_path) else: template = frappe.db.get_value("Web Template", web_template, "template") context = values or {} - context.update({'values': values}) + context.update({"values": values}) return frappe.render_template(template, context) diff --git a/frappe/website/web_template/full_width_image/full_width_image.json b/frappe/website/web_template/full_width_image/full_width_image.json index 08e04e2d3f..8458b6c79b 100644 --- a/frappe/website/web_template/full_width_image/full_width_image.json +++ b/frappe/website/web_template/full_width_image/full_width_image.json @@ -17,10 +17,11 @@ } ], "idx": 0, - "modified": "2020-04-26 15:09:18.173851", + "modified": "2020-09-11 15:52:40.656939", "modified_by": "Administrator", "name": "Full Width Image", "owner": "Administrator", "standard": 1, - "template": "" + "template": "", + "type": "Section" } \ No newline at end of file diff --git a/frappe/website/web_template/hero/hero.json b/frappe/website/web_template/hero/hero.json index 37e06b802d..ca5a0b2d41 100644 --- a/frappe/website/web_template/hero/hero.json +++ b/frappe/website/web_template/hero/hero.json @@ -47,11 +47,12 @@ "reqd": 0 } ], - "idx": 0, - "modified": "2020-04-20 12:27:45.760391", + "idx": 1, + "modified": "2020-09-11 15:52:40.707630", "modified_by": "Administrator", "name": "Hero", "owner": "Administrator", "standard": 1, - "template": "" + "template": "", + "type": "Section" } \ No newline at end of file diff --git a/frappe/website/web_template/hero_with_right_image/hero_with_right_image.json b/frappe/website/web_template/hero_with_right_image/hero_with_right_image.json index 3cb4701e7c..6eff181498 100644 --- a/frappe/website/web_template/hero_with_right_image/hero_with_right_image.json +++ b/frappe/website/web_template/hero_with_right_image/hero_with_right_image.json @@ -53,10 +53,11 @@ } ], "idx": 0, - "modified": "2020-04-29 14:12:31.613545", + "modified": "2020-09-11 15:52:40.636795", "modified_by": "Administrator", "name": "Hero with Right Image", "owner": "Administrator", "standard": 1, - "template": "" + "template": "", + "type": "Section" } \ No newline at end of file diff --git a/frappe/website/web_template/markdown/markdown.json b/frappe/website/web_template/markdown/markdown.json index 34db1d1aab..ff7d44b33f 100644 --- a/frappe/website/web_template/markdown/markdown.json +++ b/frappe/website/web_template/markdown/markdown.json @@ -11,9 +11,10 @@ } ], "idx": 0, - "modified": "2020-04-19 15:56:20.833205", + "modified": "2020-09-11 15:52:40.722171", "modified_by": "Administrator", "name": "Markdown", "owner": "Administrator", - "standard": 1 + "standard": 1, + "type": "Section" } \ No newline at end of file diff --git a/frappe/website/web_template/section_with_cards/section_with_cards.json b/frappe/website/web_template/section_with_cards/section_with_cards.json index 311cced829..cf2f5efb3d 100644 --- a/frappe/website/web_template/section_with_cards/section_with_cards.json +++ b/frappe/website/web_template/section_with_cards/section_with_cards.json @@ -240,9 +240,10 @@ } ], "idx": 0, - "modified": "2020-05-15 13:52:02.984001", + "modified": "2020-09-11 15:58:00.731982", "modified_by": "Administrator", "name": "Section with Cards", "owner": "Administrator", - "standard": 1 + "standard": 1, + "type": "Section" } \ No newline at end of file diff --git a/frappe/website/web_template/section_with_collapsible_content/section_with_collapsible_content.json b/frappe/website/web_template/section_with_collapsible_content/section_with_collapsible_content.json index f35b8d793e..3aca9944fd 100644 --- a/frappe/website/web_template/section_with_collapsible_content/section_with_collapsible_content.json +++ b/frappe/website/web_template/section_with_collapsible_content/section_with_collapsible_content.json @@ -42,10 +42,11 @@ } ], "idx": 0, - "modified": "2020-08-13 15:51:23.728803", + "modified": "2020-09-11 15:52:40.552274", "modified_by": "Administrator", "name": "Section with Collapsible Content", "owner": "Administrator", "standard": 1, - "template": "" + "template": "", + "type": "Section" } \ No newline at end of file diff --git a/frappe/website/web_template/section_with_cta/section_with_cta.json b/frappe/website/web_template/section_with_cta/section_with_cta.json index b1de1c991f..05a4376913 100644 --- a/frappe/website/web_template/section_with_cta/section_with_cta.json +++ b/frappe/website/web_template/section_with_cta/section_with_cta.json @@ -41,9 +41,10 @@ } ], "idx": 0, - "modified": "2020-04-24 22:01:17.098158", + "modified": "2020-09-11 15:52:40.669334", "modified_by": "Administrator", "name": "Section with CTA", "owner": "Administrator", - "standard": 1 + "standard": 1, + "type": "Section" } \ No newline at end of file diff --git a/frappe/website/web_template/section_with_embed/section_with_embed.json b/frappe/website/web_template/section_with_embed/section_with_embed.json index b3564c5a04..9611d6ff81 100644 --- a/frappe/website/web_template/section_with_embed/section_with_embed.json +++ b/frappe/website/web_template/section_with_embed/section_with_embed.json @@ -22,10 +22,11 @@ "reqd": 0 } ], - "idx": 0, - "modified": "2020-08-18 17:45:13.606363", + "idx": 2, + "modified": "2020-09-11 15:52:40.439927", "modified_by": "Administrator", "name": "Section with Embed", "owner": "Administrator", - "standard": 1 + "standard": 1, + "type": "Section" } \ No newline at end of file diff --git a/frappe/website/web_template/section_with_features/section_with_features.json b/frappe/website/web_template/section_with_features/section_with_features.json index 5aa06bffc0..4b15d6dc24 100644 --- a/frappe/website/web_template/section_with_features/section_with_features.json +++ b/frappe/website/web_template/section_with_features/section_with_features.json @@ -53,10 +53,11 @@ "reqd": 0 } ], - "idx": 0, - "modified": "2020-08-18 13:48:43.138779", + "idx": 2, + "modified": "2020-09-11 15:52:40.533302", "modified_by": "Administrator", "name": "Section with Features", "owner": "Administrator", - "standard": 1 + "standard": 1, + "type": "Section" } \ No newline at end of file diff --git a/frappe/website/web_template/section_with_image/section_with_image.json b/frappe/website/web_template/section_with_image/section_with_image.json index 46169a8cc3..f4f6696fd5 100644 --- a/frappe/website/web_template/section_with_image/section_with_image.json +++ b/frappe/website/web_template/section_with_image/section_with_image.json @@ -36,9 +36,10 @@ } ], "idx": 0, - "modified": "2020-08-06 16:08:12.005764", + "modified": "2020-09-11 15:57:55.186983", "modified_by": "Administrator", "name": "Section with Image", "owner": "Administrator", - "standard": 1 + "standard": 1, + "type": "Section" } \ No newline at end of file diff --git a/frappe/website/web_template/section_with_image_grid/section_with_image_grid.json b/frappe/website/web_template/section_with_image_grid/section_with_image_grid.json index 684a4c1910..c3fc77fa88 100644 --- a/frappe/website/web_template/section_with_image_grid/section_with_image_grid.json +++ b/frappe/website/web_template/section_with_image_grid/section_with_image_grid.json @@ -41,10 +41,11 @@ } ], "idx": 0, - "modified": "2020-06-04 16:57:43.097550", + "modified": "2020-09-11 15:52:40.571423", "modified_by": "Administrator", "name": "Section with Image Grid", "owner": "Administrator", "standard": 1, - "template": "" + "template": "", + "type": "Section" } \ No newline at end of file diff --git a/frappe/website/web_template/section_with_small_cta/section_with_small_cta.json b/frappe/website/web_template/section_with_small_cta/section_with_small_cta.json index d392830473..45744f7944 100644 --- a/frappe/website/web_template/section_with_small_cta/section_with_small_cta.json +++ b/frappe/website/web_template/section_with_small_cta/section_with_small_cta.json @@ -29,9 +29,10 @@ } ], "idx": 0, - "modified": "2020-06-01 17:51:23.073342", + "modified": "2020-09-11 15:52:40.588688", "modified_by": "Administrator", "name": "Section with Small CTA", "owner": "Administrator", - "standard": 1 + "standard": 1, + "type": "Section" } \ No newline at end of file diff --git a/frappe/website/web_template/section_with_tabs/section_with_tabs.json b/frappe/website/web_template/section_with_tabs/section_with_tabs.json index 1ff205839a..514a6cff3b 100644 --- a/frappe/website/web_template/section_with_tabs/section_with_tabs.json +++ b/frappe/website/web_template/section_with_tabs/section_with_tabs.json @@ -89,9 +89,10 @@ } ], "idx": 0, - "modified": "2020-04-23 21:22:26.011780", + "modified": "2020-09-11 15:52:40.687774", "modified_by": "Administrator", "name": "Section with Tabs", "owner": "Administrator", - "standard": 1 + "standard": 1, + "type": "Section" } \ No newline at end of file diff --git a/frappe/website/web_template/split_section_with_image/split_section_with_image.json b/frappe/website/web_template/split_section_with_image/split_section_with_image.json index c3885c33d1..d6ebb34a68 100644 --- a/frappe/website/web_template/split_section_with_image/split_section_with_image.json +++ b/frappe/website/web_template/split_section_with_image/split_section_with_image.json @@ -29,10 +29,11 @@ } ], "idx": 0, - "modified": "2020-05-17 06:37:27.461722", + "modified": "2020-09-11 15:52:40.604761", "modified_by": "Administrator", "name": "Split Section with Image", "owner": "Administrator", "standard": 1, - "template": "" + "template": "", + "type": "Section" } \ No newline at end of file diff --git a/frappe/website/web_template/testimonial/testimonial.json b/frappe/website/web_template/testimonial/testimonial.json index 8b194fe81b..b8e7242e26 100644 --- a/frappe/website/web_template/testimonial/testimonial.json +++ b/frappe/website/web_template/testimonial/testimonial.json @@ -23,9 +23,10 @@ } ], "idx": 0, - "modified": "2020-05-16 19:52:11.590319", + "modified": "2020-09-11 15:52:40.622205", "modified_by": "Administrator", "name": "Testimonial", "owner": "Administrator", - "standard": 1 + "standard": 1, + "type": "Section" } \ No newline at end of file