diff options
| author | Parth Gajjar (Open ERP) <pga@tinyerp.com> | 2014-03-28 18:48:22 +0530 |
|---|---|---|
| committer | Parth Gajjar (Open ERP) <pga@tinyerp.com> | 2014-03-28 18:48:22 +0530 |
| commit | 3de6738dbbfeb5f5dda0eae434e3ccef62aa4e8e (patch) | |
| tree | 7dfdb25e57640ffdc5d12169b372bf51318dc04b /addons/website/models/website.py | |
| parent | 1ccbc213e7f39c1902d70714d0e75418155dab6d (diff) | |
| parent | a224b88d80bc5311a684a6ae59e8584a2eec9150 (diff) | |
merged with trunk addons
bzr revid: pga@tinyerp.com-20140328131822-0kc0f5j5qhupkhbr
Diffstat (limited to 'addons/website/models/website.py')
| -rw-r--r-- | addons/website/models/website.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 15e1a643d3d..a516f5cb96f 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -4,6 +4,7 @@ import inspect import itertools import logging import math +import mimetypes import re import urlparse @@ -553,7 +554,7 @@ class ir_attachment(osv.osv): def _website_url_get(self, cr, uid, ids, name, arg, context=None): result = {} for attach in self.browse(cr, uid, ids, context=context): - if attach.type == 'url': + if attach.url: result[attach.id] = attach.url else: result[attach.id] = urlplus('/website/image', { @@ -574,7 +575,7 @@ class ir_attachment(osv.osv): def _compute_checksum(self, attachment_dict): if attachment_dict.get('res_model') == 'ir.ui.view'\ - and not attachment_dict.get('res_id')\ + and not attachment_dict.get('res_id') and not attachment_dict.get('url')\ and attachment_dict.get('type', 'binary') == 'binary'\ and attachment_dict.get('datas'): return hashlib.new('sha1', attachment_dict['datas']).hexdigest() @@ -600,17 +601,27 @@ class ir_attachment(osv.osv): 'website_url': fields.function(_website_url_get, string="Attachment URL", type='char'), 'datas_big': fields.function (_datas_big, type='binary', store=True, string="Resized file content"), + 'mimetype': fields.char('Mime Type', readonly=True), } + def _add_mimetype_if_needed(self, values): + if values.get('datas_fname'): + values['mimetype'] = mimetypes.guess_type(values.get('datas_fname'))[0] or 'application/octet-stream' + def create(self, cr, uid, values, context=None): chk = self._compute_checksum(values) if chk: match = self.search(cr, uid, [('datas_checksum', '=', chk)], context=context) if match: return match[0] + self._add_mimetype_if_needed(values) return super(ir_attachment, self).create( cr, uid, values, context=context) + def write(self, cr, uid, ids, values, context=None): + self._add_mimetype_if_needed(values) + return super(ir_attachment, self).write(cr, uid, ids, values, context=context) + def try_remove(self, cr, uid, ids, context=None): """ Removes a web-based image attachment if it is used by no view (template) |
