Commit bbdc94ed authored by Bartek Górny's avatar Bartek Górny

Added options to search by reference and to display only newest available versions

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11081 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f5c0c87b
......@@ -103,12 +103,15 @@
<key> <string>right</string> </key>
<value>
<list>
<string>reference</string>
<string>creation_from</string>
<string>creation_to</string>
<string>modification_from</string>
<string>modification_to</string>
<string>search_mode</string>
<string>mine</string>
<string>newest</string>
<string>language</string>
</list>
</value>
</item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<tuple>
<string>Products.Formulator.StandardFields</string>
<string>CheckBoxField</string>
</tuple>
<none/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>newest</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>alternate_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>css_class</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>default</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>editable</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>external_validator</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>extra</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>hidden</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Only newest versions</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -76,6 +76,11 @@ if doctype:\n
st+=\' type:%s\' % doctype[0]\n
else:\n
st+=\' type:(%s)\' % \',\'.join(doctype)\n
ref=req.get(\'reference\')\n
if ref:st+=\' reference:%s\' % ref\n
lng=req.get(\'language\')\n
if lng and lng!=\'0\':\n
st+=\' language:%s\' % lng\n
sm=req.get(\'search_mode\')\n
smmap={\'in_boolean_mode\':\'boolean\',\'with_query_expansion\':\'expanded\'}\n
if sm and smmap.has_key(sm):\n
......@@ -83,6 +88,9 @@ if sm and smmap.has_key(sm):\n
mine=req.get(\'mine\')\n
if mine:\n
st+=\' mine:yes\'\n
newest=req.get(\'newest\')\n
if newest:\n
st+=\' newest:yes\'\n
\n
return st\n
</string> </value>
......@@ -136,15 +144,18 @@ return st\n
<string>a</string>
<string>kw</string>
<string>_getattr_</string>
<string>context</string>
<string>context</string>
<string>req</string>
<string>st</string>
<string>doctype</string>
<string>len</string>
<string>_getitem_</string>
<string>ref</string>
<string>lng</string>
<string>sm</string>
<string>smmap</string>
<string>mine</string>
<string>newest</string>
</tuple>
</value>
</item>
......
......@@ -346,8 +346,16 @@
<string>Title</string>
</tuple>
<tuple>
<string>description</string>
<string>Description</string>
<string>reference</string>
<string>Reference</string>
</tuple>
<tuple>
<string>version</string>
<string>Version</string>
</tuple>
<tuple>
<string>language</string>
<string>Language</string>
</tuple>
<tuple>
<string>Base_showFoundText</string>
......
......@@ -127,10 +127,14 @@ if wheres!=[]:\n
kw[\'where_expression\']=\' AND \'.join(wheres)\n
\n
# now we search\n
# any language?\n
if kw.get(\'language\')==\'0\':kw.pop(\'language\')\n
context.log(\'SEARCH:\',args)\n
res=context.portal_catalog(**kw)\n
\n
# user wants only his documents\n
if args.get(\'mine\'): \n
context.log(\'mine\')\n
from AccessControl import getSecurityManager\n
sm=getSecurityManager()\n
u=sm.getUser()\n
......@@ -138,6 +142,30 @@ if args.get(\'mine\'): \n
# some day we will do it in catalog\n
res=[r for r in res if u.allowed(r.getObject(),(\'Owner\',))]\n
\n
#...and now we check for only the newest versions\n
# but we need to preserve order\n
if args.get(\'newest\'):\n
context.log(\'newest\')\n
idx={} # for recording what we have where and in which version\n
newest=[]\n
counter=0\n
for r in res:\n
ref=r.getReference()\n
try:\n
ver=int(r.getVersion())\n
except ValueError:\n
continue\n
if idx.has_key(ref):\n
if idx[ref][0]>=ver:\n
continue\n
else:\n
del newest[idx[ref][1]]\n
counter-=1\n
newest.append(r)\n
idx[ref]=(ver,counter)\n
counter+=1\n
res=newest\n
\n
\n
return res\n
......@@ -219,6 +247,13 @@ return res\n
<string>append</string>
<string>$append0</string>
<string>r</string>
<string>idx</string>
<string>newest</string>
<string>counter</string>
<string>ref</string>
<string>int</string>
<string>ver</string>
<string>ValueError</string>
</tuple>
</value>
</item>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment