Commit 68eda1e5 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

ERP5Catalog: implment getDocumentValueList() in CatalogTool.

parent 98c0714a
return context.Base_getDocumentValueList(**kw)
# First find the Web Section or Web Site we belong to
search_context = context.getWebSectionValue()
if all_versions is None:
all_versions = search_context.getLayoutProperty('layout_all_versions', default=False)
if all_languages is None:
all_languages = search_context.getLayoutProperty('layout_all_languages', default=False)
return context.getPortalObject().portal_catalog.getDocumentValueList(
search_context=search_context,
all_versions=all_versions,
all_languages=all_languages,
**kw)
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**kw</string> </value>
<value> <string>all_versions=None, all_languages=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -312,6 +312,38 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
return result
security.declareProtected(Permissions.View, 'getDocumentValueList')
def getDocumentValueList(self, **kw):
"""
Return the list of documents which belong to the
current section. The API is designed to
support additional parameters so that it is possible
to group documents by reference, version, language, etc.
or to implement filtering of documents.
This method must be implemented through a
portal type dependent script:
WebSection_getDocumentValueList
"""
cache = getReadOnlyTransactionCache()
if cache is not None:
key = ('getDocumentValueList', self) + tuple(kw.items())
try:
return cache[key]
except KeyError:
pass
result = self._getTypeBasedMethod('getDocumentValueList',
fallback_script_id='WebSection_getDocumentValueList')(**kw)
if cache is not None:
cache[key] = result
if result is not None and not kw.get('src__', 0):
result = [doc.__of__(self) for doc in result]
return result
security.declareProtected(Permissions.View, 'getPermanentURL')
def getPermanentURL(self, document, view=True):
"""
......
# Use getDocumentValueList for ERP5 Web
if context.getWebSectionValue() is None:
search_method = context.getPortalObject().portal_catalog
else:
search_method = context.getDocumentValueList
search_method = getattr(context, 'getDocumentValueList',
context.getPortalObject().portal_catalog)
return search_method(**kw)
......@@ -43,18 +43,10 @@ from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery
from zExceptions import Unauthorized
try:
portal = container.getPortalObject()
kw = portal.portal_catalog.getSQLCatalog().getCannonicalArgumentDict(kw)
# Try to find the Web Section or Web Site we belong to
current_section = context.getWebSectionValue()
if current_section is None:
current_section = context
else:
if all_versions is None:
all_versions = current_section.getLayoutProperty('layout_all_versions', default=False)
if all_languages is None:
all_languages = current_section.getLayoutProperty('layout_all_languages', default=False)
portal = context.getPortalObject()
kw = context.getCannonicalArgumentDict(kw)
if search_context is None:
search_context = context
# Build the list of parameters
if not language:
......@@ -86,7 +78,7 @@ try:
if all_versions:
if not all_languages:
kw['language'] = language
return current_section.searchResults(src__=src__, **kw)
return search_context.searchResults(src__=src__, **kw)
else:
group_by_list = set(kw.get('group_by_list', []))
if all_languages:
......@@ -100,7 +92,8 @@ try:
kw.setdefault('select_dict', {}).update(
(x.replace('.', '_') + '__ext__', x)
for x in extra_column_set if not x.endswith('__score__'))
return current_section.Base_zGetDocumentValueList(language=language,
return context.SQLCatalog_zGetDocumentValueList(search_context=search_context,
language=language,
all_languages=all_languages,
src__=src__,
kw=kw)
......
......@@ -50,11 +50,11 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>language=None, all_languages=None, all_versions=None, now=None, src__=0, **kw</string> </value>
<value> <string>search_context=None, language=None, all_languages=None, all_versions=None, now=None, src__=0, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getDocumentValueList</string> </value>
<value> <string>SQLCatalog_getDocumentValueList</string> </value>
</item>
</dictionary>
</pickle>
......
<dtml-let query="(_.has_key('buildSQLQuery') and buildSQLQuery or portal_catalog.buildSQLQuery)(query=portal_catalog.getSecurityQuery(**kw), **kw)"
<dtml-let query="getattr(search_context, 'buildSQLQuery', portal_catalog.buildSQLQuery)(query=portal_catalog.getSecurityQuery(**kw), **kw)"
selection_domain="kw.get('selection_domain', None)"
selection_report="kw.get('selection_report', None)"
optimizer_switch_key_list="portal_catalog.getSQLCatalog().getOptimizerSwitchKeyList()">
optimizer_switch_key_list="getOptimizerSwitchKeyList()">
<dtml-comment>
Currently, there is no other choice to implement this method as an SQL catalog until SQLCatalog
......
......@@ -22,7 +22,8 @@
</item>
<item>
<key> <string>arguments_src</string> </key>
<value> <string>language\r\n
<value> <string>search_context\r\n
language\r\n
all_languages\r\n
kw</string> </value>
</item>
......@@ -50,7 +51,7 @@ kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_zGetDocumentValueList</string> </value>
<value> <string>SQLCatalog_zGetDocumentValueList</string> </value>
</item>
<item>
<key> <string>max_cache_</string> </key>
......
erp5_mysql_innodb/SQLCatalog_catalogTransformation
erp5_mysql_innodb/SQLCatalog_catalogTransformationList
erp5_mysql_innodb/SQLCatalog_getDocumentValueList
erp5_mysql_innodb/SQLCatalog_zGetDocumentValueList
erp5_mysql_innodb/SQLCatalog_makeFullTextQuery
erp5_mysql_innodb/SQLCatalog_makeQuickSearchQuery
erp5_mysql_innodb/SQLCatalog_makeSearchTextQuery
......
......@@ -1126,5 +1126,21 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
db.query(r)
return src
# XXX which permission ?
# XXX API parameters should be explicitly defined in interface
# instead of **kw
def getDocumentValueList(self, **kw):
"""
Return the list of documents which belong to the
current section. The API is designed to
support additional parameters so that it is possible
to group documents by reference, version, language, etc.
or to implement filtering of documents.
This method must be implemented through a
catalog method script :
SQLCatalog_getDocumentValueList
"""
return self.getSQLCatalog().SQLCatalog_getDocumentValueList(**kw)
InitializeClass(CatalogTool)
......@@ -42,7 +42,6 @@ from Products.CMFCore.CMFCatalogAware import CMFCatalogAware
from Products.CMFCore.PortalFolder import ContentFilter
from Products.ERP5Type.Base import Base
from Products.ERP5Type.Cache import getReadOnlyTransactionCache
from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage
from Products.ERP5Type.CopySupport import CopyContainer
from Products.ERP5Type import PropertySheet
......@@ -432,42 +431,6 @@ class FolderMixIn(ExtensionClass.Base):
else:
return None
security.declareProtected(Permissions.View, 'getDocumentValueList')
def getDocumentValueList(self, **kw):
"""
Return the list of documents which belong to the
current section. The API is designed to
support additional parameters so that it is possible
to group documents by reference, version, language, etc.
or to implement filtering of documents.
This method must be implemented through a
portal type dependent script like :
Base_getDocumentValueList
"""
cache = getReadOnlyTransactionCache()
if cache is not None:
key = ('getDocumentValueList', self) + tuple(kw.items())
try:
return cache[key]
except KeyError:
pass
_getTypeBasedMethod = getattr(self, '_getTypeBasedMethod', None)
if _getTypeBasedMethod is None:
result = self.Base_getDocumentValueList(**kw)
else:
result = _getTypeBasedMethod('getDocumentValueList',
fallback_script_id='Base_getDocumentValueList')(**kw)
if cache is not None:
cache[key] = result
if result is not None and not kw.get('src__', 0):
result = [doc.__of__(self) for doc in result]
return result
def _recurseCallMethod(self, method_id, method_args=(), method_kw={},
restricted=False, id_list=None, min_id=None, **kw):
"""Run a script by activity on objects found recursively from this folder
......
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