version 1.1.2.7, 2008/10/23 07:53:50
|
version 1.1.2.9, 2009/11/06 15:37:42
|
Line 111 def shortenString(s, l, ellipsis='...'):
|
Line 111 def shortenString(s, l, ellipsis='...'):
|
"""returns a string of length l (or l-1) by omitting characters in the middle of s, replacing with ellipsis.""" |
"""returns a string of length l (or l-1) by omitting characters in the middle of s, replacing with ellipsis.""" |
l1 = int((l - len(ellipsis)) / 2) |
l1 = int((l - len(ellipsis)) / 2) |
return "%s%s%s"%(s[:l1],ellipsis,s[-l1:]) |
return "%s%s%s"%(s[:l1],ellipsis,s[-l1:]) |
|
|
|
|
|
# |
|
# navigation methods (should better be a mixin class) |
|
# |
|
def getBreadcrumbs(self): |
|
"""return list of breadcrumbs from here to the root""" |
|
crumbs = [(self.title, self.absolute_url(), self)] |
|
parent = self.aq_parent |
|
if hasattr(parent, 'getBreadcrumbs'): |
|
if self.title: |
|
return parent.getBreadcrumbs() + crumbs |
|
else: |
|
# if there's no title, skip this level |
|
return parent.getBreadcrumbs() |
|
|
|
return crumbs |
|
|
|
|
|
def getSection(self, crumbs=None): |
|
"""returns the current section name""" |
|
# use breadcrumbs if available |
|
if crumbs is not None and len(crumbs) > 0: |
|
return crumbs[0][2].getId() |
|
|
|
p = self |
|
sec = None |
|
# descend parents to the root (and remember the last id) |
|
while p is not None and p.meta_type != 'MPIWGRoot': |
|
sec = p.getId() |
|
p = p.aq_parent |
|
|
|
return sec |
|
|
|
def getSubSection(self, crumbs=None): |
|
"""returns the current subsection name""" |
|
# use breadcrumbs if available |
|
if crumbs is not None and len(crumbs) > 1: |
|
return crumbs[1][2].getId() |
|
|
|
p = self |
|
sec = None |
|
subsec = None |
|
# descend parents to the root (and remember the last id) |
|
while p is not None and p.meta_type != 'MPIWGRoot': |
|
subsec = sec |
|
sec = p.getId() |
|
p = p.aq_parent |
|
|
|
return subsec |
|
|