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