source: products/quintagroup.plonegooglesitemaps/branches/blacklist/quintagroup/plonegooglesitemaps/utilities.py @ 2925

Last change on this file since 2925 was 2923, checked in by mylan, 14 years ago

#228: Fixed default Path filter

  • Property svn:eol-style set to native
File size: 1.3 KB
Line 
1from zope.interface import implements
2from zope.component import queryMultiAdapter
3from quintagroup.plonegooglesitemaps.interfaces import IBlackoutFilterUtility
4
5class IdBlackoutFilterUtility(object):
6    """Filter-out by ID utility."""
7
8    implements(IBlackoutFilterUtility)
9
10    def filterOut(self, fdata, fkey, **kwargs):
11        """Filter-out fdata list by id in fkey."""
12        return [b for b in fdata if (b.getId or b.id) != fkey]
13
14
15class PathBlackoutFilterUtility(object):
16    """Filter-out by PATH utility."""
17
18    implements(IBlackoutFilterUtility)
19
20    def filterOut(self, fdata, fkey, **kwargs):
21        """Filter-out fdata list by path in fkey."""
22        sm = kwargs.get("sitemap", None)
23        req = kwargs.get("request", None)
24        if fkey.startswith("/"):
25            # absolute path filter
26            # portal_state = getMultiAdapter((self.context, self.request), name=u'plone_portal_state')
27            portal = queryMultiAdapter((sm, req), name=u"plone_portal_state").portal()
28            return [b for b in fdata if b.getPath() != '/%s%s' % (portal.getId(), fkey)]
29        elif fkey.startswith("./"):
30            # relative path filter
31            contpath = '/'.join(sm.getPhysicalPath()[:-1])
32            return [b for b in fdata if b.getPath() != (contpath + fkey[1:])]
33        return fdata
Note: See TracBrowser for help on using the repository browser.