From 031b6cfd4442fbf4c032baeabdff7d6e7d523eb6 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Wed, 30 Jan 2019 16:22:54 +0530 Subject: [PATCH] fix: Rename fields and cleanup --- frappe/templates/base.html | 4 +- .../doctype/website_theme/website_theme.json | 46 ++++++++++++++++--- .../doctype/website_theme/website_theme.py | 21 ++++++--- generate_bootstrap_theme.js | 3 +- 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/frappe/templates/base.html b/frappe/templates/base.html index 4d62eb57ee..c37744a863 100644 --- a/frappe/templates/base.html +++ b/frappe/templates/base.html @@ -25,8 +25,8 @@ {{ head_html or "" }} {%- endif %} - {% if theme.css_file_url %} - + {% if theme.apply_custom_theme and theme.custom_theme_url %} + {% else %} {% endif %} diff --git a/frappe/website/doctype/website_theme/website_theme.json b/frappe/website/doctype/website_theme/website_theme.json index 38d7387417..945c64a65e 100644 --- a/frappe/website/doctype/website_theme/website_theme.json +++ b/frappe/website/doctype/website_theme/website_theme.json @@ -948,7 +948,40 @@ "bold": 0, "collapsible": 0, "columns": 0, - "fieldname": "customize_bootstrap_4", + "fieldname": "apply_custom_theme", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Apply Custom Theme", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "depends_on": "apply_custom_theme", + "fieldname": "custom_theme", "fieldtype": "Code", "hidden": 0, "ignore_user_permissions": 0, @@ -957,7 +990,7 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Customize Bootstrap 4", + "label": "Custom Theme", "length": 0, "no_copy": 0, "options": "SCSS", @@ -981,8 +1014,9 @@ "bold": 0, "collapsible": 0, "columns": 0, - "fieldname": "css_file_url", - "fieldtype": "Data", + "depends_on": "apply_custom_theme", + "fieldname": "custom_theme_url", + "fieldtype": "Read Only", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -990,7 +1024,7 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "CSS File URL", + "label": "Custom Theme URL", "length": 0, "no_copy": 0, "permlevel": 0, @@ -1017,7 +1051,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2019-01-27 16:43:58.160802", + "modified": "2019-01-30 15:48:12.196916", "modified_by": "Administrator", "module": "Website", "name": "Website Theme", diff --git a/frappe/website/doctype/website_theme/website_theme.py b/frappe/website/doctype/website_theme/website_theme.py index e225328eb7..f0a29ff87c 100644 --- a/frappe/website/doctype/website_theme/website_theme.py +++ b/frappe/website/doctype/website_theme/website_theme.py @@ -41,9 +41,9 @@ class WebsiteTheme(Document): frappe.throw(_("Top Bar Color and Text Color are the same. They should be have good contrast to be readable.")) def validate_custom_bootstrap_theme(self): - if self.customize_bootstrap_4: + if self.apply_custom_theme and self.custom_theme: doc_before_save = self.get_doc_before_save() - if self.customize_bootstrap_4 != doc_before_save.customize_bootstrap_4: + if self.custom_theme != doc_before_save.custom_theme: self.generate_bootstrap_theme() def export_doc(self): @@ -59,13 +59,22 @@ class WebsiteTheme(Document): website_settings.clear_cache() def generate_bootstrap_theme(self): - from frappe.commands import popen + from subprocess import Popen, PIPE + file_name = frappe.scrub(self.name) + '.css' - content = self.customize_bootstrap_4 + content = self.custom_theme content = content.replace('\n', '\\n') command = ['node', 'generate_bootstrap_theme.js', file_name, content] - popen(command, cwd=frappe.get_app_path('frappe', '..'), shell=False) - self.css_file_url = '/assets/frappe/website_theme/' + file_name + + process = Popen(command, cwd=frappe.get_app_path('frappe', '..'), stdout=PIPE, stderr=PIPE) + stdout, stderr = process.communicate() + + if stderr: + frappe.throw('
{stderr}
'.format(stderr=stderr)) + else: + self.custom_theme_url = '/assets/frappe/website_theme/' + file_name + + frappe.msgprint(_('Compiled Successfully'), alert=True) def use_theme(self): use_theme(self.name) diff --git a/generate_bootstrap_theme.js b/generate_bootstrap_theme.js index e30a1e7944..af192b2990 100644 --- a/generate_bootstrap_theme.js +++ b/generate_bootstrap_theme.js @@ -7,6 +7,7 @@ const node_modules_path = path.resolve(get_public_path('frappe'), 'node_modules' const scss_path = path.resolve(get_public_path('frappe'), 'scss'); const website_theme_path = path.resolve(get_public_path('frappe'), 'website_theme'); const custom_theme_name = process.argv[2]; + let scss_content = process.argv[3]; scss_content = scss_content.replace(/\\n/g, '\n'); @@ -30,7 +31,7 @@ sass.render({ } }, function(err, result) { if (err) { - console.error(err) + console.error(err.formatted) return; }