[2996] | 1 | from itertools import ifilter |
---|
[2939] | 2 | from zope.interface import implements |
---|
| 3 | from zope.component import queryMultiAdapter |
---|
| 4 | from quintagroup.plonegooglesitemaps.interfaces import IBlackoutFilter |
---|
| 5 | |
---|
[2996] | 6 | |
---|
[2939] | 7 | class 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.""" |
---|
[2996] | 18 | return ifilter(lambda b,fa=fargs:(b.getId or b.id) != fargs, |
---|
| 19 | fdata) |
---|
[2939] | 20 | |
---|
| 21 | |
---|
| 22 | class 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), |
---|
| 36 | name=u"plone_portal_state").portal().getId() |
---|
| 37 | test_path = '/' + portal_id + fargs |
---|
[2996] | 38 | elif fargs.startswith("./"): |
---|
[2939] | 39 | # relative path filter |
---|
[2979] | 40 | container_path = '/'.join(self.context.getPhysicalPath()[:-1]) |
---|
| 41 | test_path = container_path + fargs[1:] |
---|
[2996] | 42 | else: |
---|
| 43 | # unrecognized starting point |
---|
| 44 | return fdata |
---|
[2979] | 45 | |
---|
[2996] | 46 | return ifilter(lambda b,tp=test_path: b.getPath() != tp, |
---|
| 47 | fdata) |
---|