From 152f9ca0fc9f002fca533fe059a93b27918624f4 Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Thu, 1 Oct 2015 16:27:55 +0200 Subject: [PATCH] [REF] ir_qweb: clean_attachments * use format to avoid escaping the % * add a docstring to explain what's going on --- openerp/addons/base/ir/ir_qweb.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/openerp/addons/base/ir/ir_qweb.py b/openerp/addons/base/ir/ir_qweb.py index a0e99c96c3b..44e063bce05 100644 --- a/openerp/addons/base/ir/ir_qweb.py +++ b/openerp/addons/base/ir/ir_qweb.py @@ -1209,8 +1209,18 @@ class AssetsBundle(object): return hashlib.sha1(check).hexdigest() def clean_attachments(self, type): + """ Takes care of deleting any outdated ir.attachment records associated to a bundle before + saving a fresh one. + + When `type` is css we need to check that we are deleting a different version (and not *any* + version) because css may be paginated and, therefore, may produce multiple attachments for + the same bundle's version. + """ ira = self.registry['ir.attachment'] - domain = ['&', '!', ('url', '=like', '/web/content/%%-%s/%%' % self.version), ('url', '=like', '/web/content/%%-%%/%s%%.%s' % (self.xmlid, type))] + domain = [ + ('url', '=like', '/web/content/%-%/{0}%.{1}'.format(self.xmlid, type)), # The wilcards are id, version and pagination number (if any) + '!', ('url', '=like', '/web/content/%-{}/%'.format(self.version)) + ] attachment_ids = ira.search(self.cr, openerp.SUPERUSER_ID, domain, context=self.context) return ira.unlink(self.cr, openerp.SUPERUSER_ID, attachment_ids, context=self.context)