Commit fb61a34b authored by Noah Brackenbury's avatar Noah Brackenbury

Merge branch 'master' of https://lab.nexedi.com/nexedi/erp5 into business_bot

parents 3ef80952 a14279e5
...@@ -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'))
""" """
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.
The default implementation searches for
documents which are in the user language if any
and which reference is equal to the name parameter.
Other implementations are possible: ex. display the last
version in the closest language rather than
the latest version in the user language.
NOTE:
- the portal parameter was introduced to - the portal parameter was introduced to
fix acquisition issues within the _aq_dynamic fix acquisition issues within the _aq_dynamic
lookup from WebSection class. lookup from WebSection class.
""" """
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery if portal is None:
if portal is None: portal = context.getPortalObject() portal = context.getPortalObject()
portal_catalog = portal.portal_catalog document_list = portal.portal_catalog.getDocumentValueList(
# The list of portal types here should be large enough to include reference=name,
# all portal_types defined in the various sections so that language=language,
# href tags which point to a document by reference can still work. strict_language=strict_language,
valid_portal_type_list = portal.getPortalDocumentTypeList() now=now,
**kw
# Find the applicable language )
if language is None: if document_list:
language = portal.Localizer.get_selected_language() return document_list[0].getObject()
if validation_state is None:
validation_state = ('released', 'released_alive', 'published', 'published_alive',
'shared', 'shared_alive', 'public', 'validated')
if effective_date is None:
if now is None:
now = DateTime()
effective_date = ComplexQuery(
SimpleQuery(effective_date=None),
SimpleQuery(effective_date=now, comparison_operator='<='),
logical_operator='or',
)
# Note: In sorts, NULL is considered lesser than non-NULL. So in descending
# sort, NULLs will be listed after non-NULLs, which is perfect for
# effective_date, which defines the date at which content becomes effective.
# None (NULL) effective date hence means "effective since infinite in te past".
base_sort = (('effective_date', 'descending'), )
# Search the catalog for all documents matching the reference
# this will only return documents which are accessible by the user
web_page_list = portal_catalog(reference=name,
effective_date=effective_date,
portal_type=valid_portal_type_list,
validation_state=validation_state,
language=(language, ''),
sort_on=(('language', 'descending'), ) + base_sort,
limit=1,
**kw)
if len(web_page_list) == 0 and language != 'en':
# Search again with English as a fallback.
web_page_list = portal_catalog(reference=name,
effective_date=effective_date,
portal_type=valid_portal_type_list,
validation_state=validation_state,
language='en',
sort_on=base_sort,
limit=1,
**kw)
if len(web_page_list) == 0:
# Search again without the language
web_page_list = portal_catalog(reference=name,
effective_date=effective_date,
portal_type=valid_portal_type_list,
validation_state=validation_state,
sort_on=base_sort,
limit=1,
**kw)
if len(web_page_list) == 0:
# Default returns None
web_page = None
else:
# Try to get the first page on the list
web_page = web_page_list[0]
web_page = web_page.getObject()
# return the web page
return web_page
...@@ -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, validation_state=None, effective_date=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>
......
...@@ -52,10 +52,10 @@ try: ...@@ -52,10 +52,10 @@ try:
if not language: if not language:
language = portal.Localizer.get_selected_language() language = portal.Localizer.get_selected_language()
if 'portal_type' not in kw: if not kw.get('portal_type'):
kw['portal_type'] = portal.getPortalDocumentTypeList() kw['portal_type'] = portal.getPortalDocumentTypeList()
if 'validation_state' not in kw: if not kw.get('validation_state'):
# XXX hardcoded validation state list. # XXX hardcoded validation state list.
# Use predicate or layout property instead # Use predicate or layout property instead
kw['validation_state'] = ('released', 'released_alive', 'published', kw['validation_state'] = ('released', 'released_alive', 'published',
...@@ -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())
......
...@@ -1242,10 +1242,11 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -1242,10 +1242,11 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
db.query(r) db.query(r)
return src return src
# XXX which permission ? security.declarePublic('getDocumentValueList')
# XXX API parameters should be explicitly defined in interface def getDocumentValueList(self, sql_catalog_id=None,
# instead of **kw search_context=None, language=None,
def getDocumentValueList(self, **kw): strict_language=True, all_languages=None,
all_versions=None, now=None, **kw):
""" """
Return the list of documents which belong to the Return the list of documents which belong to the
current section. The API is designed to current section. The API is designed to
...@@ -1256,7 +1257,29 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -1256,7 +1257,29 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
This method must be implemented through a This method must be implemented through a
catalog method script : catalog method script :
SQLCatalog_getDocumentValueList SQLCatalog_getDocumentValueList
Here is the list of arguments :
* search_context
* language
* strict_language
* all_languages
* all_versions
* now
If you specify search_context, its predicate will be
respected,
i.e. web_section.WebSection_getDocumentValueList is
equivalent to
portal_catalog.getDocumentValueList(search_context=web_section)
""" """
return self.getSQLCatalog().SQLCatalog_getDocumentValueList(**kw) catalog = self.getSQLCatalog(sql_catalog_id)
return catalog.SQLCatalog_getDocumentValueList(
search_context=search_context,
language=language,
strict_language=strict_language,
all_languages=all_languages,
all_versions=all_versions,
now=now,
**kw)
InitializeClass(CatalogTool) InitializeClass(CatalogTool)
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