Back to index

plone3  3.1.7
search.py
Go to the documentation of this file.
00001 ##parameters=b_start=0
00002 ##
00003 from Products.PythonScripts.standard import thousands_commas
00004 from ZTUtils import Batch
00005 from Products.CMFCore.utils import getToolByName
00006 from Products.CMFDefault.utils import decode
00007 from Products.CMFDefault.utils import Message as _
00008 
00009 ctool = getToolByName(script, 'portal_catalog')
00010 utool = getToolByName(script, 'portal_url')
00011 portal_url = utool()
00012 epoch = DateTime('1970/01/01 00:00:01 GMT')
00013 
00014 
00015 options = {}
00016 
00017 target = '%s/search' % portal_url
00018 kw = context.REQUEST.form.copy()
00019 for k, v in kw.items():
00020     if k in ('review_state', 'Title', 'Subject', 'Description', 'portal_type',
00021              'listCreators'):
00022         if same_type(v, []):
00023             v = filter(None, v)
00024         if not v:
00025             del kw[k]
00026     elif k in ('created',):
00027         if v['query'] == epoch and v['range'] == 'min':
00028             del kw[k]
00029         else:
00030             # work around problems with DateTime in records
00031             kw[k] = v.copy()
00032     elif k in ('go', 'go.x', 'go.y', 'b_start'):
00033             del kw[k]
00034 items = ctool.searchResults(kw)
00035 batch_obj = Batch(items, 25, b_start, orphan=1)
00036 
00037 items = [ {'description': item.Description,
00038            'icon': item.getIcon,
00039            'title': item.Title,
00040            'type': item.Type,
00041            'date': item.Date,
00042            'url': item.getURL()+'/view'}
00043           for item in batch_obj ]
00044 
00045 length = batch_obj.sequence_length
00046 summary = { 'length': length and thousands_commas(length) or '',
00047             'type': (length == 1) and _(u'item') or _(u'items'),
00048             'match': kw.get('SearchableText') }
00049 navigation = context.getBatchNavigation(batch_obj, target, **kw)
00050 options['batch'] = { 'summary': summary,
00051                      'listItemInfos': tuple(items),
00052                      'navigation': navigation }
00053 
00054 return context.search_results_template(**decode(options, script))