Author: croberts
Date: 2012-12-04 16:24:56 +0000 (Tue, 04 Dec 2012)
New Revision: 5561
Modified:
trunk/cumin/python/cumin/objectselector.py
Log:
Fixing BZ 879330, Added new sqlfilter type to handle properly searching uptime values
(which are stored as bigint seconds from epoch, but displayed and searched in dd:hh:mm).
The new filter levels the playing field when searching against the database by truncating
the seconds.
Modified: trunk/cumin/python/cumin/objectselector.py
===================================================================
--- trunk/cumin/python/cumin/objectselector.py 2012-12-03 20:13:18 UTC (rev 5560)
+++ trunk/cumin/python/cumin/objectselector.py 2012-12-04 16:24:56 UTC (rev 5561)
@@ -446,8 +446,10 @@
self.adapter.query.add_filter(self.SelectableFieldDateValueFilter(sql_column,
searchvalue, operator))
elif sql_column.type.literal == "int8" or sql_column.type.literal ==
"float8":
if sql_column.name in self.special_columns:
+ #adjust our search value to be an int based on the timestamp
customvalue = str(fmt_ddhhmm_timestamp(customvalue))
- if sql_column.type.literal == "int8" or sql_column.type.literal ==
"float8":
+
self.adapter.query.add_filter(self.SelectableFieldUptimeValueFilter(sql_column,
operator))
+ if (sql_column.type.literal == "int8" or sql_column.type.literal
== "float8") and sql_column.name not in self.special_columns:
if operator == ">=":
self.adapter.query.add_filter(self.SelectableFieldValueFilter(sql_column,
">="))
elif operator == ">":
@@ -536,7 +538,23 @@
pass
class SelectableFieldDateValueFilter(SqlDateValueFilter, SelectableFieldFilter):
- pass
+ pass
+
+ class SelectableFieldUptimeValueFilter(SqlValueFilter, SelectableFieldFilter):
+ #necessary because we only show day:hour:minute to the user, but we store seconds
in
+ #the cumin database. This filter takes the value from the user, and
+ #searches it against the truncated value in the database
+ #This filter uses to_timestamp to go from the int to a timestamp, then
+ #does a date_trunc to remove anything after seconds, then does
+ #extract(epoch....) to get a value that can be fairly filtered against
+ #the user input.
+ def emit(self):
+ if self.gen_cursor and True in self.mogrify:
+ return self._mogrify()
+
+ return "extract(epoch from date_trunc('minute',
to_timestamp(%s))) %s %s" % (self.this,
+ self.operator,
+ self.that)
class ObjectCheckboxColumn(ObjectTableColumn):
def __init__(self, app, name, attr, selection):
Show replies by date