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