From c30cc8bcb262fcf8c30a3d7e4b40e8ac0fc60945 Mon Sep 17 00:00:00 2001
From: joe <joe@incal.net>
Date: Tue, 19 Feb 2013 17:03:34 +0100
Subject: [PATCH] Added the methods to get the timestamp as well.

---
 configdb/db/db_api.py      | 18 ++++++++++++++++++
 configdb/server/wsgiapp.py |  8 ++++++++
 2 files changed, 26 insertions(+)

diff --git a/configdb/db/db_api.py b/configdb/db/db_api.py
index 2182294..3347e64 100644
--- a/configdb/db/db_api.py
+++ b/configdb/db/db_api.py
@@ -241,3 +241,21 @@ class AdmDbApi(object):
 
         self.schema.acl_check_entity(ent, auth_context, 'r', None)
         return self.db.get_audit(query, session)
+
+    @with_session
+    def get_timestamp(self, session, entity_name, auth_context):
+        """Get the timestamp of the last update on an entity.
+
+        """
+        ent = self.schema.get_entity(entity_name)
+        if not ent:
+            raise exceptions.NotFound(entity_name)
+
+        self.schema.acl_check_entity(ent, auth_context, 'r', None)
+
+        obj = self.db.get_by_name('__timestamp', entity_name, session)
+        if not obj:
+            raise exceptions.NotFound(entity_name)
+        return obj
+        
+                                  
diff --git a/configdb/server/wsgiapp.py b/configdb/server/wsgiapp.py
index e6f818b..b98b079 100644
--- a/configdb/server/wsgiapp.py
+++ b/configdb/server/wsgiapp.py
@@ -156,6 +156,14 @@ def find(class_name):
 def delete(class_name, object_name):
     return g.api.delete(class_name, object_name, g.auth_ctx)
 
+@api_app.route('/timestamp/<class_name>')
+@authenticate
+def ts(class_name):
+    try:
+        res = g.api.get_timestamp(class_name, g.auth_ctx)
+        return str(res.ts)
+    except exceptions.NotFound:
+        return "0"
 
 @api_app.route('/audit', methods=['POST'])
 @authenticate
-- 
GitLab