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

Last change on this file since 2979 was 2979, checked in by mylan, 13 years ago

#228: Remake filterOut method of into generator for default filters

  • Property svn:eol-style set to native
File size: 1.5 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        for b in fdata:
17            if (b.getId or b.id) != fargs:
18                yield b
19
20
21class PathBlackoutFilter(object):
22    """Filter-out by PATH."""
23
24    implements(IBlackoutFilter)
25
26    def __init__(self, context, request):
27        self.context = context
28        self.request = request
29
30    def filterOut(self, fdata, fargs):
31        """Filter-out fdata list by path in fargs."""
32        if not (fargs.startswith("/") or fargs.startswith("./")):
33            for b in fdata:
34                yield b
35           
36        if fargs.startswith("/"):
37            # absolute path filter
38            portal_id = queryMultiAdapter((self.context, self.request),
39                         name=u"plone_portal_state").portal().getId()
40            test_path = '/' + portal_id + fargs
41        else:
42            # relative path filter
43            container_path = '/'.join(self.context.getPhysicalPath()[:-1])
44            test_path = container_path + fargs[1:]
45
46        for b in fdata:
47            if b.getPath() != test_path:
48                yield b
49
Note: See TracBrowser for help on using the repository browser.