Server IP : 127.0.0.2 / Your IP : 3.21.35.68 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /opt/odoo/addons/website/models/ |
Upload File : |
# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. import ast from odoo import models from odoo.http import request class QWeb(models.AbstractModel): """ QWeb object for rendering stuff in the website context """ _inherit = 'ir.qweb' URL_ATTRS = { 'form': 'action', 'a': 'href', } CDN_TRIGGERS = { 'link': 'href', 'script': 'src', 'img': 'src', } def _get_asset(self, xmlid, options, css=True, js=True, debug=False, async=False, values=None): website = getattr(request, 'website', None) if request else None if website and website.cdn_activated: values = dict(values, url_for=website.get_cdn_url) return super(QWeb, self)._get_asset(xmlid, options, css, js, debug, async, values) def _website_build_attribute(self, tagName, name, value, options, values): """ Compute the value of an attribute while rendering the template. """ if name == self.URL_ATTRS.get(tagName) and values.get('url_for'): return values.get('url_for')(value or '') elif request and getattr(request, 'website', None) and request.website.cdn_activated and (name == self.URL_ATTRS.get(tagName) or name == self.CDN_TRIGGERS.get(tagName)): return request.website.get_cdn_url(value or '') return value def _wrap_build_attributes(self, el, items, options): """ Map items corresponding to URL and CDN attributes to an ast expression. """ if options.get('rendering_bundle'): return items url_att = self.URL_ATTRS.get(el.tag) cdn_att = self.CDN_TRIGGERS.get(el.tag) def process(item): if isinstance(item, tuple) and (item[0] in (url_att, cdn_att)): return (item[0], ast.Call( func=ast.Attribute( value=ast.Name(id='self', ctx=ast.Load()), attr='_website_build_attribute', ctx=ast.Load() ), args=[ ast.Str(el.tag), ast.Str(item[0]), item[1], ast.Name(id='options', ctx=ast.Load()), ast.Name(id='values', ctx=ast.Load()), ], keywords=[], starargs=None, kwargs=None )) else: return item return map(process, items) def _compile_static_attributes(self, el, options): items = super(QWeb, self)._compile_static_attributes(el, options) return self._wrap_build_attributes(el, items, options) def _compile_dynamic_attributes(self, el, options): items = super(QWeb, self)._compile_dynamic_attributes(el, options) return self._wrap_build_attributes(el, items, options) # method called by computing code def _get_dynamic_att(self, tagName, atts, options, values): atts = super(QWeb, self)._get_dynamic_att(tagName, atts, options, values) if options.get('rendering_bundle'): return atts for name, value in atts.iteritems(): atts[name] = self._website_build_attribute(tagName, name, value, options, values) return atts def _is_static_node(self, el): url_att = self.URL_ATTRS.get(el.tag) cdn_att = self.CDN_TRIGGERS.get(el.tag) return super(QWeb, self)._is_static_node(el) and \ (not url_att or not el.get(url_att)) and \ (not cdn_att or not el.get(cdn_att))