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

handle provided key= to Query constructor even if the query value is a list

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@22219 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7dd18f16
master ERP5ify-portal_workfow_yusei_20210303 UpdateValidationStateFromConsistency addToDate_implicit_localtime allow_login_change allow_login_change_wip arnau arnau-RD-Components-CacheTool arnau-RD-Components-ERP5Form-ERP5Report arnau-RD-Components-ERP5Form-SelectionTool-MemcachedTool arnau-RD-Components-ERP5OOo arnau-RD-Components-PreferenceTool-Preference arnau-RD-Components-Products-import-compat arnau-RD-Components-astroid_cache_per_component_reset arnau-RD-Components-erp5_crm arnau-RD-Components-erp5_trade-TODO-Interactor arnau-RD-ERP5ify-portal_workflow arnau-RD-ERP5ify-portal_workflow-1-seb-merged-with-recent-master arnau-RD-ERP5ify-portal_workflow-2-do-not-rename-erp5_workflow-portal_types arnau-RD-ERP5ify-portal_workflow-BAK arnau-RD-ERP5ify-portal_workflow-WIP arnau-RD-ERP5ify-portal_workflow-WITHOUT-MIGRATION arnau-RD-ERP5ify-portal_workflow-WORKFLOWS-NOT-MIGRATED arnau-TM-Components-Migrate-PortalTransforms arnau-TM-Components-ModuleSecurityInfo arnau-TM-FEC-output arnau-TM-WIP arnau-TM-isBuildable-with-multiple-BusinessLinks arnau-TM-newContent-temp_object arnau-TM-runUnitTest-clear-previous-execution-catalog arnau-TM-wkhtmltopdf arnau-WIP arnau-kns arnau-kns-without-property-mapping arnau-merge arnau-poc arnau-real-time-inventory-accounting auto_extend_select_list autoflake backup_erp5_workflow bk_erp5ish_actions_tool bk_sqlcatalog boc-interaction-drop bt5_config cache cache-control-304-response callable-jupyter-storage catalog_filter catalog_fulltext catalog_fulltext_old cedric cedriclen cedriclen-eos certificate_authority cherry-pick-4a8e045d cleanJSByJSLint clean_up_upgrader cleanup_acquisition_base_category cloud_reliability_test credential_update_action cribjs-bootloader datetimefield deferred_listbox delivery_item_barcode douglas_forum dream_distributor dsn-phase3 enhance_scalability_testing eos-dev erp5-component erp5-component-bak erp5-forum erp5-imt erp5-messenger erp5-preference erp5-release erp5-slapos-upgrade erp5-util-testing erp5-vifib erp5-vifib-cleanup erp5_calendar erp5_catalog erp5_catalog_final erp5_corporate_identity erp5_free_subscription erp5_hal_json_style_fix_restricted_access_with_traverse erp5_payslip_migration erp5_workflow erp5testnode_max_timeout feat/dms_implicit_predecessor_successor_fields feat/erp5_ide feat/generate_report_ERP5JS feat/inventory_api_group_by_time_interval_list feat/notification-message-ignore-missing feat/olapy feat/python_language_support feat/show_user_on_logout_page feat/zopewsgi-start-timerserver feature/renderjs-ui-no-header fix-ftp-putFile fix/ZMI_editor_preference fix/advance_ecommerce_coding_crimes fix/business-template-update-tool fix/cmf_activity_global_request fix/getParent fix/login_validate_check_consistency fix/support-request-app-empty fix/test_result_after_mep fix/web_page_officejs_duplicate_actions fix/workflow_method_security fix_web_illustration for_testrunner_1 for_testrunner_2 for_testrunner_3 gabriel gadget-json-value graphic_gadget_js hotfix/rjs-formfields-padding improve_default_caching_policy_manager initsite interaction-drop inventory isDeletable ivan jerome-bt-reference-doc jerome_graph_editor_renderjs jerome_user_preference_time_zone jio jm/form-action-guard js-ui kns lazy_simulation_causality lignan limit_accelerated_http_cache_manager lingnan listbox_url lle-bout/metadata-modules macros_fix mame-test-stock-indexation master-erp5-test-result-scalability master-erp5-test-result-scalability-rebase master-test-fix-additionalbt5path master_w mic_wind monitoring-graph mr1362 mrp my2to3 new-render-presentation nicolas-slice-price no_longer_simulated_state notebook_roque officejs override_cache_control_header_by_caching_policy_manager pere poc/json-forms-study portal_callables portal_solver_process_security_configuration presentation publish_recursiveReindexObject rebased_mrp refactor/base_edit reindex_calendar_after_change_calendar_exception restore-from-trashbin revert-38554dbe rjs_listbox_sort_icon scalability-master scalability-master2 scalability-master2-rebase scalability-roque scalability-roque-2 scalability-run-command scalability_crash_mariadb shop-box shop-box-rebase streaming_fix streaming_fix-0 support_relative_url_in_hyperlink_field support_request syncml taskdistribution-xmlrpc-binary test-renderjs-float-field-step test_page testnode_software_link timezones tristan tristan-merge tristan-performance trustable-x-forwarded-for ttrm unify_predicate_edit valentin_translation_fix view-aggregated-amounts vivekpab_renderjs_interfaces wenjie wenjie_branch wsgi wsgi-gevent wsgi_backport_setbody_lock wsgi_medusa_stream_fix yryr yryr-components-cp yryr-inventory-cache yryr-test yryr-with-components yusei yusei_20210303 0.4.59.1 0.4.59 test-ui test-rjsacc test-rjs renderjs-test nexedi-erp5-vifib-20201105 erp5.util-0.4.72 erp5.util-0.4.71 erp5.util-0.4.69 erp5.util-0.4.68 erp5.util-0.4.67 erp5.util-0.4.66 erp5.util-0.4.65 erp5.util-0.4.64 erp5.util-0.4.63 erp5.util-0.4.62 erp5.util-0.4.61 erp5.util-0.4.60 erp5.util-0.4.59.1 erp5.util-0.4.59 erp5.util-0.4.58 erp5.util-0.4.57 erp5.util-0.4.56 erp5.util-0.4.55 erp5.util-0.4.54 erp5.util-0.4.53 erp5.util-0.4.52 erp5.util-0.4.49 erp5.util-0.4.46 erp5.util-0.4.44 erp5.util-0.4.43 erp5.util-0.4.41 erp5.util-0.4.40 erp5.util-0.4.37 erp5.util-0.4.1 erp5.util-0.4 erp5.util-0.3 erp5.util-0.2 erp5.util-0.1 erp5-vifib-20210707 erp5-vifib-20201229 erp5-vifib-20200129
No related merge requests found
......@@ -179,6 +179,24 @@ class SimpleQuery(QueryMixin):
sql_expressions = {'where_expression': '1',
'select_expression_list': []}
# try to get search key type by the key definitions passed
if search_key_class is None:
if search_key == EXACT_MATCH_SEARCH_MODE:
search_key_class = RawKey
elif search_key == KEYWORD_SEARCH_MODE or \
(key in keyword_search_keys):
search_key_class = KeyWordKey
elif search_key == DATETIME_SEARCH_MODE or \
(key in datetime_search_keys):
search_key_class = DateTimeKey
elif search_key == FULL_TEXT_SEARCH_MODE or \
(key in full_text_search_keys):
search_key_class = FullTextKey
# get search class based on explicitly passed key type
if search_key_class is None:
search_key_class = self._getSearchKeyClassByType(type)
# some use cases where we can just return SQL without grammar staff
if key is None or (ignore_empty_string and \
isinstance(value, basestring) and \
......@@ -197,9 +215,6 @@ class SimpleQuery(QueryMixin):
sql_expressions = {'where_expression': "%s is NULL" % (key),
'select_expression_list': [],}
return sql_expressions
# get search class based on explicitly passed key type
if search_key_class is None:
search_key_class = self._getSearchKeyClassByType(type)
# we have a list of values and respective operator defined
if isinstance(value, (tuple, list)):
......@@ -259,20 +274,6 @@ class SimpleQuery(QueryMixin):
# try to guess by type of first_element in list
search_key_class = self._getSearchKeyClassByValue(value[0])
# try to get search key type by the key definitions passed
if search_key_class is None:
if search_key == EXACT_MATCH_SEARCH_MODE:
search_key_class = RawKey
elif search_key == KEYWORD_SEARCH_MODE or \
(key in keyword_search_keys):
search_key_class = KeyWordKey
elif search_key == DATETIME_SEARCH_MODE or \
(key in datetime_search_keys):
search_key_class = DateTimeKey
elif search_key == FULL_TEXT_SEARCH_MODE or \
(key in full_text_search_keys):
search_key_class = FullTextKey
# get search class based on value of value
if search_key_class is None:
search_key_class = self._getSearchKeyClassByValue(value)
......
......@@ -416,6 +416,21 @@ class TestQuery(unittest.TestCase):
select_expression_list=[]),
q.asSQLExpression())
def testListValuesInQuery(self):
q = Query(title=('Foo', 'Bar'))
self.assertEquals(
dict(where_expression="(((((title = 'Foo')))) OR ((((title = 'Bar')))))",
select_expression_list=[]),
q.asSQLExpression())
def testListValuesInQueryWithKey(self):
q = Query(title=('Foo', 'Bar'), key='Keyword')
self.assertEquals(
dict(where_expression=
"(((((title LIKE '%Foo%')))) OR ((((title LIKE '%Bar%')))))",
select_expression_list=[]),
q.asSQLExpression())
def test_suite():
suite = unittest.TestSuite()
......
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