Commit e322e0ac authored by Jérome Perrin's avatar Jérome Perrin

Define a scriptable key for translated_title

parent dbdb101e
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>from Products.ZSQLCatalog.SQLCatalog import Query, SimpleQuery, AndQuery\n
portal = context.getPortalObject()\n
\n
# This scriptable key supports content_translation if the table is present\n
catalog = portal.portal_catalog.getSQLCatalog()\n
if \'content_translation\' in catalog.getProperty(\'sql_search_tables\'):\n
return AndQuery(SimpleQuery(**{\'content_translation.translated_text\': value, \'comparison_operator\': \'match\'}),\n
Query(**{\'content_translation.property_name\': \'title\'}))\n
\n
# Otherwise it simply use title\n
return SimpleQuery(title=value)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>value</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SQLCatalog_makeTranslatedTitleQuery</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -3,4 +3,5 @@ ...@@ -3,4 +3,5 @@
<key>full_text | SQLCatalog_makeFullTextQuery</key> <key>full_text | SQLCatalog_makeFullTextQuery</key>
<key>quick_search_text | SQLCatalog_makeQuickSearchQuery</key> <key>quick_search_text | SQLCatalog_makeQuickSearchQuery</key>
<key>search_text | SQLCatalog_makeSearchTextQuery</key> <key>search_text | SQLCatalog_makeSearchTextQuery</key>
<key>translated_title | SQLCatalog_makeTranslatedTitleQuery</key>
</key_list> </key_list>
\ No newline at end of file
...@@ -3,6 +3,7 @@ erp5_mysql_innodb/SQLCatalog_catalogTransformationList ...@@ -3,6 +3,7 @@ erp5_mysql_innodb/SQLCatalog_catalogTransformationList
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
erp5_mysql_innodb/SQLCatalog_makeTranslatedTitleQuery
erp5_mysql_innodb/z0_drop_alarm erp5_mysql_innodb/z0_drop_alarm
erp5_mysql_innodb/z0_drop_catalog erp5_mysql_innodb/z0_drop_catalog
erp5_mysql_innodb/z0_drop_category erp5_mysql_innodb/z0_drop_category
......
quick_search_text | SQLCatalog_makeQuickSearchQuery quick_search_text | SQLCatalog_makeQuickSearchQuery
advanced_search_text | SQLCatalog_makeQuickSearchQuery advanced_search_text | SQLCatalog_makeQuickSearchQuery
full_text | SQLCatalog_makeFullTextQuery full_text | SQLCatalog_makeFullTextQuery
search_text | SQLCatalog_makeSearchTextQuery search_text | SQLCatalog_makeSearchTextQuery
\ No newline at end of file translated_title | SQLCatalog_makeTranslatedTitleQuery
\ No newline at end of file
...@@ -111,14 +111,47 @@ class TestContentTranslation(ERP5TypeTestCase): ...@@ -111,14 +111,47 @@ class TestContentTranslation(ERP5TypeTestCase):
result4 = portal.portal_catalog(content_translation_title='村岡') result4 = portal.portal_catalog(content_translation_title='村岡')
self.assertEquals(len(result4), 0) self.assertEquals(len(result4), 0)
# columns test # Low level columns test. This behaviour is not guaranteed. I'm not sure
# content_translation must be a search table - jerome
result5 = portal.portal_catalog(property_name='title') result5 = portal.portal_catalog(property_name='title')
self.assertEquals(len(result5), 2) self.assertEquals(len(result5), 2)
result6 = portal.portal_catalog(content_language='nob-read') result6 = portal.portal_catalog(content_language='nob-read')
self.assertEquals(len(result6), 2) self.assertEquals(len(result6), 2)
result7 = portal.portal_catalog(translated_text='XXX YYY') result7 = portal.portal_catalog(translated_text='XXX YYY')
self.assertEquals(len(result7), 1) self.assertEquals(len(result7), 1)
def testCatalogSearchTranslatedTitleScriptableKey(self):
# Test 'translated_title' scriptable key.
portal = self.portal
portal.Localizer._add_user_defined_language('Nobody Readable', 'nob-read')
portal.Localizer.add_language('nob-read')
self.tic()
person = portal.person_module.newContent(portal_type='Person',
first_name='Yusuke',
last_name='Muraoka')
person.setNobReadTranslatedFirstName('友介')
person.setNobReadTranslatedLastName('村岡')
self.tic()
# We can search either by the translated title
self.assertEquals(person,
portal.portal_catalog.getResultValue(translated_title='友介'))
# Or the original title
self.assertEquals(person,
portal.portal_catalog.getResultValue(translated_title='Yusuke'))
# documents for which translation is not set can also be found with
# translated_title key
not_translated_person = portal.person_module.newContent(portal_type='Person',
first_name='Jérome',
last_name='Perrin')
self.tic()
self.assertEquals(not_translated_person,
portal.portal_catalog.getResultValue(translated_title='Jérome'))
def testContentTranslation(self): def testContentTranslation(self):
""" """
Make sure that translatable properties can have content translation into Make sure that translatable properties can have content translation into
......
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