Extract a file like object's file name as per docs (using the .name property) and not an unicode representation of the file object instance. Reference: https://docs.python.org/2.7/library/stdtypes.html#file-objects

This commit is contained in:
Roberto Rosario
2016-03-30 01:32:53 -04:00
parent 8b28bdd443
commit c6890c487a
2 changed files with 4 additions and 4 deletions

View File

@@ -127,7 +127,7 @@ class DocumentType(models.Model):
with transaction.atomic():
document = self.documents.create(
description=description or '',
label=label or unicode(file_object),
label=label or file_object.name,
language=language or setting_language.value
)
document.save(_user=_user)
@@ -138,7 +138,7 @@ class DocumentType(models.Model):
logger.critical(
'Unexpected exception while trying to create new document '
'"%s" from document type "%s"; %s',
label or unicode(file_object), self, exception
label or file_object.name, self, exception
)
raise

View File

@@ -65,7 +65,7 @@ class Source(models.Model):
with transaction.atomic():
document = Document.objects.create(
description=description or '', document_type=document_type,
label=label or unicode(file_object),
label=label or file_object.name,
language=language or setting_language.value
)
document.save(_user=user)
@@ -100,7 +100,7 @@ class Source(models.Model):
logger.critical(
'Unexpected exception while trying to create new document '
'"%s" from source "%s"; %s',
label or unicode(file_object), self, exception
label or file_object.name, self, exception
)
raise