using sfa.util.namespace instead of sfa.util.misc
[sfa.git] / sfa / util / record.py
index f2a455b..de221fc 100644 (file)
@@ -14,10 +14,10 @@ from sfa.trust.gid import *
 import sfa.util.report
 from sfa.util.rspec import *
 from sfa.util.parameter import *
-from sfa.util.misc import *
+from sfa.util.namespace import *
+from sfa.util.row import Row
 
-
-class GeniRecord(dict):
+class GeniRecord(Row):
     """ 
     The GeniRecord class implements a Geni Record. A GeniRecord is a tuple
     (Hrn, GID, Type, Info).
@@ -37,19 +37,24 @@ class GeniRecord(dict):
     of different types.
     """
 
+    table_name = 'sfa'
+    
+    primary_key = 'record_id'
+
     ### the wsdl generator assumes this is named 'fields'
     internal_fields = {
-        'record_id': Parameter(int, 'An id that uniquely identifies this record'),
+        'record_id': Parameter(int, 'An id that uniquely identifies this record', ro=True),
         'pointer': Parameter(int, 'An id that uniquely identifies this record in an external database ')
     }
 
     fields = {
         'authority': Parameter(str, "The authority for this record"),
+        'peer_authority': Parameter(str, "The peer authority for this record"),
         'hrn': Parameter(str, "Human readable name of object"),
         'gid': Parameter(str, "GID of the object"),
         'type': Parameter(str, "Record type"),
-        'last_updated': Parameter(int, 'Date and time of last update'),
-        'date_created': Parameter(int, 'Date and time this record was created'),
+        'last_updated': Parameter(int, 'Date and time of last update', ro=True),
+        'date_created': Parameter(int, 'Date and time this record was created', ro=True),
     }
     all_fields = dict(fields.items() + internal_fields.items())
     ##
@@ -61,12 +66,13 @@ class GeniRecord(dict):
     # @param pointer is a pointer to a PLC record
     # @param dict if !=None, then fill in this record from the dictionary
 
-    def __init__(self, hrn=None, gid=None, type=None, pointer=None, dict=None, string=None):
+    def __init__(self, hrn=None, gid=None, type=None, pointer=None, peer_authority=None, dict=None, string=None):
         self.dirty = True
         self.hrn = None
         self.gid = None
         self.type = None
         self.pointer = None
+        self.set_peer_auth(peer_authority)
         if hrn:
             self.set_name(hrn)
         if gid:
@@ -79,6 +85,10 @@ class GeniRecord(dict):
             self.load_from_dict(dict)
         if string:
             self.load_from_string(string)
+
+
+    def validate_last_updated(self, last_updated):
+        return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
         
     def update(self, new_dict):
         if isinstance(new_dict, list):
@@ -150,6 +160,12 @@ class GeniRecord(dict):
         self['pointer'] = pointer
         self.dirty = True
 
+
+    def set_peer_auth(self, peer_authority):
+        self.peer_authority = peer_authority
+        self['peer_authority'] = peer_authority
+        self.dirty = True
+
     ##
     # Return the name (HRN) of the record