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.
This commit is contained in:
Faris Ansari 2020-06-24 11:03:10 +05:30
parent 71d25dece1
commit a6eae56658
2 changed files with 6 additions and 14 deletions

View file

@ -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'
]

View file

@ -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', '<br>')
frappe.throw('<div style="font-family: monospace;">{stderr}</div>'.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())