Files
odoo_source/addons/website/controllers/web_editor.py
T
Andrea Ulliana 515e7bc50f [IMP] website, *: improve CSS edition usability + add JS edition
* web_editor

Currently, when an user wants to edit the css of its website, he has
access to lots of files and, in debug mode, to even more files. While
the feature is nice for people who know what they are doing, a lambda
person can easily break its website by changing the wrong files. Also,
nothing warns the user that the files that are edited will never receive
updates anymore (unless if they are reset). The goal is to prevent
those behavior while still allowing the add custom css. Another goal
is to be able to *add* custom javascript.

Custom files created for the user:
SCSS: user_custom_rules.scss, user_custom_bootstrap_overridden.scss
JS: user_custom_javascript.js

See https://github.com/odoo/odoo/pull/29999
task-1919350
2019-02-05 14:28:29 +00:00

39 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.web_editor.controllers.main import Web_Editor
from odoo.http import request
class Web_Editor(Web_Editor):
def _get_view_fields_to_read(self):
res = super(Web_Editor, self)._get_view_fields_to_read()
res.append('website_id')
return res
def save_scss_or_js_view_hook(self):
res = super(Web_Editor, self).save_scss_or_js_view_hook()
website = request.env['website'].get_current_website()
if website:
res['website_id'] = website.id
return res
def save_scss_or_js_attachment_hook(self):
res = super(Web_Editor, self).save_scss_or_js_attachment_hook()
website = request.env['website'].get_current_website()
if website:
res['website_id'] = website.id
return res
def get_custom_attachment(self, custom_url, op='='):
website = request.env['website'].get_current_website()
res = super(Web_Editor, self).get_custom_attachment(custom_url, op=op)
return res.with_context(website_id=website.id).filtered(lambda x: not x.website_id or x.website_id == website)
def get_custom_view(self, custom_url, op='='):
website = request.env['website'].get_current_website()
res = super(Web_Editor, self).get_custom_view(custom_url, op=op)
return res.with_context(website_id=website.id).filter_duplicate()