[FIX] website: robust attribute checking

When installing website or one of its dependencies directly, the website
attribute is not defined on request. If the installation triggers qweb
rendering [1], we need to correctly check the presence of the website
attribute, which this commit does.

[1]: This is the case in website_blog since
4a132e2afb
This commit is contained in:
Julien Legros
2016-05-26 16:44:01 +02:00
parent a93b6e8de0
commit 9bd223f50d
+3 -3
View File
@@ -31,18 +31,18 @@ class QWeb(orm.AbstractModel):
if not context.get('rendering_bundle'):
if name == self.URL_ATTRS.get(element.tag) and qwebcontext.get('url_for'):
value = qwebcontext.get('url_for')(value)
elif request and request.website and request.website.cdn_activated and (name == self.URL_ATTRS.get(element.tag) or name == self.CDN_TRIGGERS.get(element.tag)):
elif request and getattr(request, 'website', None) and request.website.cdn_activated and (name == self.URL_ATTRS.get(element.tag) or name == self.CDN_TRIGGERS.get(element.tag)):
value = request.website.get_cdn_url(value)
return super(QWeb, self).render_attribute(element, name, value, qwebcontext)
def render_text(self, text, element, qwebcontext):
compress = request and not request.debug and request.website and request.website.compress_html
compress = request and not request.debug and getattr(request, 'website', None) and request.website.compress_html
if compress and element.tag not in self.PRESERVE_WHITESPACE:
text = self.re_remove_spaces.sub(' ', text)
return super(QWeb, self).render_text(text, element, qwebcontext)
def render_tail(self, tail, element, qwebcontext):
compress = request and not request.debug and request.website and request.website.compress_html
compress = request and not request.debug and getattr(request, 'website', None) and request.website.compress_html
if compress and element.getparent().tag not in self.PRESERVE_WHITESPACE:
# No need to recurse because those tags children are not html5 parser friendly
tail = self.re_remove_spaces.sub(' ', tail.rstrip())