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']:
|
|
220 if gisIdIdx is not None:
|
|
221 gisID = dataset[gisIdIdx]
|
58
|
222 coords=self.getPointForChGisId(gisID)
|
55
|
223 if coords!=None:
|
|
224 xCoord=coords[0]
|
|
225 yCoord=coords[1]
|
|
226
|
|
227 elif latIdx is not None:
|
|
228 xCoord = dataset[lonIdx]
|
|
229 yCoord = dataset[latIdx]
|
|
230
|
|
231 else:
|
|
232 logging.error("getKMLdata unable to find position")
|
|
233 return None
|
|
234
|
|
235 if float(xCoord) == 0.0:
|
|
236 continue
|
|
237
|
|
238 if float(yCoord) == 0.0:
|
|
239 continue
|
|
240
|
|
241 kmlPlace = {}
|
|
242
|
|
243 # description
|
|
244 desc = ''
|
|
245 i = -1
|
|
246 for value in dataset:
|
|
247 i += 1
|
|
248 name = data['fields'][i][0]
|
58
|
249 #logging.debug("value=%s"%value)
|
55
|
250 if value != None:
|
57
|
251 #if name.find('name')>-1:
|
|
252 # desc += "<name>%s</name>\n"%value
|
|
253 # continue
|
|
254 #elif name.find('place')>-1:
|
|
255 # desc += "<name>%s</name>\n"%value
|
|
256 # continue
|
55
|
257
|
|
258 val = "%s: %s"%(name, value)
|
|
259 if val.find('http')>-1:
|
|
260 val ='<a href="' + val + '" target="_blank">' + val + '</a>'
|
|
261
|
57
|
262 #desc += kmlEncode(val)
|
|
263 desc += val
|
55
|
264 desc += '<br/>\n'
|
|
265
|
57
|
266 #kmlPlace['description'] = "<![CDATA[%s]]>"%desc
|
|
267 kmlPlace['description'] = desc
|
55
|
268 kmlPlace['icon'] = '#marker_icon'
|
|
269 kmlPlace['coord_x'] = str(xCoord)
|
|
270 kmlPlace['coord_y'] = str(yCoord)
|
|
271 kmlPlace['coord_z'] = '0'
|
|
272 kmlData.append(kmlPlace)
|
|
273
|
|
274 #logging.debug("kmlData=%s"%(repr(kmlData)))
|
|
275 return kmlData
|
58
|
276
|
|
277 def getPointForChGisId(self, gis_id):
|
|
278 """returns coordinate pair for given gis_id"""
|
59
|
279 def getPoint(id):
|
|
280 sql="SELECT x_coord,y_coord FROM chgis.chgis_coords WHERE gis_id = %s"
|
|
281 res = self.executeSQL(sql, (gis_id,))
|
|
282 if len(res['rows']) > 0:
|
|
283 return res['rows'][0]
|
|
284 return None
|
|
285
|
58
|
286 if gis_id is None or gis_id == "":
|
|
287 return None
|
|
288
|
59
|
289 # try gis_id
|
|
290 coords = getPoint(gis_id)
|
|
291 if coords is None:
|
58
|
292 # try to clean gis_id...
|
|
293 gis_id = re.sub(r'[^0-9]','',gis_id)
|
|
294 # try again
|
59
|
295 coords = getPoint(gis_id)
|
|
296 if coords is None:
|
58
|
297 logging.error("CH-GIS ID %s not found!"%repr(gis_id))
|
|
298
|
|
299 # TODO: do we need the getCoordsFromREST_gisID stuff?
|
|
300
|
59
|
301 return coords
|
|
302
|
|
303
|
|
304 ## legacy methods...
|
|
305
|
|
306 def getKmlUrl(self,schema='chgis',table='mpdl',id=[],doc=None):
|
|
307 logging.debug("getKmlUrl")
|
|
308 data = self.getDataForGoogleMap(schema,table,id,doc)
|
|
309 kml=self.getKMLname(data=data,table=table)
|
|
310 baseUrl = self.absolute_url()
|
|
311 return "%s/daten/%s"%(baseUrl,kml)
|
|
312
|
|
313 def getDataForGoogleMap(self,schema='chgis',table='mpdl',id=None,doc=None):
|
|
314 logging.debug("getDataForGoogleMap")
|
|
315 qstr="SELECT * FROM "+schema+"."+table
|
|
316 try:
|
|
317 if id is not None:
|
|
318 qstr=qstr+" WHERE "
|
|
319 for id_item in id.split(","):
|
|
320 if table=='mpdl':
|
|
321 qstr=qstr+" mpdl_xmlsource_id = '"+id_item+ "' OR"
|
|
322 else:
|
|
323 qstr=qstr+" cast(id as text) LIKE '"+id_item+ "' OR"
|
|
324 qstr=str(qstr).rsplit(" ",1)[0] #to remove last " and "
|
|
325 data=self.ZSQLSimpleSearch(qstr)
|
|
326 return data
|
|
327 except:
|
|
328 return qstr
|
55
|
329
|
|
330
|
43
|
331 def getKMLname(self,data=[],table=""):
|
|
332 logging.debug("getKMLname")
|
|
333 #session=context.REQUEST.SESSION
|
|
334 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"
|
|
335 initializeStringForGoogleMaps=""
|
|
336 #doLine=container.getVar('doLine')
|
|
337 # Mapping a set of points from table-based SQL-query:
|
|
338 if data!=None:
|
|
339 try:
|
|
340 SQL='SELECT "attribute with gis_id" FROM public.metadata WHERE tablename = %s'
|
|
341 res = self.executeSQL(SQL, (table,))
|
|
342 gisIDattribute = res['rows'][0][0]
|
|
343 except:
|
|
344 return "table not registered within metadata"
|
|
345
|
|
346 for dataset in data:
|
|
347 try:
|
|
348 xCoord=getattr(dataset,'longitude')
|
|
349 yCoord=getattr(dataset,'latitude')
|
|
350 except:
|
|
351 try:
|
|
352 xCoord=getattr(dataset,'x_coord')
|
|
353 yCoord=getattr(dataset,'y_coord')
|
|
354 except:
|
|
355 #try:
|
|
356 gisID=getattr(dataset,gisIDattribute)
|
|
357 coords=self.getPoint4GISid(gisID)
|
|
358 if coords!=None:
|
|
359 xCoord=coords[0]
|
|
360 yCoord=coords[1]
|
|
361 # except:
|
|
362 # return "no coordinates found"
|
|
363
|
|
364 if float(xCoord)!=0:
|
|
365 if float(yCoord)!=0:
|
|
366 kml4Marker=kml4Marker+"<Placemark>"
|
|
367 kml4Marker=kml4Marker+"<description> <![CDATA[<b>"
|
|
368 for values in dataset:
|
55
|
369 #logging.debug("values=%s"%repr(values))
|
43
|
370 if values != (None, None):
|
|
371 if str(values).find('name')>-1:
|
|
372 kml4Marker=kml4Marker+"<name>"+str(values[1])+"</name>\n"
|
|
373 continue
|
|
374 elif str(values).find('place')>-1:
|
|
375 kml4Marker=kml4Marker+"<name>"+str(values[1])+"</name>\n"
|
|
376 continue
|
|
377
|
|
378 kml4Marker=kml4Marker+str(values)+": "
|
|
379 attribute_string=str(values).replace("'","__Apostroph__")
|
|
380 attribute_string=str(attribute_string).replace('"','__DoubleApostroph__')
|
|
381 attribute_string=str(attribute_string).replace(';','__$$__')
|
|
382 attribute_string=str(attribute_string).replace('&','&')
|
|
383 if str(attribute_string).find('http')>-1:
|
|
384 attribute_string='<A HREF=' + str(attribute_string) + ' target=_blank>' + str(attribute_string) + '</A>'
|
|
385 kml4Marker=kml4Marker+attribute_string+"</a><br>\n"
|
|
386
|
|
387 kml4Marker=kml4Marker+"]]></description>\n"
|
|
388 kml4Marker=kml4Marker+"<styleURL>#marker_icon</styleURL>\n"
|
|
389 kml4Marker=kml4Marker+"<Point>"
|
|
390
|
|
391 kml4Marker=kml4Marker+"<coordinates>"+str(xCoord)+","+str(yCoord)+",0</coordinates>\n"
|
|
392 kml4Marker=kml4Marker+"</Point>\n"
|
|
393 kml4Marker=kml4Marker+"</Placemark>\n"
|
|
394
|
|
395 kml4Marker=kml4Marker+"</Document>\n</kml>"
|
|
396 kmlFileName="marker"+str(time.time())+".kml"
|
|
397
|
|
398 #kml4Marker=str(kml4Marker).replace('&','$$')
|
|
399 #kml4Marker=str(kml4Marker).replace(';','__$$__')
|
|
400 #kml4Marker=str(kml4Marker).replace('#','__SHARP__')
|
|
401 isLoadReady='false'
|
|
402 while isLoadReady=='false':
|
|
403 isLoadReady=self.RESTwrite2File(self.daten,kmlFileName,kml4Marker)
|
|
404
|
|
405 return kmlFileName
|
|
406
|
44
|
407 # def getGoogleMapString(self,kml):
|
|
408 # logging.debug("getGoogleMapString")
|
|
409 # printed= '<body %s> '%kml +"""\n <div id="map_canvas" style="width: 98%; height: 95%"> </div> \n </body>" \n </html>"""
|
|
410 # return printed
|
43
|
411
|
|
412 def getPoint4GISid(self,gis_id):
|
|
413 j=0
|
|
414 coords=(0,0)
|
|
415 if gis_id != None:
|
|
416 while (True):
|
|
417 j=j+1
|
|
418 if (j>100): # FJK: just to prevent endless loops
|
|
419 break
|
|
420 if (gis_id.isdigit()): # FJK: regular exit from while-loop
|
|
421 break
|
|
422 else:
|
|
423 gis_id=gis_id.strip('abcdefghijklmnopqrstuvwxyz_') # FJK: to strip all letters
|
|
424 gis_id=gis_id.strip() # FJK: to strip all whitespaces
|
|
425 resultpoint = [0,0]
|
|
426 results = None
|
|
427 try:
|
|
428 if int(gis_id)>0:
|
|
429 SQL="SELECT x_coord,y_coord FROM chgis.chgis_coords WHERE gis_id LIKE cast("+ str(gis_id) +" as text);"
|
|
430 results=self.ZSQLSimpleSearch(SQL)
|
|
431 #print results
|
|
432 if results != None:
|
|
433 for result in results:
|
|
434 resultpoint=[getattr(result,str('x_coord')),getattr(result,str('y_coord'))]
|
|
435 if resultpoint !=[0,0]:
|
|
436 return resultpoint
|
|
437 else:
|
|
438 coords=self.getCoordsFromREST_gisID(joinid)
|
|
439 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;"
|
|
440 returnstring=self.ZSQLSimpleSearch(SQL)
|
|
441 return coords[0]
|
|
442 except:
|
|
443 return "gis_id not to interpretable:"+str(gis_id)
|
|
444 else:
|
|
445 return coords[0]
|
|
446
|
|
447 def getCoordsFromREST_gisID(self,gis_id):
|
|
448 coordlist=[]
|
|
449 i=0
|
|
450 while (i<5 and coordlist==[]):
|
|
451
|
|
452 urlresponse=container.urlFunctions.zUrlopenParseString(container.urlFunctions.zUrlopenRead("http://chgis.hmdc.harvard.edu/xml/id/"+gis_id))
|
|
453 baseDocElement=container.urlFunctions.zUrlopenDocumentElement(urlresponse)
|
|
454 childnodes=container.urlFunctions.zUrlopenChildNodes(baseDocElement)
|
|
455 itemnodes=container.urlFunctions.zUrlopenGetElementsByTagName(baseDocElement,'item')
|
|
456
|
|
457 for i in range(0,container.urlFunctions.zUrlopenLength(itemnodes)):
|
|
458 itemnode=container.urlFunctions.zUrlopenGetItem(itemnodes,i)
|
|
459 itemspatialnodes=container.urlFunctions.zUrlopenGetElementsByTagName(itemnode,'spatial')
|
|
460 for j in range(0,container.urlFunctions.zUrlopenLength(itemspatialnodes)):
|
|
461 coord=[]
|
|
462 itemspatialnode= container.urlFunctions.zUrlopenGetItem(itemspatialnodes,j)
|
|
463 itemspatiallatnodes=container.urlFunctions.zUrlopenGetElementsByTagName(itemspatialnode,'degrees_latitude')
|
|
464 for k in range(0,container.urlFunctions.zUrlopenLength(itemspatiallatnodes)):
|
|
465 itemspatiallatnode= container.urlFunctions.zUrlopenGetItem(itemspatiallatnodes,k)
|
|
466 coord.append(container.urlFunctions.zUrlopenGetTextData(itemspatiallatnode))
|
|
467 itemspatiallngnodes=container.urlFunctions.zUrlopenGetElementsByTagName(itemspatialnode,'degrees_longitude')
|
|
468 for k in range(0,container.urlFunctions.zUrlopenLength(itemspatiallngnodes)):
|
|
469 itemspatiallngnode= container.urlFunctions.zUrlopenGetItem(itemspatiallngnodes,k)
|
|
470 coord.append(container.urlFunctions.zUrlopenGetTextData(itemspatiallngnode))
|
|
471 coordlist.append(coord)
|
|
472 gis_id= "_"+gis_id
|
|
473 return coordlist
|
|
474
|
|
475 # End for GoogleMaps creation
|
|
476
|
|
477 def RESTwrite2File(self,datadir, name,text):
|
|
478 logging.debug("RESTwrite2File datadir=%s name=%s"%(datadir,name))
|
|
479 try:
|
|
480 import cStringIO as StringIO
|
|
481 except:
|
|
482 import StringIO
|
|
483
|
|
484 # make filehandle from string
|
|
485 textfile = StringIO.StringIO(text)
|
|
486 fileid=name
|
|
487 if fileid in datadir.objectIds():
|
|
488 datadir.manage_delObjects(fileid)
|
|
489 fileInZope=datadir.manage_addFile(id=fileid,file=textfile)
|
|
490 return "Write successful"
|
|
491
|
|
492 def manage_editRestDbGisApi(self, title=None, connection_id=None,
|
|
493 REQUEST=None):
|
|
494 """Change the object"""
|
|
495 if title is not None:
|
|
496 self.title = title
|
|
497
|
|
498 if connection_id is not None:
|
|
499 self.connection_id = connection_id
|
|
500
|
|
501 #checkPermission=getSecurityManager().checkPermission
|
|
502 REQUEST.RESPONSE.redirect('manage_main')
|
|
503
|
|
504
|
|
505 manage_addRestDbGisApiForm=PageTemplateFile('zpt/addRestDbGisApi',globals())
|
|
506
|
|
507 def manage_addRestDbGisApi(self, id, title='', label='', description='',
|
|
508 createPublic=0,
|
|
509 createUserF=0,
|
|
510 REQUEST=None):
|
|
511 """Add a new object with id *id*."""
|
|
512
|
|
513 ob=RestDbGisApi(str(id),title)
|
|
514 self._setObject(id, ob)
|
|
515
|
|
516 #checkPermission=getSecurityManager().checkPermission
|
|
517 REQUEST.RESPONSE.redirect('manage_main')
|
|
518
|
|
519
|