From a6eae56658ee0922086d0c73073354c34205e8fd Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Wed, 24 Jun 2020 11:03:10 +0530 Subject: [PATCH] fix: Create website theme file in public folder Earlier theme files were generated in assets folder, so if a site was moved to a different bench, theme files were not moved with the site. Now, they will be generated in /public/files/website_theme folder so they move along with the site. --- frappe/hooks.py | 1 - .../doctype/website_theme/website_theme.py | 19 ++++++------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/frappe/hooks.py b/frappe/hooks.py index f5a8701089..c207e61de5 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -273,7 +273,6 @@ setup_wizard_exception = [ before_migrate = ['frappe.patches.v11_0.sync_user_permission_doctype_before_migrate.execute'] after_migrate = [ - 'frappe.website.doctype.website_theme.website_theme.generate_theme_files_if_not_exist', 'frappe.modules.full_text_search.build_index_for_all_routes' ] diff --git a/frappe/website/doctype/website_theme/website_theme.py b/frappe/website/doctype/website_theme/website_theme.py index da6d26c2e0..c2c4a6e2c8 100644 --- a/frappe/website/doctype/website_theme/website_theme.py +++ b/frappe/website/doctype/website_theme/website_theme.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe from frappe import _ from frappe.model.document import Document -from os.path import join as join_path, exists as path_exists +from os.path import join as join_path, exists as path_exists, abspath class WebsiteTheme(Document): def validate(self): @@ -60,7 +60,10 @@ class WebsiteTheme(Document): def generate_bootstrap_theme(self): from subprocess import Popen, PIPE - folder_path = join_path(frappe.utils.get_bench_path(), 'sites', 'assets', 'css') + # create theme file in site public files folder + folder_path = abspath(frappe.utils.get_files_path('website_theme', is_private=False)) + # create folder if not exist + frappe.create_folder(folder_path) if not self.custom: self.delete_old_theme_files(folder_path) @@ -83,7 +86,7 @@ class WebsiteTheme(Document): stderr = stderr.replace('\n', '
') frappe.throw('
{stderr}
'.format(stderr=stderr)) else: - self.theme_url = '/assets/css/' + file_name + self.theme_url = '/files/website_theme/' + file_name frappe.msgprint(_('Compiled Successfully'), alert=True) @@ -123,16 +126,6 @@ def get_active_theme(): except frappe.DoesNotExistError: pass -def generate_theme_files_if_not_exist(): - print('Generating Website Theme Files...') - themes = frappe.get_all('Website Theme') - for theme in themes: - doc = frappe.get_doc('Website Theme', theme.name) - try: - doc.generate_theme_if_not_exist() - doc.save() - except Exception: - frappe.log_error(frappe.get_traceback(), "Theme File Generation Failed") def get_scss(doc): return frappe.render_template('frappe/website/doctype/website_theme/website_theme_template.scss', doc.as_dict())