changeset 24:f3811d9a36da

start adding checkuploadtable
author casties
date Fri, 20 Aug 2010 12:01:41 +0200
parents 860ec92f99df
children cef1bfa821cb
files RestDbInterface.py
diffstat 1 files changed, 25 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/RestDbInterface.py	Thu Aug 19 18:55:50 2010 +0200
+++ b/RestDbInterface.py	Fri Aug 20 12:01:41 2010 +0200
@@ -77,6 +77,7 @@
     JSONHTML_index = PageTemplateFile('zpt/JSONHTML_index', globals())
     JSONHTML_schema = PageTemplateFile('zpt/JSONHTML_schema', globals())
     JSONHTML_schema_table = PageTemplateFile('zpt/JSONHTML_schema_table', globals())
+    # JSON_* templates are scripts
 
     
     
@@ -194,13 +195,17 @@
             
         if len(path) == 1:
             # list of schemas
-            return self.showListOfSchemas(format=format,REQUEST=REQUEST,RESPONSE=RESPONSE)
+            return self.showListOfSchemas(format=format)
         elif len(path) == 2:
             # list of tables
-            return self.showListOfTables(format=format,schema=path[1],REQUEST=REQUEST,RESPONSE=RESPONSE)
+            return self.showListOfTables(format=format,schema=path[1])
         elif len(path) == 3:
             # table
-            return self.showTable(format=format,schema=path[1],table=path[2],REQUEST=REQUEST,RESPONSE=RESPONSE)
+            if request.get("method") == "POST" and request.get("create_table_file",None) is not None:
+                # POST to table to check
+                return self.checkTable(format=format,schema=path[1],table=path[2])
+            # else show table
+            return self.showTable(format=format,schema=path[1],table=path[2])
         
         # don't know what to do
         return str(REQUEST)
@@ -241,7 +246,6 @@
             RESPONSE.setStatus(400)
             return
         
-
     def showTable(self,format='XML',schema='public',table=None,REQUEST=None,RESPONSE=None):
         """returns PageTemplate with tables"""
         logging.debug("showtable")
@@ -253,13 +257,6 @@
             doc = REQUEST.get('doc',None)
             return self.showGoogleMap(schema=path[1],table=path[2],id=id,doc=doc)
 
-        # JSON gets special treatment
-        if format == "JSON":
-            data = self.getListOfTables(schema)
-            RESPONSE.setHeader("Content-Type", "application/json")
-            json.dump(data, RESPONSE)
-            return
-        
         # everything else has its own template
         pt = getattr(self.template, '%s_schema_table'%format, None)
         if pt is None:
@@ -279,14 +276,7 @@
         logging.debug("showlistoftables")
         # should be cross-site accessible 
         RESPONSE.setHeader('Access-Control-Allow-Origin', '*')
-        # JSON gets special treatment
-        if format == "JSON":
-            data = self.getListOfTables(schema)
-            RESPONSE.setHeader("Content-Type", "application/json")
-            json.dump(data, RESPONSE)
-            return
-            
-        # everything else has its own template
+
         pt = getattr(self.template, '%s_schema'%format, None)
         if pt is None:
             return "ERROR!! template %s_schema not found"%format
@@ -311,12 +301,7 @@
         logging.debug("showlistofschemas")
         # should be cross-site accessible 
         RESPONSE.setHeader('Access-Control-Allow-Origin', '*')
-        # JSON gets special treatment
-        if format == "JSON":
-            data = self.getListOfSchemas()
-            RESPONSE.setHeader("Content-Type", "application/json")
-            json.dump(data, RESPONSE)
-            return
+
         pt = getattr(self.template, '%s_index'%format, None)
         if pt is None:
             return "ERROR!! template %s_index not found"%format
@@ -331,6 +316,21 @@
         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 createEmptyTable(self,schema,table,fields):
         """create a table with the given fields
            returns list of created fields"""