changeset 191:90d44df497a6

updated breadcrumb handling, works for members now.
author casties
date Wed, 19 Jun 2013 11:52:48 +0200
parents 9a09156eee7c
children dbc397782c76
files MPIWGHelper.py MPIWGProjects.py MPIWGStaff.py zpt/staff/member_index_html.zpt zpt/www/main_template.zpt
diffstat 5 files changed, 37 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/MPIWGHelper.py	Tue Jun 18 14:12:17 2013 +0200
+++ b/MPIWGHelper.py	Wed Jun 19 11:52:48 2013 +0200
@@ -102,7 +102,8 @@
 #
 def getBreadcrumbs(self):
     """return list of breadcrumbs from here to the root"""
-    crumbs = [(self.title, self.absolute_url(), self)]
+    #logging.debug("getBreadcrumbs of %s"%repr(self))
+    crumbs = [{'text':self.title, 'url':self.absolute_url(), 'object':self}]
     parent = self.aq_parent
     if hasattr(parent, 'getBreadcrumbs'):
         if self.title:
@@ -118,7 +119,7 @@
     """returns the current section name"""
     # use breadcrumbs if available
     if crumbs is not None and len(crumbs) > 0:
-        return crumbs[0][2].getId()
+        return crumbs[0]['object'].getId()
 
     p = self
     sec = None
@@ -133,7 +134,7 @@
     """returns the current subsection name"""
     # use breadcrumbs if available
     if crumbs is not None and len(crumbs) > 1:
-        return crumbs[1][2].getId()
+        return crumbs[1]['object'].getId()
 
     p = self
     sec = None
--- a/MPIWGProjects.py	Tue Jun 18 14:12:17 2013 +0200
+++ b/MPIWGProjects.py	Wed Jun 19 11:52:48 2013 +0200
@@ -1348,9 +1348,9 @@
         
         # try to get acquisition URL from parent
         if hasattr(parent, 'absolute_url'):
-            baseUrl = "%s/%s/" % (parent.absolute_url(), 'projects')
+            baseUrl = "%s/%s" % (parent.absolute_url(), 'projects')
         else:
-            baseUrl = "/en/research/projects/"
+            baseUrl = "/en/research/projects"
             
         # add in the internal project hierarchy
         tree = self.getProjectTree()
@@ -1358,10 +1358,10 @@
         # start with grandparents
         for p in ap:
             label = shortenString(p.getLabel(), 13)
-            crumbs.append((label, p.getUrl(baseUrl=baseUrl), p))            
+            crumbs.append({'text':label, 'url':p.getUrl(baseUrl=baseUrl), 'title':p.getLabel(), 'object':p})            
 
         # add this project
-        crumbs.append((self.getLabel(), self.getUrl(baseUrl=baseUrl), self))
+        crumbs.append({'text':self.getLabel(), 'url':self.getUrl(baseUrl=baseUrl), 'title':self.getLabel(), 'object':self})
             
         return crumbs
 
--- a/MPIWGStaff.py	Tue Jun 18 14:12:17 2013 +0200
+++ b/MPIWGStaff.py	Wed Jun 19 11:52:48 2013 +0200
@@ -8,6 +8,7 @@
 from zope.interface import implements
 from zope.publisher.interfaces import IPublishTraverse
 from ZPublisher.BaseRequest import DefaultPublishTraverse
+from Acquisition import aq_parent
 
 from AccessControl import ClassSecurityInfo
 from App.class_init import InitializeClass
@@ -764,6 +765,29 @@
     # TODO: compat, is this used?
     getStaffURL = getUsername
         
+
+    def getBreadcrumbs(self):
+        """return list of breadcrumbs from here to the root"""
+        crumbs = []
+        label = '%s %s'%(self.content.first_name, self.content.last_name)
+        baseUrl = None
+        parent = aq_parent(self)
+        # get parents breadcrumbs
+        if hasattr(parent, 'getBreadcrumbs'):
+            crumbs = parent.getBreadcrumbs()
+            if len(crumbs) > 0:
+                # get base url from crumbs
+                baseUrl = crumbs[-1]['url'] + '/members'
+        
+        if baseUrl is None:
+            baseUrl = '/en/staff/members'
+            
+        # add this
+        crumbs.append({'text':label, 'url':self.getUrl(baseUrl=baseUrl), 'object':self})
+            
+        return crumbs
+
+        
     def getPublicationsFromPubman(self,limit=None,publicationType=None):
         """Return list of publications."""
         if self.content.publications_mode=="year": 
--- a/zpt/staff/member_index_html.zpt	Tue Jun 18 14:12:17 2013 +0200
+++ b/zpt/staff/member_index_html.zpt	Wed Jun 19 11:52:48 2013 +0200
@@ -8,7 +8,8 @@
   <tal:block
     tal:define="global member options/member; global key member/getKey;
       global username member/getUsername; global content member/getContent;
-      global baseUrl string:$root/${secmap/staff}/members/$username" />
+      global baseUrl string:$root/${secmap/staff}/members/$username;
+      global crumbs member/getBreadcrumbs;" />
 </metal:block>
 </head>
 <body>
--- a/zpt/www/main_template.zpt	Tue Jun 18 14:12:17 2013 +0200
+++ b/zpt/www/main_template.zpt	Wed Jun 19 11:52:48 2013 +0200
@@ -2,7 +2,7 @@
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" metal:define-macro="page"
       tal:define="root here/MPIWGrootURL|here/en/MPIWGrootURL; 
-                  crumbs template/getBreadcrumbs | nothing;
+                  global crumbs template/getBreadcrumbs | nothing;
                   section here/getSection | nothing;
                   sections here/getSections | nothing;
                   lang here/getLang | nothing;
@@ -55,10 +55,10 @@
       <a tal:attributes="href root">Home</a> &gt;
       <tal:block tal:repeat="crumb crumbs | nothing">
         <tal:block tal:condition="not:repeat/crumb/end">
-          <a tal:attributes="href python:crumb[1]" tal:content="python:crumb[0]">News</a> &gt;
+          <a tal:attributes="href crumb/url; title crumb/title|nothing;" tal:content="crumb/text">News</a> &gt;
             </tal:block>
         <tal:block tal:condition="repeat/crumb/end">
-          <span class="selected"> <a tal:attributes="href python:crumb[1]" tal:content="python:crumb[0]">News</a>
+          <span class="selected"> <a tal:attributes="href crumb/url; title crumb/title|nothing;" tal:content="crumb/text">News</a>
           </span>
         </tal:block>
       </tal:block>