dabo Commit
Revision 7101
Date: 2012-02-17 12:13:35 -0800 (Fri, 17 Feb 2012)
Author: Paul
Trac: http://trac.dabodev.com/changeset/7101
Changed:
U trunk/dabo/biz/dBizobj.py
U trunk/dabo/db/dCursorMixin.py
Log:
Added explicit support for multiple-field search in seek() and locate(). This
was working before but you had to craft your call like:
biz.locate(("CA", "Hollister"), "state, city")
This commit simply makes it more consistent by allowing a tuple for the flds:
biz.locate(("CA", "Hollister"), ("state", "city"))
Plus it documents the ability to search multiple fields.
Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py 2012-02-17 20:10:06 UTC (rev 7100)
+++ trunk/dabo/biz/dBizobj.py 2012-02-17 20:13:35 UTC (rev 7101)
@@ -1476,6 +1476,8 @@
Search for a value in a field, and optionally move the record
pointer to the first
matching record. Returns the True or False, depending on
whether the value was found.
+ Multiple fields can be searched by sending tuples as the val
and fld arguments.
+
If runRequery is True, and the record pointer is moved, all
child bizobjs
will be requeried, and the afterPointerMove() hook method will
fire.
@@ -1495,6 +1497,8 @@
sort=True, incremental=False):
"""
Search for a value in a field, and move the record pointer to
the match.
+ Multiple fields can be searched by sending tuples for the val
and fld
+ arguments.
Used for searching of the bizobj's cursor for a particular
value in a
particular field. Can be optionally case-sensitive.
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py 2012-02-17 20:10:06 UTC (rev 7100)
+++ trunk/dabo/db/dCursorMixin.py 2012-02-17 20:13:35 UTC (rev 7101)
@@ -2108,6 +2108,8 @@
"""
Find the first row where the field value matches the passed
value.
+ Multiple fields can be searched by sending tuples as the val
and fld arguments.
+
Returns True or False, depending on whether a matching value
was located.
If 'fld' is not specified, the current sortColumn is used. If
'caseSensitive' is
set to False, string comparisons are done in a case-insensitive
fashion.
@@ -2123,7 +2125,7 @@
def seek(self, val, fld=None, caseSensitive=True, near=False,
movePointer=True,
sort=True, incremental=False):
"""
- Find the first row where the field value matches the passed
value.
+ Find the first row where the field value matches the passed
value.
Returns the row number of the first record that matches the
passed
value in the designated field, or -1 if there is no match. If
'near' is
@@ -2136,6 +2138,9 @@
If incremental is True (default is False), then we only compare
the first
characters up until the length of val.
+
+ Multiple fields can be searched by sending tuples for the val
and fld
+ arguments.
"""
ret = -1
if fld is None:
@@ -2148,11 +2153,17 @@
if not fld:
raise dException.FieldNotFoundException(_("No field
specified for seek()"))
- simpleKey = ("," not in fld)
- if simpleKey:
- flds = [fld]
+ if isinstance(fld, list) or isinstance(fld, tuple):
+ simpleKey = (len(fld) == 1)
+ flds = fld
+ fld = flds[0]
else:
- flds = [f.strip() for f in fld.split(",")]
+ simpleKey = ("," not in fld)
+ if simpleKey:
+ flds = [fld]
+ else:
+ flds = [f.strip() for f in fld.split(",")]
+
badflds = []
for fldname in flds:
if (fldname not in self._records[0]) and (fldname not
in self.VirtualFields):
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message:
http://leafe.com/archives/byMID/[email protected]