[Erp5-report] r33150 ivan - in /erp5/trunk/bt5/erp5_dms: SkinTemplateItem/portal_skins/erp5...

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Feb 26 15:59:00 CET 2010


Author: ivan
Date: Fri Feb 26 15:59:00 2010
New Revision: 33150

URL: http://svn.erp5.org?rev=33150&view=rev
Log:
Refactor script:
- no need to set / get selections, this is not a listbox but a search dialog form
- adjust to current ZSQLCatalog API
- raise if search criteria not specified rather than return empty list
- use proper variable naming

Modified:
    erp5/trunk/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/Base_getAdvancedSearchResultList.xml
    erp5/trunk/bt5/erp5_dms/bt/revision

Modified: erp5/trunk/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/Base_getAdvancedSearchResultList.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/Base_getAdvancedSearchResultList.xml?rev=33150&r1=33149&r2=33150&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/Base_getAdvancedSearchResultList.xml [utf8] (original)
+++ erp5/trunk/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/Base_getAdvancedSearchResultList.xml [utf8] Fri Feb 26 15:59:00 2010
@@ -56,100 +56,74 @@
             <value> <string encoding="cdata"><![CDATA[
 
 """\n
-The main search script. Receives one big string - a searchabletext, in\n
-the search syntax, parses the string using external method Base_parseSearchString,\n
-then does the following:\n
-- processes arguments for searching by any category\n
-- selects search mode\n
-- adds creation and modification date clauses\n
-- searches\n
-- if requested, filters result so that only the user\'s docs are returned\n
-- if requested, filters result to return only the newest versions\n
+  The main search script. Receives one big string - a searchabletext, in\n
+  the search syntax, parses the string using external method Base_parseSearchString,\n
+  then does the following:\n
+    - processes arguments for searching by any category\n
+    - selects search mode\n
+    - adds creation and modification date clauses\n
+    - searches\n
+    - if requested, filters result so that only the user\'s docs are returned\n
+    - if requested, filters result to return only the newest versions\n
 """\n
-\n
-# if no args we return empty list\n
-# we use only searchabletext - all params are passed through this\n
-\n
-# searchabletext can be supplied in request or stored in selection\n
-sstr = context.REQUEST.get(\'searchabletext\')\n
-\n
-if sstr:\n
-  context.portal_selections.setSelectionParamsFor(\'search_params_selection\', dict(searchabletext=sstr))\n
+portal = context.getPortalObject()\n
+\n
+query_kw = {}\n
+date_format = \'%Y-%m-%d\'\n
+\n
+if searchabletext is None:\n
+  # searchabletext can be supplied in request (fallback)\n
+  searchabletext = context.REQUEST.get(\'searchabletext\')\n
+\n
+if searchabletext is None:\n
+  raise ValueError, "No search string specified."\n
+\n
+parsed_search_string = context.Base_parseSearchString(searchabletext)\n
+\n
+# if no portal type specified, take all\n
+portal_type = parsed_search_string.get(\'portal_type\', None)\n
+if portal_type is None or not len(portal_type):\n
+  query_kw[\'portal_type\'] = portal.getPortalDocumentTypeList()\n
+\n
+# ZSQLCatalog wants table.key to avoid ambiguity\n
+parsed_searchabletext = parsed_search_string.get(\'searchabletext\', None)\n
+if parsed_searchabletext is not None: \n
+  query_kw[\'full_text.SearchableText\'] =  parsed_searchabletext\n
+\n
+where_expression_list = []\n
+creation_from = parsed_search_string.get(\'creation_from\', None)\n
+creation_to = parsed_search_string.get(\'creation_to\', None)\n
+modification_from = parsed_search_string.get(\'modification_from\', None)\n
+modification_to = parsed_search_string.get(\'modification_to\', None)\n
+if creation_from:\n
+  where_expression_list.append(\'catalog.creation_date >= "%s"\' \\\n
+                                 %creation_from.strftime(date_format))\n
+if creation_to:\n
+  where_expression_list.append(\'catalog.creation_date <= "%s"\' \\\n
+                                 %creation_to.strftime(date_format))\n
+if modification_from:\n
+  where_expression_list.append(\'catalog.modification_date >= "%s"\' \\\n
+                                 %modification_from.strftime(date_format))\n
+if modification_to:\n
+  where_expression_list.append(\'catalog.modification_date <= "%s"\' \\\n
+                                 %modification_to.strftime(date_format))\n
+if len(where_expression_list):\n
+  query_kw[\'where_expression\'] = \' AND \'.join(where_expression_list)\n
+\n
+if parsed_search_string.get(\'mine\'):\n
+  # user wants only his documents\n
+  query_kw[\'owner\'] = str(portal.portal_membership.getAuthenticatedMember())\n
+\n
+if parsed_search_string.get(\'newest\'):\n
+  #...and now we check for only the newest versions\n
+  # but we need to preserve order\n
+  query_kw[\'group_by\'] = (\'reference\',)\n
+  result = [doc.getLatestVersionValue() \\\n
+              for doc in context.portal_catalog(**query_kw)]\n
 else:\n
-  params = context.portal_selections.getSelectionParamsFor(\'search_params_selection\')\n
-  if params:\n
-    sstr = params.get(\'searchabletext\')\n
-\n
-if not sstr: return []\n
-\n
-args = context.Base_parseSearchString(sstr)\n
-\n
-# if no portal type specified, take all\n
-if not args.has_key(\'portal_type\') or args[\'portal_type\'] == ():\n
-  args[\'portal_type\'] = context.getPortalDocumentTypeList()\n
-\n
-### All document types in DMS do not use any xxx_relative property.\n
-### So, I comment out here. (yusei)\n
-## process searching by category\n
-#cats = []\n
-#bases = context.portal_categories.getBaseCategoryList()\n
-#for k,v in args.items():\n
-#  if k in bases and k!=\'language\':\n
-#    args[k+\'_relative_url\'] = k + \'/\' + v\n
-\n
-# expand simplified notation of search mode\n
-#mode = args.get(\'mode\')\n
-#modemap = {\'natural\':0, \'boolean\':\'in_boolean_mode\', \'expanded\':\'with_query_expansion\'}\n
-#if mode and modemap.has_key(mode):\n
-#  args[\'SearchableText\'] = dict(query=args[\'SearchableText\'], search_mode=modemap[mode])\n
-\n
-# we always do boolean because we want these options in search dialog\n
-args[\'searchabletext\'] = dict(query=args[\'searchabletext\'], search_mode=\'in_boolean_mode\')\n
-\n
-# a hack because SQLCatalog wants table.key now \n
-# dunno if it is a bug or a feature\n
-if args.has_key(\'searchabletext\'):\n
-  args[\'full_text.SearchableText\'] = args[\'searchabletext\']\n
-  args.pop(\'searchabletext\')\n
-\n
-cf = args.get(\'creation_from\')\n
-ct = args.get(\'creation_to\')\n
-mf = args.get(\'modification_from\')\n
-mt = args.get(\'modification_to\')\n
-\n
-wheres = []\n
-if cf:\n
-  wheres.append(\'catalog.creation_date>"\' + cf.strftime(\'%Y-%m-%d\') + \'"\')\n
-if ct:\n
-  wheres.append(\'catalog.creation_date<"\' + cf.strftime(\'%Y-%m-%d\') + \'"\')\n
-if mf:\n
-  wheres.append(\'catalog.modification_date>"\' + cf.strftime(\'%Y-%m-%d\') + \'"\')\n
-if mt:\n
-  wheres.append(\'catalog.modification_date<"\' + cf.strftime(\'%Y-%m-%d\') + \'"\')\n
-if wheres != []:\n
-  args[\'where_expression\'] = \' AND \'.join(wheres)\n
-\n
-# now we search\n
-# any language?\n
-if args.get(\'language\') == \'0\': args.pop(\'language\')\n
-\n
-# user wants only his documents\n
-if args.get(\'mine\'): \n
-  from AccessControl import getSecurityManager\n
-  sm = getSecurityManager()\n
-  user = sm.getUser()\n
-  args[\'owner\'] = str(user)\n
-\n
-#...and now we check for only the newest versions\n
-# but we need to preserve order\n
-if args.get(\'newest\'):\n
-  args[\'group_by\'] = (\'reference\',)\n
-  res = context.portal_catalog(**args)\n
-  res = [doc.getLatestVersionValue() for doc in res]\n
-else:\n
-  res = context.portal_catalog(**args)\n
-\n
-return res\n
+  result = portal.portal_catalog(**query_kw)\n
+\n
+return result\n
 
 
 ]]></string> </value>
@@ -162,7 +136,7 @@
         </item>
         <item>
             <key> <string>_params</string> </key>
-            <value> <string>**kw</string> </value>
+            <value> <string>searchabletext=None, **kw</string> </value>
         </item>
         <item>
             <key> <string>errors</string> </key>
@@ -182,37 +156,38 @@
                   <dictionary>
                     <item>
                         <key> <string>co_argcount</string> </key>
-                        <value> <int>0</int> </value>
+                        <value> <int>1</int> </value>
                     </item>
                     <item>
                         <key> <string>co_varnames</string> </key>
                         <value>
                           <tuple>
+                            <string>searchabletext</string>
                             <string>kw</string>
                             <string>_getattr_</string>
                             <string>context</string>
-                            <string>sstr</string>
-                            <string>dict</string>
-                            <string>params</string>
-                            <string>args</string>
-                            <string>_getitem_</string>
+                            <string>portal</string>
+                            <string>query_kw</string>
+                            <string>date_format</string>
+                            <string>None</string>
+                            <string>ValueError</string>
+                            <string>parsed_search_string</string>
+                            <string>portal_type</string>
+                            <string>len</string>
                             <string>_write_</string>
-                            <string>cf</string>
-                            <string>ct</string>
-                            <string>mf</string>
-                            <string>mt</string>
-                            <string>wheres</string>
-                            <string>AccessControl</string>
-                            <string>getSecurityManager</string>
-                            <string>sm</string>
-                            <string>user</string>
+                            <string>parsed_searchabletext</string>
+                            <string>where_expression_list</string>
+                            <string>creation_from</string>
+                            <string>creation_to</string>
+                            <string>modification_from</string>
+                            <string>modification_to</string>
                             <string>str</string>
-                            <string>_apply_</string>
-                            <string>res</string>
                             <string>append</string>
                             <string>$append0</string>
                             <string>_getiter_</string>
+                            <string>_apply_</string>
                             <string>doc</string>
+                            <string>result</string>
                           </tuple>
                         </value>
                     </item>
@@ -224,7 +199,9 @@
         <item>
             <key> <string>func_defaults</string> </key>
             <value>
-              <none/>
+              <tuple>
+                <none/>
+              </tuple>
             </value>
         </item>
         <item>

Modified: erp5/trunk/bt5/erp5_dms/bt/revision
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_dms/bt/revision?rev=33150&r1=33149&r2=33150&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_dms/bt/revision [utf8] (original)
+++ erp5/trunk/bt5/erp5_dms/bt/revision [utf8] Fri Feb 26 15:59:00 2010
@@ -1,1 +1,1 @@
-1070
+1073




More information about the Erp5-report mailing list