43
|
1 '''
|
|
2 Created on 2.9.2010
|
|
3
|
|
4 @author: casties, fknauft
|
|
5 '''
|
|
6
|
|
7 from OFS.Folder import Folder
|
|
8 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
|
|
9 from Products.ZSQLExtend import ZSQLExtend
|
|
10 import logging
|
|
11 import re
|
|
12 import time
|
61
|
13 import datetime
|
57
|
14 import urllib
|
43
|
15
|
|
16 from RestDbInterface import *
|
|
17
|
|
18
|
|
19 gisToSqlTypeMap = {
|
|
20 "text": "text",
|
|
21 "number": "numeric",
|
|
22 "id": "text",
|
|
23 "gis_id": "text",
|
|
24 "coord_lat": "numeric",
|
|
25 "coord_lon": "numeric"
|
|
26 }
|
|
27
|
55
|
28 def kmlEncode(s):
|
|
29 """returns string encoded for displaying in KML attribute"""
|
|
30 res = s.replace("'","__Apostroph__")
|
|
31 res = res.replace('"','__DoubleApostroph__')
|
|
32 res = res.replace(';','__$$__')
|
|
33 res = res.replace('&','&')
|
|
34 return res
|
|
35
|
|
36
|
43
|
37 class RestDbGisApi(RestDbInterface):
|
|
38 """Object for RESTful GIS database queries
|
|
39 path schema: /db/{schema}/{table}/
|
|
40 omitting table gives a list of schemas
|
|
41 omitting table and schema gives a list of schemas
|
|
42 """
|
|
43
|
|
44 meta_type="RESTgis"
|
|
45
|
|
46 # data templates
|
|
47 GIS_schema_table = PageTemplateFile('zpt/GIS_schema_table', globals())
|
55
|
48 KML_schema_table = PageTemplateFile('zpt/KML_schema_table', globals())
|
61
|
49 HTML_schema_usertables = PageTemplateFile('zpt/HTML_schema_usertables', globals())
|
55
|
50
|
44
|
51 # and scripts
|
|
52 def KML_URL_schema_table(self,schema,table):
|
|
53 """KML_URL table function"""
|
|
54 self.REQUEST.RESPONSE.setHeader("Content-Type", "text/plain")
|
|
55 id = self.REQUEST.get('id',[])
|
|
56 doc = self.REQUEST.get('doc',None)
|
57
|
57 return self.getLiveKmlUrl(schema=schema,table=table)
|
44
|
58
|
61
|
59 #
|
|
60 # database methods
|
|
61 #
|
60
|
62 def getTableOwner(self,schema,table):
|
|
63 """returns the owner of the table"""
|
61
|
64 # what do we do with the schema?
|
|
65 sql = 'select table_owner from public.gis_table_meta where table_name = %s'
|
|
66 res = self.executeSQL(sql,(table,))
|
|
67 if len(res['rows']) > 0:
|
|
68 return res['rows'][0][0]
|
60
|
69 return None
|
|
70
|
|
71 def isAllowed(self,action,schema,table,user=None,owner=None):
|
43
|
72 """returns if the requested action on the table is allowed"""
|
|
73 if user is None:
|
|
74 user = self.REQUEST.get('AUTHENTICATED_USER',None)
|
60
|
75 logging.debug("isAllowed action=%s schema=%s table=%s user=%s"%(action,schema,table,user))
|
|
76 if action == "create":
|
|
77 if user is not None and str(user) != 'Anonymous User':
|
|
78 # any authenticated user can create
|
|
79 return True
|
|
80 else:
|
|
81 return False
|
|
82
|
|
83 if action == "update":
|
|
84 if owner is None:
|
|
85 owner = self.getTableOwner(schema,table)
|
61
|
86 logging.debug("isAllowed user=%s owner=%s"%(user,owner))
|
60
|
87 if user is not None and str(user) == str(owner):
|
|
88 # update only your own table
|
|
89 return True
|
|
90 else:
|
|
91 return False
|
|
92
|
62
|
93 # anything else is allowed
|
43
|
94 return True
|
|
95
|
61
|
96 def setTableMetaTypes(self,schema,table,fields,user=None):
|
43
|
97 """sets the GIS meta information for table"""
|
61
|
98 if user is None:
|
|
99 user = self.REQUEST.get('AUTHENTICATED_USER',None)
|
|
100
|
|
101 logging.debug("settablemetatypes schema=%s, table=%s, fields=%s user=%s"%(schema,table,fields,user))
|
43
|
102
|
61
|
103 today = datetime.date.today().isoformat()
|
|
104
|
|
105 res = self.executeSQL('select * from public.gis_table_meta where table_name = %s', (table,))
|
43
|
106 if len(res['rows']) > 0:
|
|
107 # meta record exists
|
61
|
108 sql = 'update public.gis_table_meta set table_owner=%s, table_modified=%s where table_name=%s'
|
|
109 self.executeSQL(sql, (str(user),today,table), hasResult=False)
|
43
|
110 else:
|
|
111 # new meta record
|
61
|
112 sql = 'insert into public.gis_table_meta (table_name,table_owner,table_created) values (%s,%s,%s)'
|
|
113 self.executeSQL(sql, (table,str(user),today), hasResult=False)
|
|
114
|
|
115 # update row info
|
|
116 sql = 'delete from public.gis_table_meta_rows where table_name=%s'
|
|
117 self.executeSQL(sql,(table,),hasResult=False)
|
|
118 sql = 'insert into public.gis_table_meta_rows (table_name,field_name,gis_type) values (%s,%s,%s)'
|
|
119 for f in fields:
|
|
120 t = f['type']
|
|
121 fn = f['name']
|
|
122 self.executeSQL(sql, (table,fn,t), hasResult=False)
|
43
|
123
|
60
|
124
|
61
|
125 def getListOfUserTables(self,schema='public',username='guest'):
|
|
126 """return list of tables"""
|
|
127 logging.debug("getlistofusertables")
|
|
128 # get list of db tables
|
|
129 qstr = """SELECT t.table_name FROM information_schema.tables t, public.gis_table_meta m WHERE t.table_type = 'BASE TABLE'
|
|
130 AND t.table_schema = %s AND t.table_name = m.table_name ORDER BY 1"""
|
43
|
131
|
61
|
132 data=self.executeSQL(qstr,(schema,))
|
|
133 return data
|
|
134
|
43
|
135
|
|
136 def createEmptyTable(self,schema,table,fields):
|
|
137 """create a table with the given fields
|
|
138 returns list of created fields"""
|
61
|
139 sqlFields = RestDbInterface.createEmptyTable(self,schema,table,fields)
|
|
140 if sqlFields is not None:
|
43
|
141 self.setTableMetaTypes(schema,table,sqlFields)
|
61
|
142
|
|
143 return sqlFields
|
43
|
144
|
|
145
|
59
|
146 def getLiveKmlUrl(self,schema,table,useTimestamp=True,REQUEST=None):
|
57
|
147 if REQUEST is None:
|
|
148 REQUEST = self.REQUEST
|
55
|
149 logging.debug("getLiveKmlUrl")
|
|
150 baseUrl = self.absolute_url()
|
57
|
151 timestamp = time.time()
|
59
|
152 # filter parameters in URL and add to new URL
|
57
|
153 params = [p for p in REQUEST.form.items() if p[0] not in ('format','timestamp')]
|
|
154 params.append(('format','KML'))
|
59
|
155 if useTimestamp:
|
|
156 # add timestamp so URL changes every time
|
|
157 params.append(('timestamp',timestamp))
|
57
|
158 paramstr = urllib.urlencode(params)
|
|
159 return "%s/db/%s/%s?%s"%(baseUrl,schema,table,paramstr)
|
55
|
160
|
58
|
161 def getKmlData(self, schema, table, ids=None, sortBy=1, gisIdField=None, latField=None, lonField=None):
|
55
|
162 """returns data structure for KML template"""
|
59
|
163 logging.debug("getKMLdata gid=%s lat=%s lon=%s"%(gisIdField,latField,lonField))
|
55
|
164 # Mapping a set of points from table-based SQL-query:
|
|
165 qstr='SELECT * FROM "%s"."%s"'%(schema,table)
|
|
166 idList = None
|
|
167 if ids is not None:
|
|
168 qstr += ' WHERE '
|
|
169 if table=='mpdl':
|
|
170 qstr += 'mpdl_xmlsource_id IN ('
|
|
171 else:
|
|
172 qstr += 'CAST(id AS text) IN ('
|
|
173
|
|
174 idList = ids.split(",")
|
|
175 qstr += ','.join(['%s' for i in idList])
|
|
176 qstr += ')'
|
|
177
|
58
|
178 if sortBy:
|
|
179 # add sort clause
|
59
|
180 if sortBy == 1:
|
|
181 qstr += ' ORDER BY 1'
|
|
182 else:
|
|
183 # TODO: proper quoting for names
|
|
184 qstr += ' ORDER BY "%s"'%sortBy.replace('"','')
|
|
185
|
|
186 data = self.executeSQL(qstr,idList)
|
55
|
187
|
|
188 fieldMap = self.getFieldNameMap(data['fields'])
|
|
189
|
|
190 if (gisIdField is None) and (latField is None or lonField is None):
|
|
191 # no fields given - choose automagically
|
|
192 # gis id in metadata first
|
61
|
193 #SQL='SELECT "attribute with gis_id" FROM public.metadata WHERE tablename = %s'
|
|
194 sql = 'SELECT field_name FROM public.gis_table_meta_rows WHERE table_name = %s and gis_type = %s'
|
|
195 res = self.executeSQL(sql, (table,'gis_id'))
|
55
|
196 if len(res['rows']) > 0:
|
|
197 gisIdField = res['rows'][0][0]
|
|
198 else:
|
|
199 logging.warning("no entry in metadata table for table %s"%table)
|
|
200 # try field names
|
|
201 if 'latitude' in fieldMap and 'longitude' in fieldMap:
|
|
202 latField = 'latitude'
|
|
203 lonField = 'longitude'
|
|
204 elif 'x_coord' in fieldMap and 'y_coord' in fieldMap:
|
|
205 latField = 'x_coord'
|
|
206 lonField = 'y_coord'
|
|
207 else:
|
|
208 logging.error("getKMLdata unable to find position fields")
|
|
209 return None
|
|
210
|
|
211 # convert field names to row indexes
|
|
212 gisIdIdx = fieldMap.get(gisIdField,None)
|
|
213 latIdx = fieldMap.get(latField,None)
|
|
214 lonIdx = fieldMap.get(lonField,None)
|
|
215 logging.debug("gisidfield=%s idx=%s"%(gisIdField,gisIdIdx))
|
|
216
|
|
217 # convert data
|
|
218 kmlData = []
|
|
219 for dataset in data['rows']:
|
65
|
220 xCoord = 0.0
|
|
221 yCoord = 0.0
|
55
|
222 if gisIdIdx is not None:
|
|
223 gisID = dataset[gisIdIdx]
|
58
|
224 coords=self.getPointForChGisId(gisID)
|
55
|
225 if coords!=None:
|
|
226 xCoord=coords[0]
|
|
227 yCoord=coords[1]
|
|
228
|
|
229 elif latIdx is not None:
|
|
230 xCoord = dataset[lonIdx]
|
|
231 yCoord = dataset[latIdx]
|
|
232
|
|
233 else:
|
|
234 logging.error("getKMLdata unable to find position")
|
|
235 return None
|
|
236
|
|
237 if float(xCoord) == 0.0:
|
|
238 continue
|
|
239
|
|
240 if float(yCoord) == 0.0:
|
|
241 continue
|
|
242
|
|
243 kmlPlace = {}
|
|
244
|
|
245 # description
|
|
246 desc = ''
|
|
247 i = -1
|
|
248 for value in dataset:
|
|
249 i += 1
|
|
250 name = data['fields'][i][0]
|
58
|
251 #logging.debug("value=%s"%value)
|
55
|
252 if value != None:
|
57
|
253 #if name.find('name')>-1:
|
|
254 # desc += "<name>%s</name>\n"%value
|
|
255 # continue
|
|
256 #elif name.find('place')>-1:
|
|
257 # desc += "<name>%s</name>\n"%value
|
|
258 # continue
|
55
|
259
|
|
260 val = "%s: %s"%(name, value)
|
|
261 if val.find('http')>-1:
|
|
262 val ='<a href="' + val + '" target="_blank">' + val + '</a>'
|
|
263
|
57
|
264 #desc += kmlEncode(val)
|
|
265 desc += val
|
55
|
266 desc += '<br/>\n'
|
|
267
|
57
|
268 #kmlPlace['description'] = "<![CDATA[%s]]>"%desc
|
|
269 kmlPlace['description'] = desc
|
55
|
270 kmlPlace['icon'] = '#marker_icon'
|
|
271 kmlPlace['coord_x'] = str(xCoord)
|
|
272 kmlPlace['coord_y'] = str(yCoord)
|
|
273 kmlPlace['coord_z'] = '0'
|
|
274 kmlData.append(kmlPlace)
|
|
275
|
|
276 #logging.debug("kmlData=%s"%(repr(kmlData)))
|
|
277 return kmlData
|
58
|
278
|
|
279 def getPointForChGisId(self, gis_id):
|
|
280 """returns coordinate pair for given gis_id"""
|
59
|
281 def getPoint(id):
|
|
282 sql="SELECT x_coord,y_coord FROM chgis.chgis_coords WHERE gis_id = %s"
|
|
283 res = self.executeSQL(sql, (gis_id,))
|
|
284 if len(res['rows']) > 0:
|
|
285 return res['rows'][0]
|
|
286 return None
|
|
287
|
58
|
288 if gis_id is None or gis_id == "":
|
|
289 return None
|
|
290
|
59
|
291 # try gis_id
|
|
292 coords = getPoint(gis_id)
|
|
293 if coords is None:
|
58
|
294 # try to clean gis_id...
|
|
295 gis_id = re.sub(r'[^0-9]','',gis_id)
|
|
296 # try again
|
59
|
297 coords = getPoint(gis_id)
|
|
298 if coords is None:
|
58
|
299 logging.error("CH-GIS ID %s not found!"%repr(gis_id))
|
|
300
|
|
301 # TODO: do we need the getCoordsFromREST_gisID stuff?
|
|
302
|
59
|
303 return coords
|
|
304
|
|
305
|
|
306 ## legacy methods...
|
|
307
|
|
308 def getKmlUrl(self,schema='chgis',table='mpdl',id=[],doc=None):
|
|
309 logging.debug("getKmlUrl")
|
|
310 data = self.getDataForGoogleMap(schema,table,id,doc)
|
|
311 kml=self.getKMLname(data=data,table=table)
|
|
312 baseUrl = self.absolute_url()
|
|
313 return "%s/daten/%s"%(baseUrl,kml)
|
|
314
|
|
315 def getDataForGoogleMap(self,schema='chgis',table='mpdl',id=None,doc=None):
|
|
316 logging.debug("getDataForGoogleMap")
|
|
317 qstr="SELECT * FROM "+schema+"."+table
|
|
318 try:
|
|
319 if id is not None:
|
|
320 qstr=qstr+" WHERE "
|
|
321 for id_item in id.split(","):
|
|
322 if table=='mpdl':
|
|
323 qstr=qstr+" mpdl_xmlsource_id = '"+id_item+ "' OR"
|
|
324 else:
|
|
325 qstr=qstr+" cast(id as text) LIKE '"+id_item+ "' OR"
|
|
326 qstr=str(qstr).rsplit(" ",1)[0] #to remove last " and "
|
|
327 data=self.ZSQLSimpleSearch(qstr)
|
|
328 return data
|
|
329 except:
|
|
330 return qstr
|
55
|
331
|
|
332
|
43
|
333 def getKMLname(self,data=[],table=""):
|
|
334 logging.debug("getKMLname")
|
|
335 #session=context.REQUEST.SESSION
|
|
336 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"
|
|
337 initializeStringForGoogleMaps=""
|
|
338 #doLine=container.getVar('doLine')
|
|
339 # Mapping a set of points from table-based SQL-query:
|
|
340 if data!=None:
|
|
341 try:
|
|
342 SQL='SELECT "attribute with gis_id" FROM public.metadata WHERE tablename = %s'
|
|
343 res = self.executeSQL(SQL, (table,))
|
|
344 gisIDattribute = res['rows'][0][0]
|
|
345 except:
|
|
346 return "table not registered within metadata"
|
|
347
|
|
348 for dataset in data:
|
|
349 try:
|
|
350 xCoord=getattr(dataset,'longitude')
|
|
351 yCoord=getattr(dataset,'latitude')
|
|
352 except:
|
|
353 try:
|
|
354 xCoord=getattr(dataset,'x_coord')
|
|
355 yCoord=getattr(dataset,'y_coord')
|
|
356 except:
|
|
357 #try:
|
|
358 gisID=getattr(dataset,gisIDattribute)
|
|
359 coords=self.getPoint4GISid(gisID)
|
|
360 if coords!=None:
|
|
361 xCoord=coords[0]
|
|
362 yCoord=coords[1]
|
|
363 # except:
|
|
364 # return "no coordinates found"
|
|
365
|
|
366 if float(xCoord)!=0:
|
|
367 if float(yCoord)!=0:
|
|
368 kml4Marker=kml4Marker+"<Placemark>"
|
|
369 kml4Marker=kml4Marker+"<description> <![CDATA[<b>"
|
|
370 for values in dataset:
|
55
|
371 #logging.debug("values=%s"%repr(values))
|
43
|
372 if values != (None, None):
|
|
373 if str(values).find('name')>-1:
|
|
374 kml4Marker=kml4Marker+"<name>"+str(values[1])+"</name>\n"
|
|
375 continue
|
|
376 elif str(values).find('place')>-1:
|
|
377 kml4Marker=kml4Marker+"<name>"+str(values[1])+"</name>\n"
|
|
378 continue
|
|
379
|
|
380 kml4Marker=kml4Marker+str(values)+": "
|
|
381 attribute_string=str(values).replace("'","__Apostroph__")
|
|
382 attribute_string=str(attribute_string).replace('"','__DoubleApostroph__')
|
|
383 attribute_string=str(attribute_string).replace(';','__$$__')
|
|
384 attribute_string=str(attribute_string).replace('&','&')
|
|
385 if str(attribute_string).find('http')>-1:
|
|
386 attribute_string='<A HREF=' + str(attribute_string) + ' target=_blank>' + str(attribute_string) + '</A>'
|
|
387 kml4Marker=kml4Marker+attribute_string+"</a><br>\n"
|
|
388
|
|
389 kml4Marker=kml4Marker+"]]></description>\n"
|
|
390 kml4Marker=kml4Marker+"<styleURL>#marker_icon</styleURL>\n"
|
|
391 kml4Marker=kml4Marker+"<Point>"
|
|
392
|
|
393 kml4Marker=kml4Marker+"<coordinates>"+str(xCoord)+","+str(yCoord)+",0</coordinates>\n"
|
|
394 kml4Marker=kml4Marker+"</Point>\n"
|
|
395 kml4Marker=kml4Marker+"</Placemark>\n"
|
|
396
|
|
397 kml4Marker=kml4Marker+"</Document>\n</kml>"
|
|
398 kmlFileName="marker"+str(time.time())+".kml"
|
|
399
|
|
400 #kml4Marker=str(kml4Marker).replace('&','$$')
|
|
401 #kml4Marker=str(kml4Marker).replace(';','__$$__')
|
|
402 #kml4Marker=str(kml4Marker).replace('#','__SHARP__')
|
|
403 isLoadReady='false'
|
|
404 while isLoadReady=='false':
|
|
405 isLoadReady=self.RESTwrite2File(self.daten,kmlFileName,kml4Marker)
|
|
406
|
|
407 return kmlFileName
|
|
408
|
44
|
409 # def getGoogleMapString(self,kml):
|
|
410 # logging.debug("getGoogleMapString")
|
|
411 # printed= '<body %s> '%kml +"""\n <div id="map_canvas" style="width: 98%; height: 95%"> </div> \n </body>" \n </html>"""
|
|
412 # return printed
|
43
|
413
|
|
414 def getPoint4GISid(self,gis_id):
|
|
415 j=0
|
|
416 coords=(0,0)
|
|
417 if gis_id != None:
|
|
418 while (True):
|
|
419 j=j+1
|
|
420 if (j>100): # FJK: just to prevent endless loops
|
|
421 break
|
|
422 if (gis_id.isdigit()): # FJK: regular exit from while-loop
|
|
423 break
|
|
424 else:
|
|
425 gis_id=gis_id.strip('abcdefghijklmnopqrstuvwxyz_') # FJK: to strip all letters
|
|
426 gis_id=gis_id.strip() # FJK: to strip all whitespaces
|
|
427 resultpoint = [0,0]
|
|
428 results = None
|
|
429 try:
|
|
430 if int(gis_id)>0:
|
|
431 SQL="SELECT x_coord,y_coord FROM chgis.chgis_coords WHERE gis_id LIKE cast("+ str(gis_id) +" as text);"
|
|
432 results=self.ZSQLSimpleSearch(SQL)
|
|
433 #print results
|
|
434 if results != None:
|
|
435 for result in results:
|
|
436 resultpoint=[getattr(result,str('x_coord')),getattr(result,str('y_coord'))]
|
|
437 if resultpoint !=[0,0]:
|
|
438 return resultpoint
|
|
439 else:
|
|
440 coords=self.getCoordsFromREST_gisID(joinid)
|
|
441 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;"
|
|
442 returnstring=self.ZSQLSimpleSearch(SQL)
|
|
443 return coords[0]
|
|
444 except:
|
|
445 return "gis_id not to interpretable:"+str(gis_id)
|
|
446 else:
|
|
447 return coords[0]
|
|
448
|
|
449 def getCoordsFromREST_gisID(self,gis_id):
|
|
450 coordlist=[]
|
|
451 i=0
|
|
452 while (i<5 and coordlist==[]):
|
|
453
|
|
454 urlresponse=container.urlFunctions.zUrlopenParseString(container.urlFunctions.zUrlopenRead("http://chgis.hmdc.harvard.edu/xml/id/"+gis_id))
|
|
455 baseDocElement=container.urlFunctions.zUrlopenDocumentElement(urlresponse)
|
|
456 childnodes=container.urlFunctions.zUrlopenChildNodes(baseDocElement)
|
|
457 itemnodes=container.urlFunctions.zUrlopenGetElementsByTagName(baseDocElement,'item')
|
|
458
|
|
459 for i in range(0,container.urlFunctions.zUrlopenLength(itemnodes)):
|
|
460 itemnode=container.urlFunctions.zUrlopenGetItem(itemnodes,i)
|
|
461 itemspatialnodes=container.urlFunctions.zUrlopenGetElementsByTagName(itemnode,'spatial')
|
|
462 for j in range(0,container.urlFunctions.zUrlopenLength(itemspatialnodes)):
|
|
463 coord=[]
|
|
464 itemspatialnode= container.urlFunctions.zUrlopenGetItem(itemspatialnodes,j)
|
|
465 itemspatiallatnodes=container.urlFunctions.zUrlopenGetElementsByTagName(itemspatialnode,'degrees_latitude')
|
|
466 for k in range(0,container.urlFunctions.zUrlopenLength(itemspatiallatnodes)):
|
|
467 itemspatiallatnode= container.urlFunctions.zUrlopenGetItem(itemspatiallatnodes,k)
|
|
468 coord.append(container.urlFunctions.zUrlopenGetTextData(itemspatiallatnode))
|
|
469 itemspatiallngnodes=container.urlFunctions.zUrlopenGetElementsByTagName(itemspatialnode,'degrees_longitude')
|
|
470 for k in range(0,container.urlFunctions.zUrlopenLength(itemspatiallngnodes)):
|
|
471 itemspatiallngnode= container.urlFunctions.zUrlopenGetItem(itemspatiallngnodes,k)
|
|
472 coord.append(container.urlFunctions.zUrlopenGetTextData(itemspatiallngnode))
|
|
473 coordlist.append(coord)
|
|
474 gis_id= "_"+gis_id
|
|
475 return coordlist
|
|
476
|
|
477 # End for GoogleMaps creation
|
|
478
|
|
479 def RESTwrite2File(self,datadir, name,text):
|
|
480 logging.debug("RESTwrite2File datadir=%s name=%s"%(datadir,name))
|
|
481 try:
|
|
482 import cStringIO as StringIO
|
|
483 except:
|
|
484 import StringIO
|
|
485
|
|
486 # make filehandle from string
|
|
487 textfile = StringIO.StringIO(text)
|
|
488 fileid=name
|
|
489 if fileid in datadir.objectIds():
|
|
490 datadir.manage_delObjects(fileid)
|
|
491 fileInZope=datadir.manage_addFile(id=fileid,file=textfile)
|
|
492 return "Write successful"
|
|
493
|
|
494 def manage_editRestDbGisApi(self, title=None, connection_id=None,
|
|
495 REQUEST=None):
|
|
496 """Change the object"""
|
|
497 if title is not None:
|
|
498 self.title = title
|
|
499
|
|
500 if connection_id is not None:
|
|
501 self.connection_id = connection_id
|
|
502
|
|
503 #checkPermission=getSecurityManager().checkPermission
|
|
504 REQUEST.RESPONSE.redirect('manage_main')
|
|
505
|
|
506
|
|
507 manage_addRestDbGisApiForm=PageTemplateFile('zpt/addRestDbGisApi',globals())
|
|
508
|
|
509 def manage_addRestDbGisApi(self, id, title='', label='', description='',
|
|
510 createPublic=0,
|
|
511 createUserF=0,
|
|
512 REQUEST=None):
|
|
513 """Add a new object with id *id*."""
|
|
514
|
|
515 ob=RestDbGisApi(str(id),title)
|
|
516 self._setObject(id, ob)
|
|
517
|
|
518 #checkPermission=getSecurityManager().checkPermission
|
|
519 REQUEST.RESPONSE.redirect('manage_main')
|
|
520
|
|
521
|