comparison RestDbJsonStore.py @ 48:2ba80c8bb47f

Merge with 3ea606bae008a71b27b3e04c37c0522ee3eebf6a
author casties
date Fri, 03 Sep 2010 14:01:47 +0200
parents 698ef00f2717 3ea606bae008
children e4828cb72ce2
comparison
equal deleted inserted replaced
47:698ef00f2717 48:2ba80c8bb47f
20 20
21 from RestDbInterface import * 21 from RestDbInterface import *
22 22
23 23
24 class RestDbJsonStore(RestDbInterface): 24 class RestDbJsonStore(RestDbInterface):
25 """Object for RESTful database queries 25 """Object for RESTful access to JSON objects
26 path schema: /db/{schema}/{table}/ 26 path schema: /db/{schema}/{table}/{tag}/{type}/{item}
27 omitting table gives a list of schemas
28 omitting table and schema gives a list of schemas
29 """ 27 """
30 implements(IPublishTraverse) 28 implements(IPublishTraverse)
31 29
32 meta_type="RESTdbJSONStore" 30 meta_type="RESTjson"
33 manage_options=Folder.manage_options+( 31 manage_options=Folder.manage_options+(
34 {'label':'Config','action':'manage_editRestDbJsonStoreForm'}, 32 {'label':'Config','action':'manage_editRestDbJsonStoreForm'},
35 ) 33 )
36 34
37 # management templates 35 # management templates
38 manage_editRestDbJsonStoreForm=PageTemplateFile('zpt/editRestDbJsonStore',globals()) 36 manage_editRestDbJsonStoreForm=PageTemplateFile('zpt/editRestDbJsonStore',globals())
39 37
40 # JSON_* templates are scripts 38 # JSON_* templates are scripts
41 def JSON_index(self,data): 39 def JSON_index(self,data):
42 """JSON index function"""
43 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
44 json.dump(data, self.REQUEST.RESPONSE)
45
46 def JSON_schema(self,data,schema):
47 """JSON index function"""
48 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
49 json.dump(data, self.REQUEST.RESPONSE)
50
51 def JSON_schema_table(self,data,tablename):
52 """JSON index function""" 40 """JSON index function"""
53 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") 41 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
54 json.dump(data, self.REQUEST.RESPONSE) 42 json.dump(data, self.REQUEST.RESPONSE)
55 43
56 44
114 # non-empty queryType -- look for template 102 # non-empty queryType -- look for template
115 pt = getattr(self.template, "%s_%s"%(resultFormat,queryType), None) 103 pt = getattr(self.template, "%s_%s"%(resultFormat,queryType), None)
116 if pt is not None: 104 if pt is not None:
117 return pt(format=resultFormat,type=queryType,path=path) 105 return pt(format=resultFormat,type=queryType,path=path)
118 106
119 if len(path) == 1: 107 if len(path) == 3:
120 # list of schemas 108 # list of tags
121 return self.showListOfSchemas(resultFormat=resultFormat) 109 return self.showListOfTags(resultFormat=resultFormat,schema=path[1],table=path[2])
122 elif len(path) == 2: 110 elif len(path) == 4:
123 # list of tables 111 # list of tables
124 return self.showListOfTables(resultFormat=resultFormat,schema=path[1]) 112 return self.showListOfTables(resultFormat=resultFormat,schema=path[1])
125 elif len(path) == 3: 113 elif len(path) == 3:
126 # table 114 # table
127 if REQUEST.get("method") == "POST" and REQUEST.get("create_table_file",None) is not None: 115 if REQUEST.get("method") == "POST" and REQUEST.get("create_table_file",None) is not None: