Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
5.9.1 (unreleased)
------------------

- Customize @download view to allow downloading miniature images with their original filename and not with miniature as filename.
[cekk]
- fix file:/// as external link in summary
[mamico]

Expand Down
8 changes: 8 additions & 0 deletions src/redturtle/volto/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@
layer="redturtle.volto.interfaces.IRedturtleVoltoLayer"
/>

<!-- override @@download view -->
<browser:page
name="download"
for="*"
class=".download.Download"
permission="zope2.View"
layer="redturtle.volto.interfaces.IRedturtleVoltoLayer"
/>
<browser:page
name="document_view"
template="templates/document.pt"
Expand Down
34 changes: 34 additions & 0 deletions src/redturtle/volto/browser/download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from plone import api
from plone.namedfile.browser import Download as BaseDownload
from plone.namedfile.utils import set_headers


class Download(BaseDownload):
"""
Customization to allow downloading miniature images with their original
filename and not with miniature as filename.
"""

def set_headers(self, file):
"""
in self.filename we have the miniature name
"""
filename = getattr(file, "filename", None)
if self.filename:
# we are downloading a miniature
filename = f"{self.filename}_{filename}"
set_headers(file, self.request.response, filename=filename)

def _getFile(self):
"""
in self.filename we have the miniature name
"""
if self.filename:
# we are downloading a miniature
view = api.content.get_view(
name="images", context=self.context, request=self.request
)
scale = view.scale(scale=self.filename, fieldname=self.fieldname)
if scale:
return scale.data
return super()._getFile()