Skip to content

Instantly share code, notes, and snippets.

@avoinea
Last active January 13, 2016 13:23
Show Gist options
  • Save avoinea/fa2324e8ab2eca4aadae to your computer and use it in GitHub Desktop.
Save avoinea/fa2324e8ab2eca4aadae to your computer and use it in GitHub Desktop.
Advanced EEA Faceted Navigation Query
<configure package="eea.facetednavigation.browser">
<browser:page
for="eea.facetednavigation.interfaces.IFacetedNavigable"
layer="enisa.databreach.content.interfaces.IDatabreachContentInstalled"
name="faceted_query"
class="enisa.databreach.content.browser.faceted.CustomQueryHandler"
template="template/query.pt"
permission="zope2.View"
/>
</configure>
<faceted:view
name="search-listing"
class=".search.SearchView"
template="templates/search.pt"
title="Assessment listing"
permission="zope2.View"
/>
from Products.Five import BrowserView
from eea.facetednavigation.browser.app.query import FacetedQueryHandler
from eea.facetednavigation.interfaces import IFacetedLayout
from enisa.databreach.content.interfaces import IChildNotification
from plone.uuid.interfaces import IUUID
class CustomQueryHandler(FacetedQueryHandler):
""" Customize faceted_query
"""
def __init__(self, context, request):
super(CustomQueryHandler, self).__init__(context, request)
self._all_uids = set()
def _query(self, batch=True, sort=False, **kwargs):
""" Custom query
"""
batch = False
brains = super(CustomQueryHandler, self).query(batch, sort, **kwargs)
res = set()
for brain in brains:
self._all_uids.add(brain.UID)
doc = brain.getObject()
if IChildNotification.providedBy(doc):
doc = doc.getParentNode()
uid = IUUID(doc)
if uid in res:
continue
res.add(uid)
yield doc
def query(self, batch=True, sort=False, **kwargs):
""" Custom query
"""
if IFacetedLayout(self.context).layout != 'search-listing':
return super(CustomQueryHandler, self).query(batch, sort, **kwargs)
# Custom results form search-listing
brains = self._query(batch, sort, **kwargs)
return {
'notifications': [brain for brain in brains],
'uids': self._all_uids
}
<div tal:define="
folderContents folderContents | python:{};
notifications python:folderContents.get('notifications', []);
uids python:folderContents.get('uids', []);">
...
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment