source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/filters.py @ 3510

Last change on this file since 3510 was 3510, checked in by potar, 12 years ago

Merged sitemap_date branch into trunk

  • Property svn:eol-style set to native
File size: 1.5 KB
RevLine 
[2996]1from itertools import ifilter
[2939]2from zope.interface import implements
3from zope.component import queryMultiAdapter
4from quintagroup.plonegooglesitemaps.interfaces import IBlackoutFilter
5
[2996]6
[2939]7class IdBlackoutFilter(object):
8    """Filter-out by ID."""
9
10    implements(IBlackoutFilter)
11
12    def __init__(self, context, request):
13        self.context = context
14        self.request = request
15
16    def filterOut(self, fdata, fargs):
17        """Filter-out fdata list by id in fargs."""
[3152]18        return ifilter(lambda b, fa=fargs: (b.getId or b.id) != fargs,
[2996]19                       fdata)
[2939]20
21
22class PathBlackoutFilter(object):
23    """Filter-out by PATH."""
24
25    implements(IBlackoutFilter)
26
27    def __init__(self, context, request):
28        self.context = context
29        self.request = request
30
31    def filterOut(self, fdata, fargs):
32        """Filter-out fdata list by path in fargs."""
33        if fargs.startswith("/"):
34            # absolute path filter
[2979]35            portal_id = queryMultiAdapter((self.context, self.request),
[3510]36                                          name=u"plone_portal_state"
37                                          ).portal().getId()
[2979]38            test_path = '/' + portal_id + fargs
[2996]39        elif fargs.startswith("./"):
[2939]40            # relative path filter
[2979]41            container_path = '/'.join(self.context.getPhysicalPath()[:-1])
42            test_path = container_path + fargs[1:]
[2996]43        else:
44            # unrecognized starting point
45            return fdata
[2979]46
[3152]47        return ifilter(lambda b, tp=test_path: b.getPath() != tp,
[2996]48                       fdata)
Note: See TracBrowser for help on using the repository browser.