annotate RestDbJsonStore.py @ 42:291aed5f0e0d

new class for JSON store
author casties
date Thu, 02 Sep 2010 12:05:17 +0200
parents
children 562717546168
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
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
21
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
22
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
23 class RestDbJsonStore(RestDbInterface):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
24 """Object for RESTful database queries
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
25 path schema: /db/{schema}/{table}/
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
26 omitting table gives a list of schemas
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
27 omitting table and schema gives a list of schemas
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
28 """
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
29 implements(IPublishTraverse)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
30
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
31 meta_type="RESTdbJSONStore"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
32 manage_options=Folder.manage_options+(
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
33 {'label':'Config','action':'manage_editRestDbJsonStoreForm'},
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
34 )
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
35
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
36 # management templates
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
37 manage_editRestDbJsonStoreForm=PageTemplateFile('zpt/editRestDbJsonStore',globals())
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
38
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
39 # JSON_* templates are scripts
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
40 def JSON_index(self,data):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
41 """JSON index function"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
42 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
43 json.dump(data, self.REQUEST.RESPONSE)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
44
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
45 def JSON_schema(self,data,schema):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
46 """JSON index function"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
47 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
48 json.dump(data, self.REQUEST.RESPONSE)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
49
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
50 def JSON_schema_table(self,data,tablename):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
51 """JSON index function"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
52 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
53 json.dump(data, self.REQUEST.RESPONSE)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
54
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
55
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
56 def __init__(self, id, title, connection_id=None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
57 """init"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
58 self.id = id
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
59 self.title = title
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
60 # database connection id
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
61 self.connection_id = connection_id
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
62
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
63 def getJsonString(self,object):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
64 """returns a JSON formatted string from object"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
65 return json.dumps(object)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
66
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
67
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
68 def publishTraverse(self,request,name):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
69 """change the traversal"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
70 # get stored path
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
71 path = request.get('restdb_path', [])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
72 logging.debug("publishtraverse: name=%s restdb_path=%s"%(name,path))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
73
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
74 if name in ("index_html", "PUT"):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
75 # end of traversal
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
76 if request.get("method") == "POST" and request.get("action",None) == "PUT":
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
77 # fake PUT by POST with action=PUT
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
78 name = "PUT"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
79
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
80 return getattr(self, name)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
81 #TODO: should we check more?
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
82 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
83 # traverse
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
84 if len(path) == 0:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
85 # first segment
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
86 if name == 'db':
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
87 # virtual path -- continue traversing
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
88 path = [name]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
89 request['restdb_path'] = path
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
90 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
91 # try real path
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
92 tr = DefaultPublishTraverse(self, request)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
93 ob = tr.publishTraverse(request, name)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
94 return ob
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
95 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
96 path.append(name)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
97
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
98 # continue traversing
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
99 return self
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
100
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
101 def index_html(self,REQUEST,RESPONSE):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
102 """index method"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
103 # ReST path was stored in request
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
104 path = REQUEST.get('restdb_path',[])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
105
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
106 # type and format are real parameter
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
107 resultFormat = REQUEST.get('format','HTML').upper()
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
108 queryType = REQUEST.get('type',None)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
109
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
110 logging.debug("index_html path=%s resultFormat=%s queryType=%s"%(path,resultFormat,queryType))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
111
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
112 if queryType is not None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
113 # non-empty queryType -- look for template
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
114 pt = getattr(self.template, "%s_%s"%(resultFormat,queryType), None)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
115 if pt is not None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
116 return pt(format=resultFormat,type=queryType,path=path)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
117
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
118 if len(path) == 1:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
119 # list of schemas
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
120 return self.showListOfSchemas(resultFormat=resultFormat)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
121 elif len(path) == 2:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
122 # list of tables
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
123 return self.showListOfTables(resultFormat=resultFormat,schema=path[1])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
124 elif len(path) == 3:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
125 # table
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
126 if REQUEST.get("method") == "POST" and REQUEST.get("create_table_file",None) is not None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
127 # POST to table to check
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
128 return self.checkTable(resultFormat=resultFormat,schema=path[1],table=path[2])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
129 # else show table
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
130 return self.showTable(resultFormat=resultFormat,schema=path[1],table=path[2])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
131
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
132 # don't know what to do
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
133 return str(REQUEST)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
134
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
135 def PUT(self, REQUEST, RESPONSE):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
136 """
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
137 Implement WebDAV/HTTP PUT/FTP put method for this object.
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
138 """
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
139 logging.debug("RestDbInterface PUT")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
140 #logging.debug("req=%s"%REQUEST)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
141 #self.dav__init(REQUEST, RESPONSE)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
142 #self.dav__simpleifhandler(REQUEST, RESPONSE)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
143 # ReST path was stored in request
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
144 path = REQUEST.get('restdb_path',[])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
145 if len(path) == 3:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
146 schema = path[1]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
147 tablename = path[2]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
148 file = REQUEST.get("create_table_file",None)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
149 if file is None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
150 RESPONSE.setStatus(400)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
151 return
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
152
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
153 fields = None
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
154 fieldsStr = REQUEST.get("create_table_fields",None)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
155 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
156 if fieldsStr is not None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
157 # unpack fields
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
158 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
159
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
160 ret = self.createTableFromXML(schema, tablename, file, fields)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
161 # return the result as JSON
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
162 format = REQUEST.get("format","JSON")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
163 if format == "JSON":
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
164 RESPONSE.setHeader("Content-Type", "application/json")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
165 json.dump(ret, RESPONSE)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
166
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
167 elif format == "JSONHTML":
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
168 RESPONSE.setHeader("Content-Type", "text/html")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
169 RESPONSE.write("<html>\n<body>\n<pre>")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
170 json.dump(ret, RESPONSE)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
171 RESPONSE.write("</pre>\n</body>\n</html>")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
172
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
173 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
174 # 400 Bad Request
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
175 RESPONSE.setStatus(400)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
176 return
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
177
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
178 def showTable(self,resultFormat='XML',schema='public',table=None,REQUEST=None,RESPONSE=None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
179 """returns PageTemplate with tables"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
180 logging.debug("showtable")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
181 if REQUEST is None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
182 REQUEST = self.REQUEST
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
183
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
184 # should be cross-site accessible
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
185 if RESPONSE is None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
186 RESPONSE = self.REQUEST.RESPONSE
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
187
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
188 RESPONSE.setHeader('Access-Control-Allow-Origin', '*')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
189
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
190 # GIS gets special treatment
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
191 if resultFormat=="GIS":
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
192 id = REQUEST.get('id',[])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
193 doc = REQUEST.get('doc',None)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
194 return self.showGoogleMap(schema=schema,table=table,id=id,doc=doc)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
195
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
196 elif resultFormat=="KML_URL":
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
197 id = REQUEST.get('id',[])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
198 doc = REQUEST.get('doc',None)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
199 return self.getKmlUrl(schema=schema,table=table,id=id,doc=doc)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
200
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
201 # everything else has its own template
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
202 pt = getattr(self.template, '%s_schema_table'%resultFormat, None)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
203 if pt is None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
204 return "ERROR!! template %s_schema_table not found"%resultFormat
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
205
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
206 data = self.getTable(schema,table)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
207 return pt(data=data,tablename=table)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
208
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
209 def getTable(self,schema='public',table=None,username='guest'):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
210 """return table data"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
211 logging.debug("gettable")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
212 data = self.executeSQL('select * from "%s"."%s"'%(schema,table))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
213 return data
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
214
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
215 def hasTable(self,schema='public',table=None,username='guest'):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
216 """return if table exists"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
217 logging.debug("hastable")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
218 data = self.executeSQL('select 1 from information_schema.tables where table_schema=%s and table_name=%s',(schema,table))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
219 ret = bool(data['rows'])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
220 return ret
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
221
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
222 def showListOfTables(self,resultFormat='XML',schema='public',REQUEST=None,RESPONSE=None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
223 """returns PageTemplate with list of tables"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
224 logging.debug("showlistoftables")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
225 # should be cross-site accessible
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
226 if RESPONSE is None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
227 RESPONSE = self.REQUEST.RESPONSE
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
228 RESPONSE.setHeader('Access-Control-Allow-Origin', '*')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
229
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
230 pt = getattr(self.template, '%s_schema'%resultFormat, None)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
231 if pt is None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
232 return "ERROR!! template %s_schema not found"%resultFormat
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
233
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
234 data = self.getListOfTables(schema)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
235 return pt(data=data,schema=schema)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
236
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
237 def getListOfTables(self,schema='public',username='guest'):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
238 """return list of tables"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
239 logging.debug("getlistoftables")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
240 # get list of fields and types of db table
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
241 qstr="""SELECT c.relname AS tablename FROM pg_catalog.pg_class c
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
242 LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
243 WHERE c.relkind IN ('r','') AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
244 AND pg_catalog.pg_table_is_visible(c.oid)"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
245 #qstr="select attname, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) from pg_attribute, pg_class where attrelid = pg_class.oid and pg_attribute.attnum > 0"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
246 data=self.executeSQL(qstr)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
247 return data
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
248
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
249 def showListOfSchemas(self,resultFormat='XML',REQUEST=None,RESPONSE=None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
250 """returns PageTemplate with list of schemas"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
251 logging.debug("showlistofschemas")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
252 # should be cross-site accessible
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
253 if RESPONSE is None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
254 RESPONSE = self.REQUEST.RESPONSE
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
255 RESPONSE.setHeader('Access-Control-Allow-Origin', '*')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
256
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
257 pt = getattr(self.template, '%s_index'%resultFormat, None)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
258 if pt is None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
259 return "ERROR!! template %s_index not found"%resultFormat
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
260
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
261 data = self.getListOfSchemas()
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
262 return pt(data=data)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
263
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
264 def getListOfSchemas(self,username='guest'):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
265 """return list of schemas"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
266 logging.debug("getlistofschemas")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
267 # TODO: really look up schemas
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
268 data={'fields': (('schemas',),), 'rows': [('public',),]}
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
269 return data
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
270
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
271 def checkTable(self,resultFormat,schema,table,REQUEST=None,RESPONSE=None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
272 """check the table.
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
273 returns valid data fields and table name."""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
274 if REQUEST is None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
275 REQUEST = self.REQUEST
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
276 RESPONSE = REQUEST.RESPONSE
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
277
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
278 file = REQUEST.get("create_table_file",None)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
279 res = self.checkTableFromXML(schema, table, file)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
280 logging.debug("checkTable result=%s"%repr(res))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
281 # return the result as JSON
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
282 if resultFormat == "JSON":
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
283 RESPONSE.setHeader("Content-Type", "application/json")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
284 json.dump(res, RESPONSE)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
285
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
286 elif resultFormat == "JSONHTML":
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
287 RESPONSE.setHeader("Content-Type", "text/html")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
288 RESPONSE.write("<html>\n<body>\n<pre>")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
289 json.dump(res, RESPONSE)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
290 RESPONSE.write("</pre>\n</body>\n</html>")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
291
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
292 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
293 return "ERROR: invalid resultFormat"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
294
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
295 def checkTableFromXML(self,schema,table,data,REQUEST=None,RESPONSE=None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
296 """check the table with the given XML data.
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
297 returns valid data fields and table name."""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
298 logging.debug("checkTableFromXML schema=%s table=%s"%(schema,table))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
299 # clean table name
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
300 tablename = sqlName(table)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
301 tableExists = self.hasTable(schema, table)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
302 if data is None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
303 fieldNames = []
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
304 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
305 # get list of field names from upload file
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
306 fields = self.importExcelXML(schema,tablename,data,fieldsOnly=True)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
307
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
308 res = {'tablename': tablename, 'table_exists': tableExists}
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
309 res['fields'] = fields
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
310 return res
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
311
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
312 def createEmptyTable(self,schema,table,fields):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
313 """create a table with the given fields
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
314 returns list of created fields"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
315 logging.debug("createEmptyTable")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
316 sqlFields = []
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
317 for f in fields:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
318 if isinstance(f,dict):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
319 # {name: XX, type: YY}
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
320 name = sqlName(f['name'])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
321 type = f['type']
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
322 sqltype = gisToSqlTypeMap[type]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
323
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
324 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
325 # name only
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
326 name = sqlName(f)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
327 type = 'text'
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
328 sqltype = 'text'
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
329
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
330 sqlFields.append({'name':name, 'type':type, 'sqltype':sqltype})
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
331
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
332 if self.checkTableMetaPermission("create", schema, table):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
333 self.executeSQL('drop table if exists "%s"."%s"'%(schema,table),hasResult=False)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
334 fieldString = ", ".join(['"%s" %s'%(f['name'],f['sqltype']) for f in sqlFields])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
335 sqlString = 'create table "%s"."%s" (%s)'%(schema,table,fieldString)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
336 logging.debug("createemptytable: SQL=%s"%sqlString)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
337 self.executeSQL(sqlString,hasResult=False)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
338 self.setTableMetaTypes(schema,table,sqlFields)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
339 return sqlFields
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
340 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
341 logging.warning("create table not allowed!")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
342 # throw exception?
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
343 return None
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
344
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
345 def createTableFromXML(self,schema,table,data, fields=None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
346 """create or replace a table with the given XML data"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
347 logging.debug("createTableFromXML schema=%s table=%s data=%s fields=%s"%(schema,table,data,fields))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
348 tablename = sqlName(table)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
349 self.importExcelXML(schema, tablename, data, fields)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
350 return {"tablename": tablename}
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
351
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
352 def importExcelXML(self,schema,table,xmldata,fields=None,fieldsOnly=False):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
353 '''
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
354 Import XML file in Excel format into the table
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
355 @param table: name of the table the xml shall be imported into
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
356 '''
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
357 from xml.dom.pulldom import parseString,parse
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
358
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
359 namespace = "urn:schemas-microsoft-com:office:spreadsheet"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
360 containerTagName = "Table"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
361 rowTagName = "Row"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
362 colTagName = "Cell"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
363 dataTagName = "Data"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
364 xmlFields = []
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
365 sqlFields = []
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
366 numFields = 0
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
367 sqlInsert = None
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
368
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
369 logging.debug("import excel xml")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
370
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
371 ret=""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
372 if isinstance(xmldata, str):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
373 logging.debug("importXML reading string data")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
374 doc=parseString(xmldata)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
375 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
376 logging.debug("importXML reading file data")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
377 doc=parse(xmldata)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
378
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
379 cnt = 0
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
380 while True:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
381 node=doc.getEvent()
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
382
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
383 if node is None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
384 break
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
385
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
386 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
387 #logging.debug("tag=%s"%node[1].localName)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
388 if node[1].localName is not None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
389 tagName = node[1].localName.lower()
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
390 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
391 # ignore non-tag nodes
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
392 continue
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
393
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
394 if tagName == rowTagName.lower():
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
395 # start of row
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
396 doc.expandNode(node[1])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
397 cnt += 1
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
398 if cnt == 1:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
399 # first row -- field names
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
400 names=node[1].getElementsByTagNameNS(namespace, dataTagName)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
401 for name in names:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
402 fn = getTextFromNode(name)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
403 xmlFields.append({'name':sqlName(fn),'type':'text'})
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
404
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
405 if fieldsOnly:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
406 # return just field names
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
407 return xmlFields
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
408
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
409 # create table
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
410 if fields is None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
411 fields = xmlFields
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
412
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
413 sqlFields = self.createEmptyTable(schema, table, fields)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
414 numFields = len(sqlFields)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
415 fieldString = ", ".join(['"%s"'%f['name'] for f in sqlFields])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
416 valString = ", ".join(["%s" for f in sqlFields])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
417 sqlInsert = 'insert into "%s"."%s" (%s) values (%s)'%(schema,table,fieldString,valString)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
418 #logging.debug("importexcelsql: sqlInsert=%s"%sqlInsert)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
419
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
420 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
421 # following rows are data
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
422 colNodes=node[1].getElementsByTagNameNS(namespace, colTagName)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
423 data = []
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
424 hasData = False
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
425 for colNode in colNodes:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
426 dataNodes=colNode.getElementsByTagNameNS(namespace, dataTagName)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
427 if len(dataNodes) > 0:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
428 val = getTextFromNode(dataNodes[0])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
429 hasData = True
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
430 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
431 val = None
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
432
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
433 data.append(val)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
434
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
435 if not hasData:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
436 # ignore empty rows
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
437 continue
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
438
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
439 # fix number of data fields
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
440 if len(data) > numFields:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
441 del data[numFields:]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
442 elif len(data) < numFields:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
443 missFields = numFields - len(data)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
444 data.extend(missFields * [None,])
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
445
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
446 logging.debug("importexcel sqlinsert=%s data=%s"%(sqlInsert,data))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
447 self.executeSQL(sqlInsert, data, hasResult=False)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
448
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
449 return cnt
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
450
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
451
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
452 # Methods for GoogleMaps creation
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
453 def showGoogleMap(self,schema='chgis',table='mpdl',id=[],doc=None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
454 logging.debug("showGoogleMap")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
455 data = self.getDataForGoogleMap(schema,table,id,doc)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
456 kmlFileName=self.getKMLname(data=data,table=table)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
457 initializeStringForGoogleMaps="""onload=\"initialize(\'http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/daten/"""+kmlFileName+"""\')\""""#+str(data)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
458 initializeStringForGoogleMaps=initializeStringForGoogleMaps.replace("None","0")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
459 googleMap_page=self.htmlHead()+str(self.getGoogleMapString(kml=initializeStringForGoogleMaps))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
460 return googleMap_page
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
461
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
462 def getKmlUrl(self,schema='chgis',table='mpdl',id=[],doc=None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
463 logging.debug("getKmlUrl")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
464 data = self.getDataForGoogleMap(schema,table,id,doc)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
465 kml=self.getKMLname(data=data,table=table)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
466 baseUrl = self.absolute_url()
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
467 return "%s/daten/%s"%(baseUrl,kml)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
468
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
469 def getDataForGoogleMap(self,schema='chgis',table='mpdl',id=[],doc=None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
470 logging.debug("getDataForGoogleMap")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
471 qstr="SELECT * FROM "+schema+"."+table
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
472 try:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
473 if id!=[]:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
474 qstr=qstr+" WHERE "
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
475 for id_item in id.split(","):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
476 if table=='mpdl':
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
477 qstr=qstr+" mpdl_xmlsource_id = '"+id_item+ "' OR"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
478 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
479 qstr=qstr+" cast(id as text) LIKE '"+id_item+ "' OR"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
480 qstr=str(qstr).rsplit(" ",1)[0] #to remove last " and "
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
481 data=self.ZSQLSimpleSearch(qstr)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
482 return data
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
483 except:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
484 return qstr
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
485
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
486 def getKMLname(self,data=[],table=""):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
487 logging.debug("getKMLname")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
488 #session=context.REQUEST.SESSION
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
489 kml4Marker="<kml xmlns=\'http://www.opengis.net/kml/2.2\'><Document><Style id=\'marker_icon\'><IconStyle><scale>15</scale><Icon><href>http://chinagis.mpiwg-berlin.mpg.de/chinagis/images/dot_red.png</href></Icon></IconStyle></Style>\n"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
490 initializeStringForGoogleMaps=""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
491 #doLine=container.getVar('doLine')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
492 # Mapping a set of points from table-based SQL-query:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
493 if data!=None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
494 try:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
495 SQL='SELECT "attribute with gis_id" FROM public.metadata WHERE tablename = %s'
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
496 res = self.executeSQL(SQL, (table,))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
497 gisIDattribute = res['rows'][0][0]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
498 except:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
499 return "table not registered within metadata"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
500
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
501 for dataset in data:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
502 try:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
503 xCoord=getattr(dataset,'longitude')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
504 yCoord=getattr(dataset,'latitude')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
505 except:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
506 try:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
507 xCoord=getattr(dataset,'x_coord')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
508 yCoord=getattr(dataset,'y_coord')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
509 except:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
510 #try:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
511 gisID=getattr(dataset,gisIDattribute)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
512 coords=self.getPoint4GISid(gisID)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
513 if coords!=None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
514 xCoord=coords[0]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
515 yCoord=coords[1]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
516 # except:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
517 # return "no coordinates found"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
518
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
519 if float(xCoord)!=0:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
520 if float(yCoord)!=0:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
521 kml4Marker=kml4Marker+"<Placemark>"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
522 kml4Marker=kml4Marker+"<description> <![CDATA[<b>"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
523 for values in dataset:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
524 if values != (None, None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
525 if str(values).find('name')>-1:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
526 kml4Marker=kml4Marker+"<name>"+str(values[1])+"</name>\n"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
527 continue
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
528 elif str(values).find('place')>-1:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
529 kml4Marker=kml4Marker+"<name>"+str(values[1])+"</name>\n"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
530 continue
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
531
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
532 kml4Marker=kml4Marker+str(values)+": "
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
533 attribute_string=str(values).replace("'","__Apostroph__")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
534 attribute_string=str(attribute_string).replace('"','__DoubleApostroph__')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
535 attribute_string=str(attribute_string).replace(';','__$$__')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
536 attribute_string=str(attribute_string).replace('&','&amp;')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
537 if str(attribute_string).find('http')>-1:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
538 attribute_string='<A HREF=' + str(attribute_string) + ' target=_blank>' + str(attribute_string) + '</A>'
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
539 kml4Marker=kml4Marker+attribute_string+"</a><br>\n"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
540
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
541 kml4Marker=kml4Marker+"]]></description>\n"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
542 kml4Marker=kml4Marker+"<styleURL>#marker_icon</styleURL>\n"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
543 kml4Marker=kml4Marker+"<Point>"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
544
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
545 kml4Marker=kml4Marker+"<coordinates>"+str(xCoord)+","+str(yCoord)+",0</coordinates>\n"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
546 kml4Marker=kml4Marker+"</Point>\n"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
547 kml4Marker=kml4Marker+"</Placemark>\n"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
548
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
549 kml4Marker=kml4Marker+"</Document>\n</kml>"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
550 kmlFileName="marker"+str(time.time())+".kml"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
551
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
552 #kml4Marker=str(kml4Marker).replace('&','$$')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
553 #kml4Marker=str(kml4Marker).replace(';','__$$__')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
554 #kml4Marker=str(kml4Marker).replace('#','__SHARP__')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
555 isLoadReady='false'
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
556 while isLoadReady=='false':
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
557 isLoadReady=self.RESTwrite2File(self.daten,kmlFileName,kml4Marker)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
558
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
559 return kmlFileName
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
560
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
561 def getGoogleMapString(self,kml):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
562 logging.debug("getGoogleMapString")
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
563 printed= '<body %s> '%kml +"""\n <div id="map_canvas" style="width: 98%; height: 95%"> </div> \n </body>" \n </html>"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
564 return printed
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
565
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
566 def getPoint4GISid(self,gis_id):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
567 j=0
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
568 coords=(0,0)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
569 if gis_id != None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
570 while (True):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
571 j=j+1
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
572 if (j>100): # FJK: just to prevent endless loops
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
573 break
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
574 if (gis_id.isdigit()): # FJK: regular exit from while-loop
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
575 break
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
576 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
577 gis_id=gis_id.strip('abcdefghijklmnopqrstuvwxyz_') # FJK: to strip all letters
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
578 gis_id=gis_id.strip() # FJK: to strip all whitespaces
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
579 resultpoint = [0,0]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
580 results = None
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
581 try:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
582 if int(gis_id)>0:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
583 SQL="SELECT x_coord,y_coord FROM chgis.chgis_coords WHERE gis_id LIKE cast("+ str(gis_id) +" as text);"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
584 results=self.ZSQLSimpleSearch(SQL)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
585 #print results
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
586 if results != None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
587 for result in results:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
588 resultpoint=[getattr(result,str('x_coord')),getattr(result,str('y_coord'))]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
589 if resultpoint !=[0,0]:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
590 return resultpoint
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
591 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
592 coords=self.getCoordsFromREST_gisID(joinid)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
593 SQL="INSERT INTO chgis.chgis_coords (gis_id,x_coord,y_coord) VALUES (" +gis_id+ "," +coords[0][1]+ "," +coords[0][0]+ "); ANALYZE chgis.chgis_coords;"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
594 returnstring=self.ZSQLSimpleSearch(SQL)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
595 return coords[0]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
596 except:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
597 return "gis_id not to interpretable:"+str(gis_id)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
598 else:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
599 return coords[0]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
600
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
601 def getCoordsFromREST_gisID(self,gis_id):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
602 coordlist=[]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
603 i=0
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
604 while (i<5 and coordlist==[]):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
605
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
606 urlresponse=container.urlFunctions.zUrlopenParseString(container.urlFunctions.zUrlopenRead("http://chgis.hmdc.harvard.edu/xml/id/"+gis_id))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
607 baseDocElement=container.urlFunctions.zUrlopenDocumentElement(urlresponse)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
608 childnodes=container.urlFunctions.zUrlopenChildNodes(baseDocElement)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
609 itemnodes=container.urlFunctions.zUrlopenGetElementsByTagName(baseDocElement,'item')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
610
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
611 for i in range(0,container.urlFunctions.zUrlopenLength(itemnodes)):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
612 itemnode=container.urlFunctions.zUrlopenGetItem(itemnodes,i)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
613 itemspatialnodes=container.urlFunctions.zUrlopenGetElementsByTagName(itemnode,'spatial')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
614 for j in range(0,container.urlFunctions.zUrlopenLength(itemspatialnodes)):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
615 coord=[]
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
616 itemspatialnode= container.urlFunctions.zUrlopenGetItem(itemspatialnodes,j)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
617 itemspatiallatnodes=container.urlFunctions.zUrlopenGetElementsByTagName(itemspatialnode,'degrees_latitude')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
618 for k in range(0,container.urlFunctions.zUrlopenLength(itemspatiallatnodes)):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
619 itemspatiallatnode= container.urlFunctions.zUrlopenGetItem(itemspatiallatnodes,k)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
620 coord.append(container.urlFunctions.zUrlopenGetTextData(itemspatiallatnode))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
621 itemspatiallngnodes=container.urlFunctions.zUrlopenGetElementsByTagName(itemspatialnode,'degrees_longitude')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
622 for k in range(0,container.urlFunctions.zUrlopenLength(itemspatiallngnodes)):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
623 itemspatiallngnode= container.urlFunctions.zUrlopenGetItem(itemspatiallngnodes,k)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
624 coord.append(container.urlFunctions.zUrlopenGetTextData(itemspatiallngnode))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
625 coordlist.append(coord)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
626 gis_id= "_"+gis_id
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
627 return coordlist
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
628
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
629 # End for GoogleMaps creation
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
630
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
631 def RESTwrite2File(self,datadir, name,text):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
632 logging.debug("RESTwrite2File datadir=%s name=%s"%(datadir,name))
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
633 try:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
634 import cStringIO as StringIO
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
635 except:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
636 import StringIO
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
637
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
638 # make filehandle from string
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
639 textfile = StringIO.StringIO(text)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
640 fileid=name
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
641 if fileid in datadir.objectIds():
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
642 datadir.manage_delObjects(fileid)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
643 fileInZope=datadir.manage_addFile(id=fileid,file=textfile)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
644 return "Write successful"
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
645
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
646 def manage_editRestDbInterface(self, title=None, connection_id=None,
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
647 REQUEST=None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
648 """Change the object"""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
649 if title is not None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
650 self.title = title
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
651
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
652 if connection_id is not None:
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
653 self.connection_id = connection_id
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
654
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
655 #checkPermission=getSecurityManager().checkPermission
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
656 REQUEST.RESPONSE.redirect('manage_main')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
657
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
658
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
659 manage_addRestDbInterfaceForm=PageTemplateFile('zpt/addRestDbInterface',globals())
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
660
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
661 def manage_addRestDbInterface(self, id, title='', label='', description='',
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
662 createPublic=0,
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
663 createUserF=0,
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
664 REQUEST=None):
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
665 """Add a new object with id *id*."""
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
666
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
667 ob=RestDbInterface(str(id),title)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
668 self._setObject(id, ob)
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
669
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
670 #checkPermission=getSecurityManager().checkPermission
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
671 REQUEST.RESPONSE.redirect('manage_main')
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
672
291aed5f0e0d new class for JSON store
casties
parents:
diff changeset
673