fix: Web Template

- Disable standard web template form in production
- Prevent standard web template creation in production
- Set type for all templates
This commit is contained in:
Faris Ansari 2020-09-11 16:00:25 +05:30
parent 687298f723
commit e662047f26
17 changed files with 67 additions and 40 deletions

View file

@ -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);
}
});

View file

@ -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)

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}

View file

@ -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"
}