[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:
parent
90e4aed135
commit
6e73a31146
|
@ -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,7 +1258,10 @@ 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)
|
||||
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
|
||||
|
@ -1267,6 +1271,8 @@ class AssetsBundle(object):
|
|||
name=url,
|
||||
url=url,
|
||||
), context=self.context)
|
||||
except psycopg2.Error:
|
||||
pass
|
||||
|
||||
def css_message(self, message):
|
||||
return """
|
||||
|
@ -1504,13 +1510,16 @@ class SassAsset(StylesheetAsset):
|
|||
|
||||
def to_html(self):
|
||||
if self.url:
|
||||
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)
|
||||
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'),
|
||||
|
@ -1519,6 +1528,8 @@ class SassAsset(StylesheetAsset):
|
|||
name=url,
|
||||
url=url,
|
||||
), context=self.context)
|
||||
except psycopg2.Error:
|
||||
pass
|
||||
return super(SassAsset, self).to_html()
|
||||
|
||||
def get_source(self):
|
||||
|
|
Loading…
Reference in New Issue