dabo Commit
Revision 6858
Date: 2011-09-26 14:09:45 -0700 (Mon, 26 Sep 2011)
Author: Paul
Trac: http://trac.dabodev.com/changeset/6858
Changed:
U trunk/dabo/biz/dBizobj.py
U trunk/dabo/db/dCursorMixin.py
Log:
Added 'sort' and 'incremental' arguments to seek(). Setting sort to False (the
default is still True) will keep the list in the current sort order, and so
return the next matching value in the current order.
Setting incremental to True (the default is still False), will compare strings
a little differently, only matching the first characters up to the length of
the string value passed.
Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py 2011-09-26 16:37:55 UTC (rev 6857)
+++ trunk/dabo/biz/dBizobj.py 2011-09-26 21:09:45 UTC (rev 6858)
@@ -1446,7 +1446,8 @@
return ret
- def seek(self, val, fld=None, caseSensitive=False, near=False,
runRequery=True):
+ def seek(self, val, fld=None, caseSensitive=False, near=False,
runRequery=True,
+ sort=True, incremental=False):
"""
Search for a value in a field, and move the record pointer to
the match.
@@ -1461,9 +1462,16 @@
If runRequery is True, and the record pointer is moved, all
child bizobjs
will be requeried, and the afterPointerMove() hook method will
fire.
+ If sort is True (the default), then we seek to the first
matching value
+ without sorting first.
+
+ If incremental is True (default is False), then we only compare
the first
+ characters up until the length of val.
+
Returns the RowNumber of the found record, or -1 if no match
found.
"""
- ret = self._CurrentCursor.seek(val, fld, caseSensitive, near)
+ ret = self._CurrentCursor.seek(val, fld, caseSensitive, near,
+ sort=sort, incremental=incremental)
if ret != -1:
if runRequery:
self.requeryAllChildren()
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py 2011-09-26 16:37:55 UTC (rev 6857)
+++ trunk/dabo/db/dCursorMixin.py 2011-09-26 21:09:45 UTC (rev 6858)
@@ -2109,7 +2109,8 @@
return (recnum > -1)
- def seek(self, val, fld=None, caseSensitive=True, near=False,
movePointer=True):
+ 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.
@@ -2118,6 +2119,12 @@
True, a match will happen on the row whose value is the
greatest value
that is less than the passed value. If 'caseSensitive' is set
to False,
string comparisons are done in a case-insensitive fashion.
+
+ If sort is True (the default), then we seek to the first
matching value
+ without sorting first.
+
+ If incremental is True (default is False), then we only compare
the first
+ characters up until the length of val.
"""
ret = -1
if fld is None:
@@ -2179,10 +2186,11 @@
except ValueError:
val = float(0)
- if compString and not caseSensitive:
- sortList.sort(key=caseInsensitiveSortKey)
- else:
- sortList.sort()
+ if sort:
+ if compString and not caseSensitive:
+ sortList.sort(key=caseInsensitiveSortKey)
+ else:
+ sortList.sort()
if compString and not caseSensitive:
# Change all of the first elements to lower case
@@ -2207,13 +2215,29 @@
ret = sortList[idx][1]
except ValueError:
if near:
- # Find the first row greater than the match
value
- numSmaller = len([testVal for testVal in
searchList
- if testVal < matchVal])
- try:
- ret = sortList[numSmaller][1]
- except IndexError:
+ if incremental:
+ # Match the next string only taking
into account the first characters
+ # up to the length of matchStr (so that
seeking for 'AB' will bring up
+ # 'AB-PC' instead of 'FW-PC'.
+
ret = len(sortList) - 1
+ for idx, testVal in
enumerate(searchList):
+ if isinstance(testVal,
basestring) and isinstance(matchVal, basestring):
+ if len(testVal) >=
len(matchVal) and testVal[:len(matchVal)] == matchVal:
+ ret =
sortList[idx][1]
+ break
+ elif not isinstance(matchVal,
basestring) and testVal > matchVal:
+ ret = idx
+ break
+ else:
+ # Find the first row greater than the
match value
+ numSmaller = len([testVal for testVal
in searchList
+ if testVal < matchVal])
+ try:
+ ret = sortList[numSmaller][1]
+ except IndexError:
+ ret = len(sortList) - 1
+
if movePointer and ret > -1:
# Move the record pointer
self.RowNumber = ret
_______________________________________________
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]