From 49e28585480f2278f51d087ce956a795484f9c95 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 15 May 2012 13:43:35 +0530 Subject: [PATCH 1/2] force decode search string in search box/link field using utf-8, since utf-8 is the default charset of content via http. This makes searching in other languages possible for old search widget and link fields. --- py/webnotes/widgets/search.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/py/webnotes/widgets/search.py b/py/webnotes/widgets/search.py index f85254e571..a69d6eb33d 100644 --- a/py/webnotes/widgets/search.py +++ b/py/webnotes/widgets/search.py @@ -49,7 +49,7 @@ def getsearchfields(): webnotes.response['searchfields'] = [['name', 'ID', 'Data', '']] + res def make_query(fields, dt, key, txt, start, length): - return """SELECT %(fields)s + query = """SELECT %(fields)s FROM `tab%(dt)s` WHERE `tab%(dt)s`.`%(key)s` LIKE '%(txt)s' AND `tab%(dt)s`.docstatus != 2 ORDER BY `tab%(dt)s`.`%(key)s` @@ -61,6 +61,7 @@ def make_query(fields, dt, key, txt, start, length): 'start': start, 'len': length } + return query def get_std_fields_list(dt, key): # get additional search fields @@ -102,6 +103,12 @@ def search_link(): txt = webnotes.form.getvalue('txt') dt = webnotes.form.getvalue('dt') query = webnotes.form.getvalue('query') + + # txt - decode it to utf-8. why to do this? + # "%(something_unicode)s %(something ascii encoded with utf-8)s" + # tries to decode ascii string using ascii codec and not utf-8 + # since web pages are encoded in utf-8, we can force decode to utf-8 + txt = txt.decode('utf-8') if query: res = webnotes.conn.sql(scrub_custom_query(query, 'name', txt)) @@ -122,6 +129,12 @@ def search_widget(): key = webnotes.form.getvalue('searchfield') or 'name' # key field user_query = webnotes.form.getvalue('query') or '' + # txt - decode it to utf-8. why to do this? + # "%(something_unicode)s %(something ascii encoded with utf-8)s" + # tries to decode ascii string using ascii codec and not utf-8 + # since web pages are encoded in utf-8, we can force decode to utf-8 + txt = txt.decode('utf-8') + if user_query: query = scrub_custom_query(user_query, key, txt) else: From f57f5bcff2243276e7739572d9678165e22d8632 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 15 May 2012 14:01:11 +0530 Subject: [PATCH 2/2] do not sync search criteria, print format, doctype mapper --- py/webnotes/model/sync.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/webnotes/model/sync.py b/py/webnotes/model/sync.py index 759f1aea33..c900096597 100644 --- a/py/webnotes/model/sync.py +++ b/py/webnotes/model/sync.py @@ -49,7 +49,7 @@ def walk_and_sync(start_path, force=0): if doctype == 'doctype': sync(module_name, name, force) - elif doctype in ['page', 'search_criteria', 'Print Format', 'DocType Mapper']: + elif doctype in ['page']:#, 'search_criteria', 'Print Format', 'DocType Mapper']: reload_doc(module_name, doctype, name) print module_name + ' | ' + doctype + ' | ' + name