[FIX] base: ir.qweb: fault tolerant save of assets.

Do not fail if an asset cannot be cached into the database.
This commit is contained in:
Christophe Simonis 2015-07-08 19:19:28 +02:00
parent 90e4aed135
commit 6e73a31146
1 changed files with 31 additions and 20 deletions

View File

@ -20,6 +20,7 @@ import babel.dates
import werkzeug
from lxml import etree, html
from PIL import Image
import psycopg2
import openerp.http
import openerp.tools
@ -1257,16 +1258,21 @@ class AssetsBundle(object):
ira = self.registry['ir.attachment']
url_prefix = '/web/%s/%s/' % (type, self.xmlid)
# Invalidate previous caches
oids = ira.search(self.cr, openerp.SUPERUSER_ID, [('url', '=like', url_prefix + '%')], context=self.context)
if oids:
ira.unlink(self.cr, openerp.SUPERUSER_ID, oids, context=self.context)
url = url_prefix + self.version
ira.create(self.cr, openerp.SUPERUSER_ID, dict(
try:
with self.cr.savepoint():
domain = [('url', '=like', url_prefix + '%')]
oids = ira.search(self.cr, openerp.SUPERUSER_ID, domain, context=self.context)
if oids:
ira.unlink(self.cr, openerp.SUPERUSER_ID, oids, context=self.context)
url = url_prefix + self.version
ira.create(self.cr, openerp.SUPERUSER_ID, dict(
datas=content.encode('utf8').encode('base64'),
type='binary',
name=url,
url=url,
), context=self.context)
except psycopg2.Error:
pass
def css_message(self, message):
return """
@ -1504,21 +1510,26 @@ class SassAsset(StylesheetAsset):
def to_html(self):
if self.url:
ira = self.registry['ir.attachment']
url = self.html_url % self.url
domain = [('type', '=', 'binary'), ('url', '=', self.url)]
ira_id = ira.search(self.cr, openerp.SUPERUSER_ID, domain, context=self.context)
if ira_id:
# TODO: update only if needed
ira.write(self.cr, openerp.SUPERUSER_ID, [ira_id], {'datas': self.content}, context=self.context)
else:
ira.create(self.cr, openerp.SUPERUSER_ID, dict(
datas=self.content.encode('utf8').encode('base64'),
mimetype='text/css',
type='binary',
name=url,
url=url,
), context=self.context)
try:
ira = self.registry['ir.attachment']
url = self.html_url % self.url
domain = [('type', '=', 'binary'), ('url', '=', self.url)]
with self.cr.savepoint():
ira_id = ira.search(self.cr, openerp.SUPERUSER_ID, domain, context=self.context)
if ira_id:
# TODO: update only if needed
ira.write(self.cr, openerp.SUPERUSER_ID, [ira_id], {'datas': self.content},
context=self.context)
else:
ira.create(self.cr, openerp.SUPERUSER_ID, dict(
datas=self.content.encode('utf8').encode('base64'),
mimetype='text/css',
type='binary',
name=url,
url=url,
), context=self.context)
except psycopg2.Error:
pass
return super(SassAsset, self).to_html()
def get_source(self):