| 1 | from zope.interface import implements |
|---|
| 2 | from zope.component import queryMultiAdapter |
|---|
| 3 | from quintagroup.plonegooglesitemaps.interfaces import IBlackoutFilterUtility |
|---|
| 4 | |
|---|
| 5 | class IdBlackoutFilterUtility(object): |
|---|
| 6 | """Filter-out by ID utility.""" |
|---|
| 7 | |
|---|
| 8 | implements(IBlackoutFilterUtility) |
|---|
| 9 | |
|---|
| 10 | def filterOut(self, fdata, fkey, **kwargs): |
|---|
| 11 | """Filter-out fdata list by id in fkey.""" |
|---|
| 12 | return [b for b in fdata if (b.getId or b.id) != fkey] |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | class PathBlackoutFilterUtility(object): |
|---|
| 16 | """Filter-out by PATH utility.""" |
|---|
| 17 | |
|---|
| 18 | implements(IBlackoutFilterUtility) |
|---|
| 19 | |
|---|
| 20 | def filterOut(self, fdata, fkey, **kwargs): |
|---|
| 21 | """Filter-out fdata list by path in fkey.""" |
|---|
| 22 | sm = kwargs.get("sitemap", None) |
|---|
| 23 | req = kwargs.get("request", None) |
|---|
| 24 | if fkey.startswith("/"): |
|---|
| 25 | # absolute path filter |
|---|
| 26 | # portal_state = getMultiAdapter((self.context, self.request), name=u'plone_portal_state') |
|---|
| 27 | portal = queryMultiAdapter((sm, req), name=u"plone_portal_state").portal() |
|---|
| 28 | return [b for b in fdata if b.getPath() != '/%s%s' % (portal.getId(), fkey)] |
|---|
| 29 | elif fkey.startswith("./"): |
|---|
| 30 | # relative path filter |
|---|
| 31 | contpath = '/'.join(sm.getPhysicalPath()[:-1]) |
|---|
| 32 | return [b for b in fdata if b.getPath() != (contpath + fkey[1:])] |
|---|
| 33 | return fdata |
|---|