Mercurial > p > roundup > code
diff roundup/backends/rdbms_common.py @ 5318:506c7ee9a385
Add a 'retired' parameter to Class.filter
.. to allow searching for retired, non-retired or all (retired and
non-retired) items similar to the argument of the same name to
Class.getnodeids. This is 'False' by default (finding only non-retired
items for backwards compatibility) and can be set to None (for finding
retired and non-retired items) or True (for finding only retired items).
| author | Ralf Schlatterbeck <rsc@runtux.com> |
|---|---|
| date | Thu, 19 Apr 2018 20:01:43 +0200 |
| parents | 198b6e810c67 |
| children | 62de601bdf6f |
line wrap: on
line diff
--- a/roundup/backends/rdbms_common.py Thu Apr 19 17:03:11 2018 +0200 +++ b/roundup/backends/rdbms_common.py Thu Apr 19 20:01:43 2018 +0200 @@ -2381,7 +2381,8 @@ multilink_table, ','.join([self.db.arg] * len(v))) return where, v, True # True to indicate original - def _filter_sql (self, search_matches, filterspec, srt=[], grp=[], retr=0): + def _filter_sql (self, search_matches, filterspec, srt=[], grp=[], retr=0, + retired=False): """ Compute the proptree and the SQL/ARGS for a filter. For argument description see filter below. We return a 3-tuple, the proptree, the sql and the sql-args @@ -2650,7 +2651,11 @@ props = self.getprops() # don't match retired nodes - where.append('_%s.__retired__=0'%icn) + if retired is not None: + op = '=' + if retired: + op = '!=' + where.append('_%s.__retired__%s0'%(icn, op)) # add results of full text search if search_matches is not None: @@ -2688,7 +2693,8 @@ __traceback_info__ = (sql, args) return proptree, sql, args - def filter(self, search_matches, filterspec, sort=[], group=[]): + def filter(self, search_matches, filterspec, sort=[], group=[], + retired=False): """Return a list of the ids of the active nodes in this class that match the 'filter' spec, sorted by the group spec and then the sort spec @@ -2711,7 +2717,8 @@ if __debug__: start_t = time.time() - sq = self._filter_sql (search_matches, filterspec, sort, group) + sq = self._filter_sql (search_matches, filterspec, sort, group, + retired=retired) # nothing to match? if sq is None: return [] @@ -2734,7 +2741,8 @@ self.db.stats['filtering'] += (time.time() - start_t) return l - def filter_iter(self, search_matches, filterspec, sort=[], group=[]): + def filter_iter(self, search_matches, filterspec, sort=[], group=[], + retired=False): """Iterator similar to filter above with same args. Limitation: We don't sort on multilinks. This uses an optimisation: We put all nodes that are in the @@ -2743,7 +2751,8 @@ a join) from the database because the nodes are already in the cache. We're using our own temporary cursor. """ - sq = self._filter_sql(search_matches, filterspec, sort, group, retr=1) + sq = self._filter_sql(search_matches, filterspec, sort, group, retr=1, + retired=retired) # nothing to match? if sq is None: return
