[2939] | 1 | from zope.interface import implements |
---|
| 2 | from zope.component import queryMultiAdapter |
---|
| 3 | from quintagroup.plonegooglesitemaps.interfaces import IBlackoutFilter |
---|
| 4 | |
---|
| 5 | class 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.""" |
---|
[2979] | 16 | for b in fdata: |
---|
| 17 | if (b.getId or b.id) != fargs: |
---|
| 18 | yield b |
---|
[2939] | 19 | |
---|
| 20 | |
---|
| 21 | class 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.""" |
---|
[2979] | 32 | if not (fargs.startswith("/") or fargs.startswith("./")): |
---|
| 33 | for b in fdata: |
---|
| 34 | yield b |
---|
| 35 | |
---|
[2939] | 36 | if fargs.startswith("/"): |
---|
| 37 | # absolute path filter |
---|
[2979] | 38 | portal_id = queryMultiAdapter((self.context, self.request), |
---|
| 39 | name=u"plone_portal_state").portal().getId() |
---|
| 40 | test_path = '/' + portal_id + fargs |
---|
| 41 | else: |
---|
[2939] | 42 | # relative path filter |
---|
[2979] | 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 | |
---|