source: products/quintagroup.plonegooglesitemaps/branches/blacklist/quintagroup/plonegooglesitemaps/filters.py @ 2939

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

#228: Remake filter utility to multiadapter, fix tests

  • 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 IBlackoutFilter
4
5class IdBlackoutFilter(object):
6    """Filter-out by ID."""
7
8    implements(IBlackoutFilter)
9
10    def __init__(self, context, request):
11        self.context = context
12        self.request = request
13
14    def filterOut(self, fdata, fargs):
15        """Filter-out fdata list by id in fargs."""
16        return [b for b in fdata if (b.getId or b.id) != fargs]
17
18
19class PathBlackoutFilter(object):
20    """Filter-out by PATH."""
21
22    implements(IBlackoutFilter)
23
24    def __init__(self, context, request):
25        self.context = context
26        self.request = request
27
28    def filterOut(self, fdata, fargs):
29        """Filter-out fdata list by path in fargs."""
30        if fargs.startswith("/"):
31            # absolute path filter
32            portal = queryMultiAdapter((self.context, self.request),
33                         name=u"plone_portal_state").portal()
34            return [b for b in fdata if b.getPath() != '/%s%s' % (portal.getId(), fargs)]
35        elif fargs.startswith("./"):
36            # relative path filter
37            contpath = '/'.join(self.context.getPhysicalPath()[:-1])
38            return [b for b in fdata if b.getPath() != (contpath + fargs[1:])]
39        return fdata
Note: See TracBrowser for help on using the repository browser.