[ADD] support old CentOS' magic module

[FIX] handle empty binary fields correctly
This commit is contained in:
Holger Brunn 2014-09-18 12:04:29 +02:00
parent 259914a27c
commit ddb47661fb

View File

@ -42,10 +42,15 @@ class IrAttachment(Model):
extension = '' extension = ''
if filename_field and this[filename_field]: if filename_field and this[filename_field]:
filename, extension = os.path.splitext(this[filename_field]) filename, extension = os.path.splitext(this[filename_field])
if not this[binary_field]:
result[this.id] = False
continue
if not extension: if not extension:
try: try:
import magic import magic
ms = magic.open(magic.MAGIC_MIME_TYPE) ms = magic.open(
hasattr(magic, 'MAGIC_MIME_TYPE')
and magic.MAGIC_MIME_TYPE or magic.MAGIC_MIME)
ms.load() ms.load()
mimetype = ms.buffer( mimetype = ms.buffer(
base64.b64decode(this[binary_field])) base64.b64decode(this[binary_field]))