You are here: Home Plone My Python Scripts Script that returns a random picture from a folder
Search
Advanced Search…
E-Mail

Webmail: webmail.wyden.com

E-Mail Preferences: postfix.wyden.com/users

E-Mail Administration: postfix.wyden.com

Statistics
Total: 463
Total Pages: 284
Total Folders: 87
Total Files: 18
Total Links: 26
Last modification: 03.02.2012 16:00
 

Script that returns a random picture from a folder

by Wyden Silvan last modified 26.11.2009 12:04

#getRandom
from Products.CMFCore.utils import getToolByName
import random

# folder containing backgrounds to choose from, relative to portal_skins
#background_folder = 'custom/banners/' + context.portal_languages.getPreferredLanguage()
background_folder = 'custom/kinder'

response = context.REQUEST.RESPONSE

url_tool = getToolByName(context, 'portal_url')

backgrounds_folder = context.restrictedTraverse('%s/portal_skins/%s' % ( url_tool.getPortalPath(), background_folder ))

obj = random.choice(backgrounds_folder.objectValues('Image'))

response.setHeader('Cache-Control','no-store, no-cache, must-revalidate, post-check=0, pre-check=0')
response.setHeader('Pragma','no-cache')

return obj