Created
March 29, 2012 12:06
-
-
Save toutpt/2236610 to your computer and use it in GitHub Desktop.
from topic to @@search from
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib import urlencode, quote_plus | |
from plone.memoize.view import memoize | |
from DateTime.DateTime import DateTime | |
from Products.Five import BrowserView | |
from Products.CMFCore.utils import getToolByName | |
class RelatedItems(BrowserView): | |
def __init__(self, context, request): | |
self.context = context | |
self.request = request | |
@memoize | |
def more_url(self): | |
"""We need to get a query and transform it to be a @@search view url | |
""" | |
portal_url = getToolByName(self.context, 'portal_url')() | |
search_url = portal_url + '/@@search?x=0&y=0&' | |
if hasattr(self.context, 'buildQuery'): | |
query = self.context.buildQuery() | |
args = [] | |
for criterion in query: | |
processed_value = False | |
value = query[criterion] | |
if type(value) == dict: | |
value = value['query'] | |
if type(value) == DateTime: | |
range = query[criterion]['range'] | |
args.append('%s.range=%s'%(criterion,quote_plus(range))) | |
d = quote_plus(value.Date()) | |
args.append('%s.query:record:list:date=%s'%(criterion,d)) | |
processed_value = True | |
if type(value) in (list,tuple): | |
arg = "" | |
if len(value) == 1: | |
args.append("%s=%s"%(criterion, quote_plus(value[0]))) | |
processed_value = True | |
else: | |
#index:list=first&index:list=second&... | |
for v in value: | |
args.append('%s:list=%s'%(criterion,quote_plus(v))) | |
processed_value = True | |
if type(value)==str: | |
args.append('%s=%s'%(criterion,quote_plus(value))) | |
return search_url+"&".join(args) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment