From 111bcd404dba914ebbb25ac20cd8ec038e1c25a1 Mon Sep 17 00:00:00 2001 From: schlatterbeck Date: Fri, 5 Mar 2010 15:51:11 +0000 Subject: [PATCH] - unify bool searching (filter method) across backends git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/roundup/trunk@4471 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/backends/back_anydbm.py | 6 ++++-- roundup/backends/rdbms_common.py | 18 +++++++++++++++++ test/db_test_base.py | 33 +++++++++++++++++++++++++++++--- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/roundup/backends/back_anydbm.py b/roundup/backends/back_anydbm.py index 90cf05e..baa389b 100644 --- a/roundup/backends/back_anydbm.py +++ b/roundup/backends/back_anydbm.py @@ -1630,12 +1630,14 @@ class Class(hyperdb.Class): pass elif isinstance(propclass, hyperdb.Boolean): - if type(v) != type([]): + if type(v) == type(""): v = v.split(',') + if type(v) != type([]): + v = [v] bv = [] for val in v: if type(val) is type(''): - bv.append(val.lower() in ('yes', 'true', 'on', '1')) + bv.append(propclass.from_raw (val)) else: bv.append(val) l.append((OTHER, k, bv)) diff --git a/roundup/backends/rdbms_common.py b/roundup/backends/rdbms_common.py index a95493a..6942a78 100644 --- a/roundup/backends/rdbms_common.py +++ b/roundup/backends/rdbms_common.py @@ -2330,6 +2330,24 @@ class Class(hyperdb.Class): pass if p.sort_type > 0: oc = ac = '_%s.__%s_int__'%(pln,k) + elif isinstance(propclass, Boolean) and p.sort_type < 2: + if type(v) == type(""): + v = v.split(',') + if type(v) != type([]): + v = [v] + bv = [] + for val in v: + if type(val) is type(''): + bv.append(propclass.from_raw (val)) + else: + bv.append(bool(val)) + if len(bv) == 1: + where.append('_%s._%s=%s'%(pln, k, a)) + args = args + bv + else: + s = ','.join([a for x in v]) + where.append('_%s._%s in (%s)'%(pln, k, s)) + args = args + bv elif p.sort_type < 2: if isinstance(v, type([])): s = ','.join([a for x in v]) diff --git a/test/db_test_base.py b/test/db_test_base.py index 4f68b79..0751216 100644 --- a/test/db_test_base.py +++ b/test/db_test_base.py @@ -1086,9 +1086,9 @@ class DBTest(MyTestCase): def filteringSetup(self): for user in ( - {'username': 'bleep', 'age': 1}, - {'username': 'blop', 'age': 1.5}, - {'username': 'blorp', 'age': 2}): + {'username': 'bleep', 'age': 1, 'assignable': True}, + {'username': 'blop', 'age': 1.5, 'assignable': True}, + {'username': 'blorp', 'age': 2, 'assignable': False}): self.db.user.create(**user) iss = self.db.issue file_content = ''.join([chr(i) for i in range(255)]) @@ -1116,6 +1116,33 @@ class DBTest(MyTestCase): ae(filt(None, {'id': '2'}, ('+','id'), (None,None)), ['2']) ae(filt(None, {'id': '100'}, ('+','id'), (None,None)), []) + def testFilteringBoolean(self): + self.filteringSetup() + ae, filt = self.assertEqual, self.db.user.filter + a = 'assignable' + ae(filt(None, {a: '1'}, ('+','id'), (None,None)), ['3','4']) + ae(filt(None, {a: '0'}, ('+','id'), (None,None)), ['5']) + ae(filt(None, {a: ['1']}, ('+','id'), (None,None)), ['3','4']) + ae(filt(None, {a: ['0']}, ('+','id'), (None,None)), ['5']) + ae(filt(None, {a: ['0','1']}, ('+','id'), (None,None)), ['3','4','5']) + ae(filt(None, {a: 'True'}, ('+','id'), (None,None)), ['3','4']) + ae(filt(None, {a: 'False'}, ('+','id'), (None,None)), ['5']) + ae(filt(None, {a: ['True']}, ('+','id'), (None,None)), ['3','4']) + ae(filt(None, {a: ['False']}, ('+','id'), (None,None)), ['5']) + ae(filt(None, {a: ['False','True']}, ('+','id'), (None,None)), + ['3','4','5']) + ae(filt(None, {a: True}, ('+','id'), (None,None)), ['3','4']) + ae(filt(None, {a: False}, ('+','id'), (None,None)), ['5']) + ae(filt(None, {a: 1}, ('+','id'), (None,None)), ['3','4']) + ae(filt(None, {a: 0}, ('+','id'), (None,None)), ['5']) + ae(filt(None, {a: [1]}, ('+','id'), (None,None)), ['3','4']) + ae(filt(None, {a: [0]}, ('+','id'), (None,None)), ['5']) + ae(filt(None, {a: [0,1]}, ('+','id'), (None,None)), ['3','4','5']) + ae(filt(None, {a: [True]}, ('+','id'), (None,None)), ['3','4']) + ae(filt(None, {a: [False]}, ('+','id'), (None,None)), ['5']) + ae(filt(None, {a: [False,True]}, ('+','id'), (None,None)), + ['3','4','5']) + def testFilteringNumber(self): self.filteringSetup() ae, filt = self.assertEqual, self.db.user.filter -- 2.30.2