r252536 - in collective.randomheaderimage/branches/random_image_per_section: . collective/randomheaderimage/browser collective/randomheaderimage/profiles/default docs
"Luca Bellenghi" <svn-changes-z4DKO/[email protected]> Tue, 10 Sep 2013 09:51:32 +0000 (UTC)
| Newsgroups | gmane.comp.web.zope.plone.collective.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: lucabel
Date: Tue Sep 10 09:51:32 2013
New Revision: 252536
Modified:
collective.randomheaderimage/branches/random_image_per_section/README.txt
collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/browser/random_image.py
collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/profiles/default/propertiestool.xml
collective.randomheaderimage/branches/random_image_per_section/docs/HISTORY.txt
collective.randomheaderimage/branches/random_image_per_section/setup.py
Log:
change way to select image source; now can specify more than one folder and show different header images per section
Modified: collective.randomheaderimage/branches/random_image_per_section/README.txt
==============================================================================
--- collective.randomheaderimage/branches/random_image_per_section/README.txt (original)
+++ collective.randomheaderimage/branches/random_image_per_section/README.txt Tue Sep 10 09:51:32 2013
@@ -3,7 +3,7 @@
The main idea is to have a random image as background of header of the Plone Site.
-The image has loaded from a Plone folder.
+The image has loaded from a Plone folder.
This folder is configurable trough ZMI and it's applied to the portal_header as css style.
Configuration
@@ -12,6 +12,10 @@
From ZMI you need to customize the *folder_header_images_path* property inside the *site_properties*
property sheet.
+In starting from version 0.2.0 the properties it's a line field and you can set
+values like /site/folder1|/site/folder1/image_source_folder1, one per line.
+In this way people can specify different source folder for different site section
+
Authors
=======
@@ -20,4 +24,4 @@
.. image:: http://www.redturtle.it/redturtle_banner.png
:alt: RedTurtle Technology Site
:target: http://www.redturtle.it/
-
\ No newline at end of file
+
Modified: collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/browser/random_image.py
==============================================================================
--- collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/browser/random_image.py (original)
+++ collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/browser/random_image.py Tue Sep 10 09:51:32 2013
@@ -5,29 +5,72 @@
from zope.component import getMultiAdapter
import random
+
class RandomImage(BrowserView):
"""Get Daily image"""
-
+
+ def get_mapping(self, images_folder_path):
+ return dict([(x.split('|')[0], x.split('|')[1])
+ for x in images_folder_path])
+
+ def get_folder_path(self, candidates):
+ l = 0
+ selected = ''
+ for candidate in candidates:
+ newl = len(candidate.split('/'))
+ if newl > l:
+ l = newl
+ selected = candidate
+ return selected
+
def getRandomImage(self):
"""
get the random image from a folder
"""
- pprop = getToolByName(self.context,'portal_properties')
+ pprop = getToolByName(self.context, 'portal_properties')
if pprop.site_properties.hasProperty('folder_header_images_path'):
- images_folder_path = pprop.site_properties.getProperty('folder_header_images_path')
+ props = pprop.site_properties
+ images_folder_path = props.getProperty('folder_header_images_path')
else:
return ""
+
if not images_folder_path:
return ""
- root=self.context.portal_url.getPortalObject()
- image_folder=root.unrestrictedTraverse(images_folder_path,None)
+ root = self.context.portal_url.getPortalObject()
+ if isinstance(images_folder_path, basestring):
+ """
+ I leave this here just for backward compatibility
+ """
+ image_folder = root.unrestrictedTraverse(images_folder_path, None)
+ elif isinstance(images_folder_path, tuple):
+ mapping = self.get_mapping(images_folder_path)
+ pcs = getMultiAdapter((self.context, self.request),
+ name='plone_context_state')
+ cpath = '/'.join(pcs.canonical_object().getPhysicalPath())
+
+ #Now we need to find the longest key in mapping dictionary
+ candidates = []
+ for key in mapping:
+ if cpath.startswith(key):
+ candidates.append(key)
+ if not candidates:
+ return ""
+ folder_path = mapping[self.get_folder_path(candidates)]
+ print "source is %s" % folder_path
+ image_folder = root.unrestrictedTraverse(folder_path, None)
+ else:
+ return ""
+
if not image_folder:
return ""
- pc=getToolByName(self.context,'portal_catalog')
- images=pc(path='/'.join(image_folder.getPhysicalPath()),
- portal_type="Image",
- sort_on="getObjPositionInParent")
+
+ pc = getToolByName(self.context, 'portal_catalog')
+ images = pc(path='/'.join(image_folder.getPhysicalPath()),
+ portal_type="Image",
+ sort_on="getObjPositionInParent")
+
if not images:
return ""
- rnd = random.randint(0, len(images)-1)
- return 'background:url("%s") no-repeat 0 0 ; }' %images[rnd].getURL()
+
+ rnd = random.randint(0, len(images) - 1)
+ return 'background:url("%s") no-repeat 0 0 ; }' % images[rnd].getURL()
Modified: collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/profiles/default/propertiestool.xml
==============================================================================
--- collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/profiles/default/propertiestool.xml (original)
+++ collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/profiles/default/propertiestool.xml Tue Sep 10 09:51:32 2013
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<object name="portal_properties">
- <object name="site_properties" meta_type="Plone Property Sheet">
- <property name="folder_header_images_path" type="string" purge="False" />
- </object>
+ <object name="site_properties" meta_type="Plone Property Sheet">
+ <property name="folder_header_images_path" type="lines" purge="False" />
+ </object>
</object>
Modified: collective.randomheaderimage/branches/random_image_per_section/docs/HISTORY.txt
==============================================================================
--- collective.randomheaderimage/branches/random_image_per_section/docs/HISTORY.txt (original)
+++ collective.randomheaderimage/branches/random_image_per_section/docs/HISTORY.txt Tue Sep 10 09:51:32 2013
@@ -1,6 +1,12 @@
Changelog
=========
+0.2.0 (unreleased)
+------------------
+- change properties to use a list instead of a single text line; in this
+ way we can set here more than one single path
+
+
0.1.0 (2012-01-19)
------------------
Modified: collective.randomheaderimage/branches/random_image_per_section/setup.py
==============================================================================
--- collective.randomheaderimage/branches/random_image_per_section/setup.py (original)
+++ collective.randomheaderimage/branches/random_image_per_section/setup.py Tue Sep 10 09:51:32 2013
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os
-version = '0.1.0'
+version = '0.2.0'
setup(name='collective.randomheaderimage',
version=version,
------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. Consolidate legacy IT systems to a single system of record for IT
2. Standardize and globalize service processes across IT
3. Implement zero-touch automation to replace manual, redundant tasks
http://pubads.g.doubleclick.net/gampad/clk?id=51271111&iu=/4140/ostg.clktrk