You are here: Home / Documentation / How To's / How to have automatic file download

How to have automatic file download

by hietpasd published Jan 11, 2012 11:26 AM, last modified Aug 16, 2016 10:50 AM
How to let files automatically download for non-editors and visitors.

This how to will show a very simple setup to allow files to be downloaded without visiting the File page.  This is similar to how Links work, links will go directly to the link address for all non-editors.  This easy setup will do the same, it will download the file directly.

  1. Go to ZMI > portal_skins > Custom
  2. Add a new Script (Python) file called file_redirection without the quotes.
  3. Paste the script below.
  4. Go to ZMI > portal_types > File
  5. Add file_redirection to the Available View Methods
  6. Change the Default View Method to file_redirection
## Script (Python) "file_redirection"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
"""
Will open file automatically for non-editors.
"""
request = context.REQUEST
response = request.response

from Products.CMFCore.utils import getToolByName

properties = getToolByName(context, 'portal_properties')
membership = getToolByName(context, 'portal_membership')

download = properties.site_properties.getProperty('redirect_links', False)
can_modify = membership.checkPermission('Modify portal content', context)

if download and not can_modify:
    return response.redirect(context.absolute_url())
else:
    return context.file_view()

 Optional Extra:

  1. To split the redirection on/off from the Links Type, add a new property to the sites_properties file and make the change in this file on the properties.site_properties.getProperty('redirect_links',False) to get your property.

 

Navigation