Commit 090d24ba authored by Georgios Dagkakis's avatar Georgios Dagkakis

BusinessTemplate: In guessExtensionOfDocument allow

to use content_type or reference even if the object is broken.
parent 923bd362
...@@ -765,12 +765,17 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -765,12 +765,17 @@ class ObjectTemplateItem(BaseTemplateItem):
- '.bin' is returned for binary files - '.bin' is returned for binary files
- '.txt' is returned for text - '.txt' is returned for text
""" """
# Try to guess the extension based on the content_type of the document
# XXX Zope items like DTMLMethod would not # XXX Zope items like DTMLMethod would not
# implement getContentType method # implement getContentType method
extension = None extension = None
binary = 'not_identified' binary = 'not_identified'
content_type = None
if hasattr(document, 'getContentType'): if hasattr(document, 'getContentType'):
content_type = document.getContentType() content_type = document.getContentType()
elif isinstance(document, ERP5BaseBroken):
content_type = getattr(document, "content_type", None)
if content_type:
lookup_result = self.getMimetypesRegistryLookupResultOfContenType(content_type) lookup_result = self.getMimetypesRegistryLookupResultOfContenType(content_type)
if lookup_result: if lookup_result:
# return first registered Extension (if any) # return first registered Extension (if any)
...@@ -793,15 +798,19 @@ class ObjectTemplateItem(BaseTemplateItem): ...@@ -793,15 +798,19 @@ class ObjectTemplateItem(BaseTemplateItem):
return extension return extension
# Try to guess the extension based on the reference of the document # Try to guess the extension based on the reference of the document
mime = MimeTypes() mime = MimeTypes()
reference = None
if hasattr(document, 'getReference'): if hasattr(document, 'getReference'):
reference = document.getReference() reference = document.getReference()
if reference: elif isinstance(document, ERP5BaseBroken):
mime_type = mime.guess_type(reference) reference = getattr(document, "reference", None)
if mime_type[0]: if reference:
extension = guess_extension(mime_type[0]) mime_type = mime.guess_type(reference)
return extension if mime_type[0]:
extension = guess_extension(mime_type[0])
return extension
# Try to guess the extension based on the title of the document # Try to guess the extension based on the title of the document
if hasattr(document, 'title'): title = getattr(document, "title", None)
if title:
mime_type = mime.guess_type(document.title) mime_type = mime.guess_type(document.title)
if mime_type[0]: if mime_type[0]:
extension = guess_extension(mime_type[0]) extension = guess_extension(mime_type[0])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment