mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-26 10:28:40 -06:00
[FIX] fix bugs and add logging
This commit is contained in:
parent
6b74ea45e1
commit
e49b7fb71b
@ -18,12 +18,16 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
import collections
|
|
||||||
import os.path
|
|
||||||
import mimetypes
|
|
||||||
import base64
|
import base64
|
||||||
|
import collections
|
||||||
|
import logging
|
||||||
|
import mimetypes
|
||||||
|
import os.path
|
||||||
|
|
||||||
from openerp.osv.orm import Model
|
from openerp.osv.orm import Model
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class IrAttachment(Model):
|
class IrAttachment(Model):
|
||||||
_inherit = 'ir.attachment'
|
_inherit = 'ir.attachment'
|
||||||
@ -50,6 +54,8 @@ class IrAttachment(Model):
|
|||||||
this[filename_field])
|
this[filename_field])
|
||||||
if this[binary_field] and extension:
|
if this[binary_field] and extension:
|
||||||
result[this.id] = extension
|
result[this.id] = extension
|
||||||
|
_logger.debug('Got extension %s from filename %s',
|
||||||
|
extension, this[filename_field])
|
||||||
# Second pass for all attachments which have to be loaded fully
|
# Second pass for all attachments which have to be loaded fully
|
||||||
# to get the extension from the content
|
# to get the extension from the content
|
||||||
ids_to_browse = [_id for _id in ids_to_browse if _id not in result]
|
ids_to_browse = [_id for _id in ids_to_browse if _id not in result]
|
||||||
@ -64,18 +70,24 @@ class IrAttachment(Model):
|
|||||||
if model == self._name and binary_field == 'datas'\
|
if model == self._name and binary_field == 'datas'\
|
||||||
and this.store_fname:
|
and this.store_fname:
|
||||||
mimetype = ms.file(
|
mimetype = ms.file(
|
||||||
this._full_path(cr, uid, this.store_fname))
|
this._full_path(this.store_fname))
|
||||||
|
_logger.debug('Magic determined mimetype %s from file %s',
|
||||||
|
mimetype, this.store_fname)
|
||||||
else:
|
else:
|
||||||
mimetype = ms.buffer(
|
mimetype = ms.buffer(
|
||||||
base64.b64decode(this[binary_field]))
|
base64.b64decode(this[binary_field]))
|
||||||
|
_logger.debug('Magic determined mimetype %s from buffer',
|
||||||
|
mimetype)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
(mimetype, encoding) = mimetypes.guess_type(
|
(mimetype, encoding) = mimetypes.guess_type(
|
||||||
'data:;base64,' + this[binary_field], strict=False)
|
'data:;base64,' + this[binary_field], strict=False)
|
||||||
|
_logger.debug('Mimetypes guessed type %s from buffer',
|
||||||
|
mimetype)
|
||||||
extension = mimetypes.guess_extension(
|
extension = mimetypes.guess_extension(
|
||||||
mimetype.split(';')[0], strict=False)
|
mimetype.split(';')[0], strict=False)
|
||||||
result[this.id] = extension
|
result[this.id] = extension
|
||||||
for _id in result:
|
for _id in result:
|
||||||
result[_id] = (extension or '').lstrip('.').lower()
|
result[_id] = (result[_id] or '').lstrip('.').lower()
|
||||||
return result if isinstance(ids, collections.Iterable) else result[ids]
|
return result if isinstance(ids, collections.Iterable) else result[ids]
|
||||||
|
|
||||||
def get_attachment_extension(self, cr, uid, ids, context=None):
|
def get_attachment_extension(self, cr, uid, ids, context=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user