From 266cad9a2eabf10dccd2b7ca11571b7f41e6705f Mon Sep 17 00:00:00 2001 From: Vo Minh Thu Date: Fri, 22 Jul 2011 10:10:30 +0200 Subject: [PATCH] [IMP] unaccent: added an unaccent command-line flag, and a function to test unaccent availability. bzr revid: vmt@openerp.com-20110722081030-ltxuqknpe1arduw5 --- openerp/modules/db.py | 10 ++++++++++ openerp/modules/registry.py | 5 +++++ openerp/tools/config.py | 2 ++ 3 files changed, 17 insertions(+) diff --git a/openerp/modules/db.py b/openerp/modules/db.py index 25ce7283c97..2e61212925c 100644 --- a/openerp/modules/db.py +++ b/openerp/modules/db.py @@ -118,4 +118,14 @@ def create_categories(cr, categories): categories = categories[1:] return p_id +def has_unaccent(cr): + """ Test if the database has an unaccent function. + + The unaccent is supposed to be provided by the PostgreSQL unaccent contrib + module but any similar function will be picked by OpenERP. + + """ + cr.execute("SELECT proname FROM pg_proc WHERE proname='unaccent'") + return len(cr.fetchall()) > 0 + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/openerp/modules/registry.py b/openerp/modules/registry.py index 11f484a71a0..bc80a7bc354 100644 --- a/openerp/modules/registry.py +++ b/openerp/modules/registry.py @@ -25,6 +25,7 @@ import openerp.sql_db import openerp.osv.orm +import openerp.modules.db class Registry(object): @@ -44,6 +45,10 @@ class Registry(object): self.db_name = db_name self.db = openerp.sql_db.db_connect(db_name) + cr = self.db.cursor() + self.has_unaccent = openerp.modules.db.has_unaccent(cr) + cr.close() + def do_parent_store(self, cr): for o in self._init_parent: self.get(o)._parent_store_compute(cr) diff --git a/openerp/tools/config.py b/openerp/tools/config.py index 18f40e0011f..b09ef040cea 100644 --- a/openerp/tools/config.py +++ b/openerp/tools/config.py @@ -250,6 +250,8 @@ class configmanager(object): "osv_memory tables. This is a decimal value expressed in hours, " "and the default is 1 hour.", type="float") + group.add_option("--unaccent", dest="unaccent", my_default=False, + help="Use the unaccent function provided by the database when available.") parser.add_option_group(group) # Copy all optparse options (i.e. MyOption) into self.options.