annotate RestDbJsonStore.py @ 43:562717546168

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