svn keywords
[plcapi.git] / PLC / EventObjects.py
index d96b901..3bd4cc9 100644 (file)
@@ -4,7 +4,8 @@
 # Tony Mack <tmack@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
-# $Id: EventObjects.py,v 1.1 2007/02/27 18:54:32 tmack Exp $
+# $Id$
+# $URL$
 #
 
 from PLC.Faults import *
@@ -42,35 +43,22 @@ class EventObjects(Table):
     def __init__(self, api, event_filter = None, columns = None):
         Table.__init__(self, api, EventObject, columns)
        
-       # Since we are querying a table (not a view) ensure that timestamps
-       # are converted to ints in the db before being returned
-       timestamps = ['time']
-       for col in self.columns:
-           if col in timestamps:
-               if isinstance(self.columns, (list, tuple, set)): 
-                   index = self.columns.index(col)
-                   self.columns[index] = "CAST(date_part('epoch', events.time) AS bigint) AS time"
-               elif isinstance(self.columns, dict):
-                   type = self.columns.pop(col)
-                   self.columns["CAST(date_part('epoch', events.time) AS bigint) AS time"] = type
-           elif col in [EventObject.primary_key]:
-               if isinstance(self.columns, (list, tuple, set)):
-                    index = self.columns.index(col)
-                    self.columns[index] = EventObject.table_name+"."+EventObject.primary_key
-                elif isinstance(self.columns, dict):
-                    type = self.columns.pop(col)
-                    self.columns[EventObject.table_name+"."+EventObject.primary_key] = type
-                        
-       sql = "SELECT %s FROM event_object, events WHERE True" % \
+       sql = "SELECT %s FROM view_event_objects WHERE True" % \
             ", ".join(self.columns)
         
        if event_filter is not None:
             if isinstance(event_filter, (list, tuple, set)):
                 event_filter = Filter(EventObject.fields, {'event_id': event_filter})
+                sql += " AND (%s) %s" % event_filter.sql(api, "OR")
             elif isinstance(event_filter, dict):
                 event_filter = Filter(EventObject.fields, event_filter)
-            sql += " AND (%s) " % event_filter.sql(api)
-       sql += " AND events.event_id = event_object.event_id " 
-       sql += " ORDER BY %s" % EventObject.table_name+"."+EventObject.primary_key
+                sql += " AND (%s) %s" % event_filter.sql(api, "AND")
+            elif isinstance (event_filter, int):
+                event_filter = Filter(EventObject.fields, {'event_id':[event_filter]})
+                sql += " AND (%s) %s" % event_filter.sql(api, "AND")
+            else:
+                raise PLCInvalidArgument, "Wrong event object filter %r"%event_filter
+# with new filtering, caller needs to set this explicitly
+#      sql += " ORDER BY %s" % EventObject.primary_key
         
        self.selectall(sql)