Commit 224f1e75 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

erp5_base: implement getDocumentValueList() in FolderMixin so that we can use DMS API everywhere.

parent 70bdbf67
"""
This script is part of ERP5 Web
ERP5 Web is a business template of ERP5 which provides a way
to create web sites which can display selected
ERP5 contents through multiple custom web layouts.
This script returns a list of document values (ie. objects or brains)
which are considered as part of this section. It can be
a list of web pages (usual case), a list of products
......@@ -40,7 +34,7 @@
SUGGESTIONS:
- Prevent showing duplicate references
- Add documents associated to this section through 'aggregate'.
- Display only the latest version and the appropriate language.
......@@ -52,41 +46,48 @@ try:
portal = container.getPortalObject()
kw = portal.portal_catalog.getSQLCatalog().getCannonicalArgumentDict(kw)
# First find the Web Section or Web Site we belong to
# Try to find the Web Section or Web Site we belong to
current_section = context.getWebSectionValue()
if all_versions is None:
all_versions = context.getLayoutProperty('layout_all_versions', default=False)
if all_languages is None:
all_languages = context.getLayoutProperty('layout_all_languages', default=False)
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
if not language:
language = portal.Localizer.get_selected_language()
if validation_state is None:
if 'portal_type' not in kw:
kw['portal_type'] = portal.getPortalDocumentTypeList()
if 'validation_state' not in kw:
# XXX hardcoded validation state list.
# Use predicate or layout property instead
validation_state = ('released', 'released_alive', 'published',
'published_alive', 'shared', 'shared_alive',
'public', 'validated')
kw['validation_state'] = validation_state
kw['validation_state'] = ('released', 'released_alive', 'published',
'published_alive', 'shared', 'shared_alive',
'public', 'validated')
if 'order_by_list' not in kw:
# XXX Do not sort by default, as it increases query time
kw['order_by_list'] = [('int_index', 'DESC'), ('reference', 'DESC')]
if effective_date is None:
if 'effective_date' not in kw:
if now is None:
now = DateTime()
effective_date = ComplexQuery(
kw['effective_date'] = ComplexQuery(
SimpleQuery(effective_date=None),
SimpleQuery(effective_date=now, comparison_operator='<='),
logical_operator='or',
)
kw['effective_date'] = effective_date
if not all_versions:
if all_versions:
if not all_languages:
kw['language'] = language
return current_section.searchResults(src__=src__, **kw)
else:
group_by_list = set(kw.get('group_by_list', []))
if all_languages:
kw['group_by_list'] = list(group_by_list.union(('reference', 'language')))
......@@ -99,14 +100,10 @@ try:
kw.setdefault('select_dict', {}).update(
(x.replace('.', '_') + '__ext__', x)
for x in extra_column_set if not x.endswith('__score__'))
return current_section.WebSection_zGetDocumentValueList(language=language,
all_languages=all_languages,
src__=src__,
kw=kw)
else:
if not all_languages:
kw['language'] = language
return current_section.searchResults(src__=src__, **kw)
return current_section.Base_zGetDocumentValueList(language=language,
all_languages=all_languages,
src__=src__,
kw=kw)
except Unauthorized:
return []
......@@ -50,11 +50,11 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>language=None, validation_state=None, all_languages=None, all_versions=None, effective_date=None, now=None, src__=0, **kw</string> </value>
<value> <string>language=None, all_languages=None, all_versions=None, now=None, src__=0, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WebSection_getDocumentValueListBase</string> </value>
<value> <string>Base_getDocumentValueList</string> </value>
</item>
</dictionary>
</pickle>
......
<dtml-let query="buildSQLQuery(query=portal_catalog.getSecurityQuery(**kw), **kw)"
<dtml-let query="(_.has_key('buildSQLQuery') and buildSQLQuery or 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()">
......@@ -31,7 +31,7 @@
CONCAT(CASE my_versioning.language
WHEN <dtml-sqlvar language type="string"> THEN '4'
WHEN '' THEN '3'
WHEN 'en' THEN '2'
WHEN <dtml-sqlvar expr="Localizer.get_default_language() or 'en'" type="string"> THEN '2'
ELSE '1' END,
my_versioning.version) AS priority
<dtml-if "query['select_expression']">,<dtml-var "query['select_expression']"></dtml-if>
......
......@@ -50,7 +50,7 @@ kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WebSection_zGetDocumentValueList</string> </value>
<value> <string>Base_zGetDocumentValueList</string> </value>
</item>
<item>
<key> <string>max_cache_</string> </key>
......
# This script returns a list of document values
return context.WebSection_getDocumentValueListBase(**kw)
return context.Base_getDocumentValueList(**kw)
......@@ -312,38 +312,6 @@ 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):
"""
......
search_method = getattr(context, 'getDocumentValueList',
context.getPortalObject().portal_catalog)
# Use getDocumentValueList for ERP5 Web
if context.getWebSectionValue() is None:
search_method = context.getPortalObject().portal_catalog
else:
search_method = context.getDocumentValueList
return search_method(**kw)
This diff is collapsed.
......@@ -42,6 +42,7 @@ 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
......@@ -431,6 +432,42 @@ 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