add functions for pcuview, nodeview, & siteview
[monitor.git] / monitor / database / info / findbad.py
index da7775a..566c2ae 100644 (file)
@@ -22,13 +22,19 @@ class FindbadNodeRecord(Entity):
        @classmethod
        def get_all_latest(cls):
                fbsync = FindbadNodeRecordSync.get_by(hostname="global")
-               return cls.query.filter_by(round=fbsync.round)
+               if fbsync:
+                       return cls.query.filter_by(round=fbsync.round)
+               else:
+                       return []
 
        @classmethod
        def get_latest_by(cls, **kwargs):
                fbsync = FindbadNodeRecordSync.get_by(hostname="global")
-               kwargs['round'] = fbsync.round
-               return cls.query.filter_by(**kwargs)
+               if fbsync:
+                       kwargs['round'] = fbsync.round
+                       return cls.query.filter_by(**kwargs)
+               else:
+                       return []
 
        @classmethod
        def get_latest_n_by(cls, n=3, **kwargs):
@@ -80,8 +86,10 @@ class FindbadPCURecord(Entity):
        @classmethod
        def get_all_latest(cls):
                fbsync = FindbadPCURecordSync.get_by(plc_pcuid=0)
-               print "round: ", fbsync.round
-               return cls.query.filter_by(round=fbsync.round)
+               if fbsync:
+                       return cls.query.filter_by(round=fbsync.round)
+               else:
+                       return []
 
        @classmethod
        def get_latest_by(cls, **kwargs):