source: products/quintagroup.plonegooglesitemaps/branches/sitemap_date/quintagroup/plonegooglesitemaps/filters.py @ 3565

Last change on this file since 3565 was 3498, checked in by potar, 7 years ago

fixed pep8

  • Property svn:eol-style set to native
File size: 1.5 KB
Line 
1from itertools import ifilter
2from zope.interface import implements
3from zope.component import queryMultiAdapter
4from quintagroup.plonegooglesitemaps.interfaces import IBlackoutFilter
5
6
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."""
18        return ifilter(lambda b, fa=fargs: (b.getId or b.id) != fargs,
19                       fdata)
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
35            portal_id = queryMultiAdapter((self.context, self.request),
36                                          name=u"plone_portal_state"
37                                          ).portal().getId()
38            test_path = '/' + portal_id + fargs
39        elif fargs.startswith("./"):
40            # relative path filter
41            container_path = '/'.join(self.context.getPhysicalPath()[:-1])
42            test_path = container_path + fargs[1:]
43        else:
44            # unrecognized starting point
45            return fdata
46
47        return ifilter(lambda b, tp=test_path: b.getPath() != tp,
48                       fdata)
Note: See TracBrowser for help on using the repository browser.