Bladeren bron

Merge pull request #11809 from frappe/fix_web_template_display

version-14
Faris Ansari 4 jaren geleden
committed by GitHub
bovenliggende
commit
e79cc929be
Geen bekende sleutel gevonden voor deze handtekening in de database GPG sleutel-ID: 4AEE18F83AFDEB23
2 gewijzigde bestanden met toevoegingen van 30 en 10 verwijderingen
  1. +3
    -0
      frappe/website/doctype/web_template/web_template.js
  2. +27
    -10
      frappe/website/doctype/web_template/web_template.py

+ 3
- 0
frappe/website/doctype/web_template/web_template.js Bestand weergeven

@@ -8,6 +8,9 @@ frappe.ui.form.on('Web Template', {
}

frm.toggle_display('standard', frappe.boot.developer_mode);
// necessary to show template field again, after it was hidden when
// unchecking 'standard'.
frm.toggle_display('template', !frm.doc.standard);
},
standard: function(frm) {
if (!frm.doc.standard && !frm.is_new()) {


+ 27
- 10
frappe/website/doctype/web_template/web_template.py Bestand weergeven

@@ -11,7 +11,7 @@ import frappe
from frappe.model.document import Document
from frappe import _
from frappe.modules.export_file import (
export_to_files,
write_document_file,
get_module_path,
scrub_dt_dn,
)
@@ -26,28 +26,45 @@ class WebTemplate(Document):
if not field.fieldname:
field.fieldname = frappe.scrub(field.label)

def on_update(self):
def before_save(self):
if frappe.conf.developer_mode:
# custom to standard
if self.standard:
export_to_files(record_list=[["Web Template", self.name]], create_init=True)
self.create_template_file()
self.template = ""
self.export_to_files()

# standard to custom
was_standard = (self.get_doc_before_save() or {}).get("standard")
if was_standard and not self.standard:
self.template = self.get_template(standard=True)
rmtree(self.get_template_folder())
self.import_from_files()

def create_template_file(self):
def on_trash(self):
if frappe.conf.developer_mode and self.standard:
# delete template html and json files
rmtree(self.get_template_folder())

def export_to_files(self):
"""Export Web Template to a new folder.

Doc is exported as JSON. The content of the `template` field gets
written into a separate HTML file. The template should not be contained
in the JSON.
"""
html, self.template = self.template, ""
write_document_file(self, create_init=True)
self.create_template_file(html)

def import_from_files(self):
self.template = self.get_template(standard=True)
rmtree(self.get_template_folder())

def create_template_file(self, html=None):
"""Touch a HTML file for the Web Template and add existing content, if any."""
if self.standard:
path = self.get_template_path()
if not os.path.exists(path):
with open(path, "w") as template_file:
if self.template:
template_file.write(self.template)
if html:
template_file.write(html)

def get_template_folder(self):
"""Return the absolute path to the template's folder."""


Laden…
Annuleren
Opslaan