changeset 30:51db9e78bf98

working on field types
author casties
date Mon, 30 Aug 2010 17:29:58 +0200
parents 0b9f8cca6744
children 6d2055f1b4fa
files RestDbInterface.py
diffstat 1 files changed, 20 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/RestDbInterface.py	Mon Aug 30 11:54:54 2010 +0200
+++ b/RestDbInterface.py	Mon Aug 30 17:29:58 2010 +0200
@@ -78,8 +78,21 @@
     JSONHTML_schema = PageTemplateFile('zpt/JSONHTML_schema', globals())
     JSONHTML_schema_table = PageTemplateFile('zpt/JSONHTML_schema_table', globals())
     # JSON_* templates are scripts
+    def JSON_index(self,data):
+        """JSON index function"""
+        self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
+        json.dump(data, self.REQUEST.RESPONSE)        
 
-    
+    def JSON_schema(self,data,schema):
+        """JSON index function"""
+        self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
+        json.dump(data, self.REQUEST.RESPONSE)        
+
+    def JSON_schema_table(self,data,tablename):
+        """JSON index function"""
+        self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
+        json.dump(data, self.REQUEST.RESPONSE)        
+
     
     def __init__(self, id, title, connection_id=None):
         """init"""
@@ -228,8 +241,12 @@
                 RESPONSE.setStatus(400)
                 return
 
-            fields = REQUEST.get("create_table_fields",None)
-            logging.debug("put with schema=%s table=%s file=%s fields=%s"%(schema,tablename,file,repr(fields)))
+            fields = None
+            fieldsStr = REQUEST.get("create_table_fields",None)
+            logging.debug("put with schema=%s table=%s file=%s fields=%s"%(schema,tablename,file,repr(fieldsStr)))
+            if fieldsStr is not None:
+                # unpack fields
+                fields = [{"name":n, "type": t} for (n,t) in [f.split(":") for f in fieldsStr.split(",")]]
             ret = self.createTableFromXML(schema, tablename, file, fields)
             # return the result as JSON
             format = REQUEST.get("format","JSON")
@@ -331,21 +348,6 @@
         data={'fields': (('schemas',),), 'rows': [('public',),]}
         return data
     
-    def JSON_index(self,data):
-        """JSON index function"""
-        self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
-        json.dump(data, self.REQUEST.RESPONSE)        
-
-    def JSON_schema(self,data,schema):
-        """JSON index function"""
-        self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
-        json.dump(data, self.REQUEST.RESPONSE)        
-
-    def JSON_schema_table(self,data,tablename):
-        """JSON index function"""
-        self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
-        json.dump(data, self.REQUEST.RESPONSE)        
-
     def checkTable(self,resultFormat,schema,table,REQUEST=None,RESPONSE=None):
         """check the table.
            returns valid data fields and table name."""