Commit 49becc9f authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

ERP5Catalog: add strict_language argument in getDocumentValueList().

If strict_language is False, a document having the other language is
chosen if the specified language one is missing.

all_languages=True returns results grouped by (reference, language) so
that we can have several documents for a single reference.

strict_language=False returns results grouped by (reference,) only,
with considering the language priority, thus we have only one document
for a single reference.
parent e38127c0
......@@ -4,7 +4,8 @@ notification_message_list = portal.portal_catalog.getDocumentValueList(
validation_state=validation_state or 'validated',
reference=reference,
language=language,
all_languages=True,
strict_language=strict_language,
**kw
)
if notification_message_list:
return notification_message_list[0].getObject()
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>reference, language=None, validation_state=None, **kw</string> </value>
<value> <string>reference, language=None, strict_language=False, validation_state=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -30,9 +30,4 @@
reference_list = context.getAggregateReferenceList()
if not reference_list: return None # Quick return
# We should only display those documents which are shared
# to some extend. This list takes into account some common
# state IDs used in ERP5.
return context.getDocumentValue(name=reference_list,
validation_state=('released', 'released_alive', 'published', 'published_alive',
'shared', 'shared_alive', 'public', 'validated'))
return context.getDocumentValue(name=reference_list)
......@@ -9,6 +9,7 @@ if portal is None:
document_list = portal.portal_catalog.getDocumentValueList(
reference=name,
language=language,
strict_language=strict_language,
now=now,
**kw
)
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>name, portal=None, language=None, now=None, **kw</string> </value>
<value> <string>name, portal=None, language=None, strict_language=False, now=None, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -75,10 +75,13 @@ try:
logical_operator='or',
)
if all_languages:
strict_language = False
if all_versions:
if not all_languages:
kw['language'] = language
if all_languages or not strict_language:
return search_context.searchResults(src__=src__, **kw)
else:
return search_context.searchResults(src__=src__, language=language, **kw)
else:
group_by_list = set(kw.get('group_by_list', []))
if all_languages:
......@@ -94,6 +97,7 @@ try:
for x in extra_column_set if not x.endswith('__score__'))
return context.SQLCatalog_zGetDocumentValueList(search_context=search_context,
language=language,
strict_language=strict_language,
all_languages=all_languages,
src__=src__,
kw=kw)
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>search_context=None, language=None, all_languages=None, all_versions=None, now=None, src__=0, **kw</string> </value>
<value> <string>search_context=None, language=None, strict_language=None, all_languages=None, all_versions=None, now=None, src__=0, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -57,8 +57,7 @@
<dtml-if selection_report>
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report)">
</dtml-if>
<dtml-if all_languages>
<dtml-else>
<dtml-if strict_language>
AND my_versioning.language IN (<dtml-sqlvar language type="string">, '')
</dtml-if>
......
......@@ -24,6 +24,7 @@
<key> <string>arguments_src</string> </key>
<value> <string>search_context\r\n
language\r\n
strict_language\r\n
all_languages\r\n
kw</string> </value>
</item>
......
......@@ -645,6 +645,13 @@ Hé Hé Hé!""", page.asText().strip())
self.assertEqual(5, len([w.getLanguage() for w in en_document_value_list \
if w.getLanguage() == 'ja']))
# Tests for strict_language=False
fallback_document_value_list = websection.getDocumentValueList(strict_language=False, language='ja')
self.assertEqual(
[('en', 'D'), ('ja', 'A'), ('ja', 'B'), ('ja', 'C'), ('ja', 'E'), ('pt', 'F')],
sorted([(x.getLanguage(), x.getReference()) for x in fallback_document_value_list])
)
# Tests for sort_on parameter
self.assertEqual(['A', 'B', 'C', 'D'],
[w.getReference() for w in \
......
......@@ -83,6 +83,8 @@ class TestNotificationMessageModule(ERP5TypeTestCase):
self.tic()
result = tool.getDocumentValue(reference='A')
self.assertEqual(result.getRelativeUrl(), n_m_en.getRelativeUrl())
result = tool.getDocumentValue(reference='A', language='fr')
self.assertEqual(result.getRelativeUrl(), n_m_en.getRelativeUrl())
#Same Document A in French
n_m_fr = module.newContent(portal_type='Notification Message',
reference='A',
......@@ -90,6 +92,8 @@ class TestNotificationMessageModule(ERP5TypeTestCase):
version='01')
n_m_fr.validate()
self.tic()
result = tool.getDocumentValue(reference='A')
self.assertEqual(result.getRelativeUrl(), n_m_en.getRelativeUrl())
result = tool.getDocumentValue(reference='A', language='fr')
self.assertEqual(result.getRelativeUrl(), n_m_fr.getRelativeUrl())
#Duplicate Document A French with upgraded version
......@@ -99,6 +103,8 @@ class TestNotificationMessageModule(ERP5TypeTestCase):
version='02')
n_m_fr_02.validate()
self.tic()
result = tool.getDocumentValue(reference='A')
self.assertEqual(result.getRelativeUrl(), n_m_en.getRelativeUrl())
result = tool.getDocumentValue(reference='A', language='fr')
self.assertEqual(result.getRelativeUrl(), n_m_fr_02.getRelativeUrl())
......
......@@ -1265,7 +1265,8 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
security.declarePublic('getDocumentValueList')
def getDocumentValueList(self, sql_catalog_id=None,
search_context=None, language=None, all_languages=None,
search_context=None, language=None,
strict_language=True, all_languages=None,
all_versions=None, now=None, **kw):
"""
Return the list of documents which belong to the
......@@ -1281,6 +1282,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
Here is the list of arguments :
* search_context
* language
* strict_language
* all_languages
* all_versions
* now
......@@ -1295,6 +1297,7 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
return catalog.SQLCatalog_getDocumentValueList(
search_context=search_context,
language=language,
strict_language=strict_language,
all_languages=all_languages,
all_versions=all_versions,
now=now,
......
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