annotate RestDbJsonStore.py @ 51:17dcf148beb3

more JSON store
author casties
date Thu, 09 Sep 2010 10:01:16 +0200
parents 29c822d15bc1
children 435d6664ed90
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
42
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
1 '''
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
2 Created on 2.9.2010
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
3
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
4 @author: casties
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
5 '''
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
6
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
7 from OFS.Folder import Folder
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
8 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
9 import logging
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
10 import re
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
11 import psycopg2
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
12 import json
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
13 import time
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
14
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
15 from zope.interface import implements
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
16 from zope.publisher.interfaces import IPublishTraverse
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
17 from ZPublisher.BaseRequest import DefaultPublishTraverse
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
18 import Shared.DC.ZRDB.DA
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
19 from Products.ZSQLMethods.SQL import SQLConnectionIDs
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
20
43
562717546168 refactoring...
casties
parents: 42
diff changeset
21 from RestDbInterface import *
42
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
22
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
23
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
24 class RestDbJsonStore(RestDbInterface):
46
3ea606bae008 starting JSON store
casties
parents: 43
diff changeset
25 """Object for RESTful access to JSON objects
3ea606bae008 starting JSON store
casties
parents: 43
diff changeset
26 path schema: /db/{schema}/{table}/{tag}/{type}/{item}
42
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
27 """
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
28 implements(IPublishTraverse)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
29
46
3ea606bae008 starting JSON store
casties
parents: 43
diff changeset
30 meta_type="RESTjson"
42
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
31 manage_options=Folder.manage_options+(
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
32 {'label':'Config','action':'manage_editRestDbJsonStoreForm'},
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
33 )
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
34
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
35 # management templates
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
36 manage_editRestDbJsonStoreForm=PageTemplateFile('zpt/editRestDbJsonStore',globals())
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
37
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
38 # JSON_* templates are scripts
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
39 def JSON_index(self,data):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
40 """JSON index function"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
41 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
42 json.dump(data, self.REQUEST.RESPONSE)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
43
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
44
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
45 def __init__(self, id, title, connection_id=None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
46 """init"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
47 self.id = id
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
48 self.title = title
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
49 # database connection id
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
50 self.connection_id = connection_id
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
51
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
52 def getJsonString(self,object):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
53 """returns a JSON formatted string from object"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
54 return json.dumps(object)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
55
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
56
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
57 def publishTraverse(self,request,name):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
58 """change the traversal"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
59 # get stored path
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
60 path = request.get('restdb_path', [])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
61 logging.debug("publishtraverse: name=%s restdb_path=%s"%(name,path))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
62
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
63 if name in ("index_html", "PUT"):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
64 # end of traversal
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
65 if request.get("method") == "POST" and request.get("action",None) == "PUT":
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
66 # fake PUT by POST with action=PUT
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
67 name = "PUT"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
68
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
69 return getattr(self, name)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
70 #TODO: should we check more?
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
71 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
72 # traverse
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
73 if len(path) == 0:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
74 # first segment
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
75 if name == 'db':
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
76 # virtual path -- continue traversing
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
77 path = [name]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
78 request['restdb_path'] = path
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
79 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
80 # try real path
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
81 tr = DefaultPublishTraverse(self, request)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
82 ob = tr.publishTraverse(request, name)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
83 return ob
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
84 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
85 path.append(name)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
86
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
87 # continue traversing
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
88 return self
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
89
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
90 def index_html(self,REQUEST,RESPONSE):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
91 """index method"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
92 # ReST path was stored in request
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
93 path = REQUEST.get('restdb_path',[])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
94
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
95 # type and format are real parameter
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
96 resultFormat = REQUEST.get('format','HTML').upper()
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
97 queryType = REQUEST.get('type',None)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
98
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
99 logging.debug("index_html path=%s resultFormat=%s queryType=%s"%(path,resultFormat,queryType))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
100
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
101 if queryType is not None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
102 # non-empty queryType -- look for template
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
103 pt = getattr(self.template, "%s_%s"%(resultFormat,queryType), None)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
104 if pt is not None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
105 return pt(format=resultFormat,type=queryType,path=path)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
106
46
3ea606bae008 starting JSON store
casties
parents: 43
diff changeset
107 if len(path) == 3:
3ea606bae008 starting JSON store
casties
parents: 43
diff changeset
108 # list of tags
3ea606bae008 starting JSON store
casties
parents: 43
diff changeset
109 return self.showListOfTags(resultFormat=resultFormat,schema=path[1],table=path[2])
3ea606bae008 starting JSON store
casties
parents: 43
diff changeset
110 elif len(path) == 4:
49
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
111 # list of types
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
112 return self.showListOfTypes(resultFormat=resultFormat,schema=path[1],table=path[2],tag=path[3])
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
113 elif len(path) == 5:
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
114 # list of types
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
115 return self.showListOfItems(resultFormat=resultFormat,schema=path[1],table=path[2],tag=path[3],type=path[4])
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
116 elif len(path) == 6:
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
117 # show item
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
118 return self.showItem(resultFormat=resultFormat,schema=path[1],table=path[2],tag=path[3],type=path[4],item=path[5])
42
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
119
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
120 # don't know what to do
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
121 return str(REQUEST)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
122
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
123 def PUT(self, REQUEST, RESPONSE):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
124 """
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
125 Implement WebDAV/HTTP PUT/FTP put method for this object.
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
126 """
49
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
127 path = REQUEST.get('restdb_path',[])
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
128 logging.debug("RestDbInterface PUT (path=%s)"%repr(path))
42
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
129 #logging.debug("req=%s"%REQUEST)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
130 #self.dav__init(REQUEST, RESPONSE)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
131 #self.dav__simpleifhandler(REQUEST, RESPONSE)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
132 # ReST path was stored in request
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
133 if len(path) == 3:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
134 schema = path[1]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
135 tablename = path[2]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
136 file = REQUEST.get("create_table_file",None)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
137 if file is None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
138 RESPONSE.setStatus(400)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
139 return
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
140
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
141 fields = None
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
142 fieldsStr = REQUEST.get("create_table_fields",None)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
143 logging.debug("put with schema=%s table=%s file=%s fields=%s"%(schema,tablename,file,repr(fieldsStr)))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
144 if fieldsStr is not None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
145 # unpack fields
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
146 fields = [{"name":n, "type": t} for (n,t) in [f.split(":") for f in fieldsStr.split(",")]]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
147
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
148 ret = self.createTableFromXML(schema, tablename, file, fields)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
149 # return the result as JSON
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
150 format = REQUEST.get("format","JSON")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
151 if format == "JSON":
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
152 RESPONSE.setHeader("Content-Type", "application/json")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
153 json.dump(ret, RESPONSE)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
154
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
155 elif format == "JSONHTML":
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
156 RESPONSE.setHeader("Content-Type", "text/html")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
157 RESPONSE.write("<html>\n<body>\n<pre>")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
158 json.dump(ret, RESPONSE)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
159 RESPONSE.write("</pre>\n</body>\n</html>")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
160
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
161 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
162 # 400 Bad Request
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
163 RESPONSE.setStatus(400)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
164 return
50
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
165
49
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
166 def showListOfTags(self,resultFormat,schema,table):
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
167 """returns the list of existing tags"""
50
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
168 tags = self.getListOfTags(schema, table)
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
169 if resultFormat == 'JSON':
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
170 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
171 json.dump(tags, self.REQUEST.RESPONSE)
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
172 else:
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
173 json.dump(tags, self.REQUEST.RESPONSE)
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
174
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
175 def getListOfTags(self,schema,table):
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
176 """returns the list of existing tags"""
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
177 logging.debug("getlistoftags schema=%s table=%s"%(schema,table))
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
178 sql = 'select distinct json_tag from "%s"."%s"'%(schema,table)
49
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
179 res = self.executeSQL(sql)
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
180 if len(res['rows']) > 0:
51
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
181 tags = [r[0] for r in res['rows']]
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
182 return tags
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
183
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
184 return []
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
185
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
186 def showListOfTypes(self,resultFormat,schema,table,tag):
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
187 """returns the list of existing types"""
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
188 types = self.getListOfTypes(schema, table,tag)
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
189 if resultFormat == 'JSON':
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
190 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
191 json.dump(types, self.REQUEST.RESPONSE)
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
192 else:
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
193 json.dump(types, self.REQUEST.RESPONSE)
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
194
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
195 def getListOfTypes(self,schema,table,tag):
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
196 """returns the list of existing tags"""
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
197 logging.debug("getlistoftypes schema=%s table=%s tag=%s"%(schema,table,tag))
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
198 sql = 'select distinct json_type from "%s"."%s" where json_tag = %%s'%(schema,table)
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
199 res = self.executeSQL(sql,(tag,))
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
200 if len(res['rows']) > 0:
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
201 tags = [r[0] for r in res['rows']]
49
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
202 return tags
42
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
203
49
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
204 return []
e4828cb72ce2 working on json store
casties
parents: 48
diff changeset
205
51
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
206 def showListOfItems(self,resultFormat,schema,table,tag,type):
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
207 """returns the list of existing items"""
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
208 items = self.getListOfItems(schema, table, tag, type)
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
209 if resultFormat == 'JSON':
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
210 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
211 json.dump(items, self.REQUEST.RESPONSE)
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
212 else:
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
213 json.dump(items, self.REQUEST.RESPONSE)
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
214
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
215 def getListOfItems(self,schema,table,tag,type):
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
216 """returns the list of existing tags"""
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
217 logging.debug("getlistofitems schema=%s table=%s tag=%s type=%s"%(schema,table,tag,type))
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
218 sql = 'select distinct json_item from "%s"."%s" where json_tag = %%s and json_type = %%s'%(schema,table)
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
219 res = self.executeSQL(sql,(tag,type))
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
220 if len(res['rows']) > 0:
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
221 items = [r[0] for r in res['rows']]
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
222 return items
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
223
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
224 return []
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
225
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
226 def showItem(self,resultFormat,schema,table,tag,type,item):
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
227 """returns the item"""
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
228 item = self.getItem(schema, table, tag, type, item)
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
229 if resultFormat == 'JSON':
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
230 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
231 json.dump(item, self.REQUEST.RESPONSE)
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
232 else:
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
233 json.dump(item, self.REQUEST.RESPONSE)
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
234
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
235 def getItem(self,schema,table,tag,type,item):
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
236 """returns the list of existing tags"""
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
237 logging.debug("getitem schema=%s table=%s tag=%s type=%s item=%s"%(schema,table,tag,type,item))
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
238 sql = 'select json_value from "%s"."%s" where json_tag = %%s and json_type = %%s and json_item = %%s'%(schema,table)
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
239 res = self.executeSQL(sql,(tag,type,item))
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
240 if len(res['rows']) > 0:
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
241 # just one item
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
242 item = res['rows'][0][0]
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
243 return item
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
244
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
245 return {}
17dcf148beb3 more JSON store
casties
parents: 50
diff changeset
246
50
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
247 manage_addRestDbJsonStoreForm=PageTemplateFile('zpt/addRestDbJsonStore',globals())
42
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
248
50
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
249 def manage_addRestDbJsonStore(self, id, title='', label='', description='',
42
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
250 createPublic=0,
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
251 createUserF=0,
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
252 REQUEST=None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
253 """Add a new object with id *id*."""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
254
50
29c822d15bc1 more JSON store
casties
parents: 49
diff changeset
255 ob=RestDbJsonStore(str(id),title)
42
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
256 self._setObject(id, ob)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
257
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
258 #checkPermission=getSecurityManager().checkPermission
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
259 REQUEST.RESPONSE.redirect('manage_main')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
260
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
261