0d02e57d02b23de9c5bc6048d587d4adda007878
2 from Products
.CMFCore
.utils
import getToolByName
3 from ZTUtils
import make_query
as mq
4 from ZTUtils
import make_hidden_input
5 from Products
.Plinn
.utils
import translate
6 def _(message
) : return translate(message
, context
).encode('utf-8')
8 utool
= getToolByName(context
, 'portal_url')
10 ctool
= getToolByName(context
, 'portal_catalog')
11 mtool
= getToolByName(context
,'portal_membership')
12 homeDir
= mtool
.getHomeFolder(verifyPermission
=True)
15 for i
in ctool
.indexes() :
17 hasindex
= indexes
.has_key
19 form
= context
.REQUEST
.form
21 skip_vars
= ['strCreator', 'ajax', 'b_start']
23 # list typed criterions
24 select_vars
= ( 'review_state'
30 # first cleaning: remove empty values / dict cast.
31 for k
, v
in form
.items() :
34 if same_type( v
, [] ):
38 if hasattr(v
, 'has_key') :
43 # simplifications / cleaning again
44 if query
.has_key('portal_type') :
45 try : query
['portal_type'].remove('Member Data')
46 except (ValueError, AttributeError) : pass
48 query
['portal_type'] = context
.portal_types
.objectIds()
49 noFollowVars
.append('portal_type')
51 # clean parameters that are not indexes
56 # expand creator search item
57 if form
.has_key('strCreator') and form
['strCreator'].strip() :
58 query
['listCreators'] = [ m
.getId() for m
in context
.portal_membership
.looseSearchMembers(form
['strCreator']) ]
60 # 'mofified' index solving
61 if query
.has_key('modified') :
62 def resolveDate(modified
) :
63 today
= context
.ZopeTime().earliestTime()
64 dateResolution
= {'yesterday' : (today
-1).Date()
65 , 'lastWeek' : (today
-7).Date()
66 , 'lastMonth' : (today
-31).Date()
68 member
= mtool
.getAuthenticatedMember()
70 lastLoginTime
= member
.getProperty('last_login_time', None)
72 dateResolution
['lastLogin'] = lastLoginTime
73 return dateResolution
.get(modified
)
75 date
= resolveDate(query
['modified'])
77 query
['modified'] = {'query':date
, 'range':'min'}
81 sort_on
= query
.get('sort_on', 'fTitle')
82 if hasindex(sort_on
) :
83 query
['sort_on'] = sort_on
84 query
['sort_order'] = query
.get('sort_order', 'ascending')
86 if query
.has_key('sort_on') : query
.pop('sort_on')
87 if query
.has_key('sort_order') : query
.pop('sort_order')
89 def makeColumnHeader(indexName
) :
90 toggleSortOrder
= indexName
== sort_on
91 columnQuery
= query
.copy()
92 for name
in noFollowVars
:
93 if columnQuery
.has_key(name
) :
95 columnQuery
['sort_on'] = indexName
96 sort_order
= query
.get('sort_order', 'ascending')
98 if sort_order
== 'ascending' :
99 sort_order
= 'reverse'
100 elif sort_order
== 'reverse' :
101 sort_order
= 'ascending'
102 columnQuery
['sort_order'] = sort_order
103 url
= '%s/search?%s' % (portal_url
, mq(**columnQuery
))
106 if toggleSortOrder
: # e.g. selected
107 if query
['sort_order'] == 'ascending' :
108 toggleImg
= {'src':'%s/arrowUp.gif' % portal_url
109 ,'alt' : _('ascending sort')}
111 elif query
['sort_order'] == 'reverse' :
112 toggleImg
= {'src':'%s/arrowDown.gif' % portal_url
113 ,'alt' : _('ascending sort')}
114 return {'url':url
, 'img':toggleImg
}
117 options
['makeColumnHeader'] = makeColumnHeader
118 results
= ctool( **query
)
119 options
['results'] = results
120 options
['resultsLength'] = len(results
)
121 if homeDir
and results
:
122 options
['canSaveAsTopic'] = True
124 for name
in noFollowVars
:
127 if form
.has_key('modified') :
128 possibleValues
= {'yesterday' : 1
131 value
= possibleValues
.get(form
['modified'])
133 d
= {'critType' : 'Friendly Date Criterion'
139 try : del args
['modified']
140 except KeyError : pass
141 options
['queryAsHiddenInputs'] = make_hidden_input(**args
)
143 options
['canSaveAsTopic'] = False
144 return context
.search_results_template(**options
)