changeset 2494:ea7fb2f416db

fixed RDBMS Class.find() to handle None value in multiple find... ...and a merge from maint-0-7
author Richard Jones <richard@users.sourceforge.net>
date Wed, 23 Jun 2004 23:19:07 +0000
parents fa871d7a3a0f
children 682eefe8ef23
files CHANGES.txt roundup/admin.py roundup/backends/rdbms_common.py test/db_test_base.py
diffstat 4 files changed, 28 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Tue Jun 22 23:39:08 2004 +0000
+++ b/CHANGES.txt	Wed Jun 23 23:19:07 2004 +0000
@@ -27,6 +27,8 @@
 - better roundup-server usage string (sf bug 973352)
 - include "context" always, as documented (sf bug 965447)
 - fixed REMOTE_USER (external HTTP Basic auth) (sf bug 977309)
+- fixed roundup-admin "find" to use better value parsing
+- fixed RDBMS Class.find() to handle None value in multiple find
 
 
 2004-06-10 0.7.4
--- a/roundup/admin.py	Tue Jun 22 23:39:08 2004 +0000
+++ b/roundup/admin.py	Wed Jun 23 23:19:07 2004 +0000
@@ -16,7 +16,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 #
-# $Id: admin.py,v 1.72 2004-06-13 00:27:45 richard Exp $
+# $Id: admin.py,v 1.73 2004-06-23 23:19:07 richard Exp $
 
 '''Administration commands for maintaining Roundup trackers.
 '''
@@ -617,32 +617,15 @@
         # handle the propname=value argument
         props = self.props_from_args(args[1:])
 
-        # if the value isn't a number, look up the linked class to get the
-        # number
+        # convert the user-input value to a value used for find()
         for propname, value in props.items():
-            num_re = re.compile('^\d+$')
-            if value == '-1':
-                props[propname] = None
-            elif not num_re.match(value):
-                # get the property
-                try:
-                    property = cl.properties[propname]
-                except KeyError:
-                    raise UsageError, _('%(classname)s has no property '
-                        '"%(propname)s"')%locals()
-
-                # make sure it's a link
-                if (not isinstance(property, hyperdb.Link) and not
-                        isinstance(property, hyperdb.Multilink)):
-                    raise UsageError, _('You may only "find" link properties')
-
-                # get the linked-to class and look up the key property
-                link_class = self.db.getclass(property.classname)
-                try:
-                    props[propname] = link_class.lookup(value)
-                except TypeError:
-                    raise UsageError, _('%(classname)s has no key property')%{
-                        'classname': link_class.classname}
+            if ',' in value:
+                values = value.split(',')
+            else:
+                values = []
+            d = props[propname] = {}
+            for value in values:
+                d[hyperdb.rawToHyperdb(self.db, cl, None, propname, value)] = 1
 
         # now do the find
         try:
--- a/roundup/backends/rdbms_common.py	Tue Jun 22 23:39:08 2004 +0000
+++ b/roundup/backends/rdbms_common.py	Wed Jun 23 23:19:07 2004 +0000
@@ -1,4 +1,4 @@
-# $Id: rdbms_common.py,v 1.110 2004-06-16 03:54:00 richard Exp $
+# $Id: rdbms_common.py,v 1.111 2004-06-23 23:19:07 richard Exp $
 ''' Relational database (SQL) backend common code.
 
 Basics:
@@ -1952,8 +1952,14 @@
             elif values is None:
                 where.append('_%s is NULL'%prop)
             else:
-                allvalues += tuple(values.keys())
-                where.append('_%s in (%s)'%(prop, ','.join([a]*len(values))))
+                values = values.keys()
+                s = ''
+                if None in values:
+                    values.remove(None)
+                    s = '_%s is NULL or '%prop
+                allvalues += tuple(values)
+                s += '_%s in (%s)'%(prop, ','.join([a]*len(values)))
+                where.append(s)
         tables = ['_%s'%self.classname]
         if where:
             o.append('(' + ' and '.join(where) + ')')
--- a/test/db_test_base.py	Tue Jun 22 23:39:08 2004 +0000
+++ b/test/db_test_base.py	Wed Jun 23 23:19:07 2004 +0000
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: db_test_base.py,v 1.32 2004-06-16 03:54:00 richard Exp $ 
+# $Id: db_test_base.py,v 1.33 2004-06-23 23:19:07 richard Exp $ 
 
 import unittest, os, shutil, errno, imp, sys, time, pprint
 
@@ -757,6 +757,13 @@
         got.sort()
         self.assertEqual(got, [one, three])
 
+    def testFindMultipleLink(self):
+        one, two, three, four = self._find_test_setup()
+        self.assertEqual(self.db.issue.find(status={'1':1, '3':1}),
+            [one, three, four])
+        self.assertEqual(self.db.issue.find(assignedto={None:1, '1':1}),
+            [one, three, four])
+
     def testFindMultilink(self):
         one, two, three, four = self._find_test_setup()
         got = self.db.issue.find(nosy='2')

Roundup Issue Tracker: http://roundup-tracker.org/