Commit a55c859b authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

ERP5Catalog: implment getDocumentValueList() in CatalogTool.

parent db6ec6ea
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 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>**kw</string> </value> <value> <string>all_versions=None, all_languages=None, **kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -312,6 +312,38 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin): ...@@ -312,6 +312,38 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
return result 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') security.declareProtected(Permissions.View, 'getPermanentURL')
def getPermanentURL(self, document, view=True): def getPermanentURL(self, document, view=True):
""" """
......
# Use getDocumentValueList for ERP5 Web search_method = getattr(context, 'getDocumentValueList',
if context.getWebSectionValue() is None: context.getPortalObject().portal_catalog)
search_method = context.getPortalObject().portal_catalog
else:
search_method = context.getDocumentValueList
return search_method(**kw) return search_method(**kw)
...@@ -43,18 +43,10 @@ from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery ...@@ -43,18 +43,10 @@ from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery
from zExceptions import Unauthorized from zExceptions import Unauthorized
try: try:
portal = container.getPortalObject() portal = context.getPortalObject()
kw = portal.portal_catalog.getSQLCatalog().getCannonicalArgumentDict(kw) kw = context.getCannonicalArgumentDict(kw)
if search_context is None:
# Try to find the Web Section or Web Site we belong to search_context = context
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)
# Build the list of parameters # Build the list of parameters
if not language: if not language:
...@@ -86,7 +78,7 @@ try: ...@@ -86,7 +78,7 @@ try:
if all_versions: if all_versions:
if not all_languages: if not all_languages:
kw['language'] = language kw['language'] = language
return current_section.searchResults(src__=src__, **kw) return search_context.searchResults(src__=src__, **kw)
else: else:
group_by_list = set(kw.get('group_by_list', [])) group_by_list = set(kw.get('group_by_list', []))
if all_languages: if all_languages:
...@@ -100,10 +92,11 @@ try: ...@@ -100,10 +92,11 @@ try:
kw.setdefault('select_dict', {}).update( kw.setdefault('select_dict', {}).update(
(x.replace('.', '_') + '__ext__', x) (x.replace('.', '_') + '__ext__', x)
for x in extra_column_set if not x.endswith('__score__')) 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,
all_languages=all_languages, language=language,
src__=src__, all_languages=all_languages,
kw=kw) src__=src__,
kw=kw)
except Unauthorized: except Unauthorized:
return [] return []
...@@ -50,11 +50,11 @@ ...@@ -50,11 +50,11 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <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>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>Base_getDocumentValueList</string> </value> <value> <string>SQLCatalog_getDocumentValueList</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </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_domain="kw.get('selection_domain', None)"
selection_report="kw.get('selection_report', None)" selection_report="kw.get('selection_report', None)"
optimizer_switch_key_list="portal_catalog.getSQLCatalog().getOptimizerSwitchKeyList()"> optimizer_switch_key_list="getOptimizerSwitchKeyList()">
<dtml-comment> <dtml-comment>
Currently, there is no other choice to implement this method as an SQL catalog until SQLCatalog Currently, there is no other choice to implement this method as an SQL catalog until SQLCatalog
......
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
</item> </item>
<item> <item>
<key> <string>arguments_src</string> </key> <key> <string>arguments_src</string> </key>
<value> <string>language\r\n <value> <string>search_context\r\n
language\r\n
all_languages\r\n all_languages\r\n
kw</string> </value> kw</string> </value>
</item> </item>
...@@ -50,7 +51,7 @@ kw</string> </value> ...@@ -50,7 +51,7 @@ kw</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>Base_zGetDocumentValueList</string> </value> <value> <string>SQLCatalog_zGetDocumentValueList</string> </value>
</item> </item>
<item> <item>
<key> <string>max_cache_</string> </key> <key> <string>max_cache_</string> </key>
......
erp5_mysql_innodb/SQLCatalog_catalogTransformation erp5_mysql_innodb/SQLCatalog_catalogTransformation
erp5_mysql_innodb/SQLCatalog_catalogTransformationList erp5_mysql_innodb/SQLCatalog_catalogTransformationList
erp5_mysql_innodb/SQLCatalog_getDocumentValueList
erp5_mysql_innodb/SQLCatalog_zGetDocumentValueList
erp5_mysql_innodb/SQLCatalog_makeFullTextQuery erp5_mysql_innodb/SQLCatalog_makeFullTextQuery
erp5_mysql_innodb/SQLCatalog_makeQuickSearchQuery erp5_mysql_innodb/SQLCatalog_makeQuickSearchQuery
erp5_mysql_innodb/SQLCatalog_makeSearchTextQuery erp5_mysql_innodb/SQLCatalog_makeSearchTextQuery
......
...@@ -1153,5 +1153,21 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -1153,5 +1153,21 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
db.query(r) db.query(r)
return src 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) InitializeClass(CatalogTool)
...@@ -42,7 +42,6 @@ from Products.CMFCore.CMFCatalogAware import CMFCatalogAware ...@@ -42,7 +42,6 @@ from Products.CMFCore.CMFCatalogAware import CMFCatalogAware
from Products.CMFCore.PortalFolder import ContentFilter from Products.CMFCore.PortalFolder import ContentFilter
from Products.ERP5Type.Base import Base from Products.ERP5Type.Base import Base
from Products.ERP5Type.Cache import getReadOnlyTransactionCache
from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage from Products.ERP5Type.ConsistencyMessage import ConsistencyMessage
from Products.ERP5Type.CopySupport import CopyContainer from Products.ERP5Type.CopySupport import CopyContainer
from Products.ERP5Type import PropertySheet from Products.ERP5Type import PropertySheet
...@@ -432,42 +431,6 @@ class FolderMixIn(ExtensionClass.Base): ...@@ -432,42 +431,6 @@ class FolderMixIn(ExtensionClass.Base):
else: else:
return None 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={}, def _recurseCallMethod(self, method_id, method_args=(), method_kw={},
restricted=False, id_list=None, min_id=None, **kw): restricted=False, id_list=None, min_id=None, **kw):
"""Run a script by activity on objects found recursively from this folder """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