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