r252541 - in collective.randomheaderimage/branches/random_image_per_section: . collective/randomheaderimage/browser collective/randomheaderimage/profiles/default docs

"Luca Bellenghi" <svn-changes-z4DKO/[email protected]> Fri, 13 Sep 2013 14:47:14 +0000 (UTC)
Newsgroups gmane.comp.web.zope.plone.collective.cvs
Message-ID <[email protected]>
Author: lucabel
Date: Fri Sep 13 14:47:14 2013
New Revision: 252541

Added:
   collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/browser/logo.pt
   collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/browser/logo.py
Modified:
   collective.randomheaderimage/branches/random_image_per_section/README.txt
   collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/browser/configure.zcml
   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:
version 0.3.0; also logo is customizable 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	Fri Sep 13 14:47:14 2013
@@ -12,10 +12,14 @@
 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
+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
 
+There is also section_logo_image_paths lines property. As described above user
+can specify path for site logo and show different site logo in different site
+section
+
 Authors
 =======
 

Modified: collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/browser/configure.zcml
==============================================================================
--- collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/browser/configure.zcml	(original)
+++ collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/browser/configure.zcml	Fri Sep 13 14:47:14 2013
@@ -3,24 +3,31 @@
     xmlns:browser="http://namespaces.zope.org/browser"
     i18n_domain="collective.randomheaderimage">
 
- 
-		
   <!--VISTA E VIEWLET PER LE IMMAGINI DEL GIORNO-->
   <browser:page
       for="*"
       class=".random_image.RandomImage"
       name="randomimage"
       permission="zope.Public"
-	  allowed_attributes="getRandomImage"
-      />     
-      
+      allowed_attributes="getRandomImage"
+      />
+
   <browser:viewlet
         name="plone.header"
         manager="plone.app.layout.viewlets.interfaces.IPortalTop"
         template="portal_header.pt"
-		layer=".interfaces.IRandomHeaderImageLayer"
+        layer=".interfaces.IRandomHeaderImageLayer"
+        permission="zope2.View"
+        />
+
+  <browser:viewlet
+        name="plone.logo"
+        manager="plone.app.layout.viewlets.interfaces.IPortalHeader"
+        class=".logo.LogoViewlet"
+        template="logo.pt"
+        layer=".interfaces.IRandomHeaderImageLayer"
         permission="zope2.View"
         />
 
-	
+
 </configure>

Added: collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/browser/logo.pt
==============================================================================
--- (empty file)
+++ collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/browser/logo.pt	Fri Sep 13 14:47:14 2013
@@ -0,0 +1,9 @@
+<a id="portal-logo"
+   title="Home"
+   accesskey="1"
+   tal:attributes="href view/navigation_root_url;
+                   title view/navigation_root_title"
+   i18n:domain="plone"
+   i18n:attributes="title">
+    <img src="logo.jpg" alt=""
+         tal:replace="structure view/logo_tag" /></a>

Added: collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/browser/logo.py
==============================================================================
--- (empty file)
+++ collective.randomheaderimage/branches/random_image_per_section/collective/randomheaderimage/browser/logo.py	Fri Sep 13 14:47:14 2013
@@ -0,0 +1,76 @@
+from plone.app.layout.viewlets.common import ViewletBase
+from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
+from Products.CMFCore.utils import getToolByName
+from zope.component import getMultiAdapter
+
+
+class LogoViewlet(ViewletBase):
+    index = ViewPageTemplateFile('logo.pt')
+
+    def get_mapping(self, images_path):
+        return dict([(x.split('|')[0], x.split('|')[1])
+                     for x in images_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 update(self):
+        super(LogoViewlet, self).update()
+
+        portal = self.portal_state.portal()
+        images_path = None
+
+        pprop = getToolByName(self.context, 'portal_properties')
+        if pprop.site_properties.hasProperty('section_logo_image_paths'):
+            props = pprop.site_properties
+            images_path = props.getProperty('section_logo_image_paths')
+
+        # If we have some path, try to see if are useful
+        # if we don't have get original logoName
+        if not images_path:
+            logoName = self.get_site_logo(portal)
+        else:
+            mapping = self.get_mapping(images_path)
+            candidates = self.get_image_candidate(mapping)
+            if not candidates:
+                logoName = self.get_site_logo(portal)
+            else:
+                logoName = mapping[self.get_folder_path(candidates)]
+
+        logoTitle = self.portal_state.portal_title()
+
+        #Here we could have a custom image or original site logo. Try to get it
+        #If you can't take it get original site logo
+        try:
+            logo = portal.restrictedTraverse(logoName)
+        except:
+            logoName = self.get_site_logo(portal)
+            logo = portal.restrictedTraverse(logoName)
+
+        #Follow the original behaviour: create the real logo
+        self.logo_tag = logo.tag(title=logoTitle, alt=logoTitle)
+        self.navigation_root_title = self.portal_state.navigation_root_title()
+
+    def get_image_candidate(self, mapping):
+        pcs = getMultiAdapter((self.context, self.request),
+                              name='plone_context_state')
+        cpath = '/'.join(pcs.canonical_object().getPhysicalPath())
+        candidates = []
+        for key in mapping:
+            if cpath.startswith(key):
+                candidates.append(key)
+        return candidates
+
+    def get_site_logo(self, portal):
+        bprops = portal.restrictedTraverse('base_properties', None)
+        if bprops is not None:
+            return bprops.logoName
+        else:
+            return 'logo.jpg'

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	Fri Sep 13 14:47:14 2013
@@ -64,7 +64,8 @@
             return ""
 
         pc = getToolByName(self.context, 'portal_catalog')
-        images = pc(path='/'.join(image_folder.getPhysicalPath()),
+        images = pc(path={'query': '/'.join(image_folder.getPhysicalPath()),
+                          'depth': 1},
                     portal_type="Image",
                     sort_on="getObjPositionInParent")
 

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	Fri Sep 13 14:47:14 2013
@@ -2,5 +2,6 @@
 <object name="portal_properties">
     <object name="site_properties" meta_type="Plone Property Sheet">
         <property name="folder_header_images_path" type="lines" purge="False" />
+        <property name="section_logo_image_paths" 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	Fri Sep 13 14:47:14 2013
@@ -1,6 +1,11 @@
 Changelog
 =========
 
+0.3.0 (unreleased)
+------------------
+- As done in 0.2.0 we have customized also plone.logo viewlet to show different
+  site logo in different site section
+
 0.2.0 (unreleased)
 ------------------
 - change properties to use a list instead of a single text line; in this

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	Fri Sep 13 14:47:14 2013
@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 import os
 
-version = '0.2.0'
+version = '0.3.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