annotate RestDbInterface.py @ 37:b356b86773a1

Merge with falks stuff b915bce653725bd0690605119fc9b3123253e560
author casties
date Wed, 01 Sep 2010 18:47:06 +0200
parents 55dbaea75e66 b915bce65372
children f6d9a3caf986
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
1 '''
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
2 Created on 19.5.2010
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
3
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
4 @author: casties
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
5 '''
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
6
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
7 from OFS.Folder import Folder
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
8 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
9 from Products.ZSQLExtend import ZSQLExtend
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
10 import logging
15
5e3edf980813 more work on xml import
casties
parents: 14
diff changeset
11 import re
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
12 import psycopg2
18
060797795a4d work on json return values
casties
parents: 17
diff changeset
13 import json
36
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
14 import time
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
15
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
16 from zope.interface import implements
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
17 from zope.publisher.interfaces import IPublishTraverse
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
18 from ZPublisher.BaseRequest import DefaultPublishTraverse
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
19 #from zope.publisher.interfaces import NotFound
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
20 #from zope.app import zapi
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
21 #from zope.component import queryMultiAdapter
4
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
22 import Shared.DC.ZRDB.DA
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
23 from Products.ZSQLMethods.SQL import SQLConnectionIDs
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
24
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
25
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
26 def getTextFromNode(node):
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
27 """get the cdata content of a XML node"""
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
28 if node is None:
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
29 return ""
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
30
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
31 if isinstance(node, list):
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
32 nodelist = node
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
33 else:
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
34 nodelist=node.childNodes
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
35
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
36 rc = ""
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
37 for node in nodelist:
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
38 if node.nodeType == node.TEXT_NODE:
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
39 rc = rc + node.data
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
40 return rc
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
41
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
42 def sqlName(s,lc=True):
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
43 """returns restricted ASCII-only version of string"""
15
5e3edf980813 more work on xml import
casties
parents: 14
diff changeset
44 if s is None:
5e3edf980813 more work on xml import
casties
parents: 14
diff changeset
45 return ""
5e3edf980813 more work on xml import
casties
parents: 14
diff changeset
46
5e3edf980813 more work on xml import
casties
parents: 14
diff changeset
47 # all else -> "_"
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
48 s = re.sub(r'[^A-Za-z0-9_]','_',s)
15
5e3edf980813 more work on xml import
casties
parents: 14
diff changeset
49 if lc:
5e3edf980813 more work on xml import
casties
parents: 14
diff changeset
50 return s.lower()
5e3edf980813 more work on xml import
casties
parents: 14
diff changeset
51
5e3edf980813 more work on xml import
casties
parents: 14
diff changeset
52 return s
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
53
31
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
54 gisToSqlTypeMap = {
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
55 "text": "text",
32
c732c2ff61d9 fixed sql data types
casties
parents: 31
diff changeset
56 "number": "numeric",
31
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
57 "id": "text",
32
c732c2ff61d9 fixed sql data types
casties
parents: 31
diff changeset
58 "gis_id": "text",
c732c2ff61d9 fixed sql data types
casties
parents: 31
diff changeset
59 "coord_lat": "numeric",
c732c2ff61d9 fixed sql data types
casties
parents: 31
diff changeset
60 "coord_lon": "numeric"
31
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
61 }
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
62
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
63 class RestDbInterface(Folder):
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
64 """Object for RESTful database queries
7
bd52d9445a41 trying to rework
casties
parents: 5
diff changeset
65 path schema: /db/{schema}/{table}/
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
66 omitting table gives a list of schemas
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
67 omitting table and schema gives a list of schemas
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
68 """
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
69 implements(IPublishTraverse)
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
70
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
71 meta_type="RESTdb"
4
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
72 manage_options=Folder.manage_options+(
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
73 {'label':'Config','action':'manage_editRestDbInterfaceForm'},
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
74 )
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
75
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
76 # management templates
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
77 manage_editRestDbInterfaceForm=PageTemplateFile('zpt/editRestDbInterface',globals())
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
78
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
79 # data templates
8
a9a49f5765c9 reworking templates and schema
casties
parents: 7
diff changeset
80 XML_index = PageTemplateFile('zpt/XML_index', globals())
a9a49f5765c9 reworking templates and schema
casties
parents: 7
diff changeset
81 XML_schema = PageTemplateFile('zpt/XML_schema', globals())
a9a49f5765c9 reworking templates and schema
casties
parents: 7
diff changeset
82 XML_schema_table = PageTemplateFile('zpt/XML_schema_table', globals())
a9a49f5765c9 reworking templates and schema
casties
parents: 7
diff changeset
83 HTML_index = PageTemplateFile('zpt/HTML_index', globals())
a9a49f5765c9 reworking templates and schema
casties
parents: 7
diff changeset
84 HTML_schema = PageTemplateFile('zpt/HTML_schema', globals())
a9a49f5765c9 reworking templates and schema
casties
parents: 7
diff changeset
85 HTML_schema_table = PageTemplateFile('zpt/HTML_schema_table', globals())
22
1a4b56716902 NEW - # 12: create table and upload data
casties
parents: 21
diff changeset
86 JSONHTML_index = PageTemplateFile('zpt/JSONHTML_index', globals())
1a4b56716902 NEW - # 12: create table and upload data
casties
parents: 21
diff changeset
87 JSONHTML_schema = PageTemplateFile('zpt/JSONHTML_schema', globals())
1a4b56716902 NEW - # 12: create table and upload data
casties
parents: 21
diff changeset
88 JSONHTML_schema_table = PageTemplateFile('zpt/JSONHTML_schema_table', globals())
24
f3811d9a36da start adding checkuploadtable
casties
parents: 23
diff changeset
89 # JSON_* templates are scripts
30
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
90 def JSON_index(self,data):
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
91 """JSON index function"""
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
92 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
93 json.dump(data, self.REQUEST.RESPONSE)
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
94
30
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
95 def JSON_schema(self,data,schema):
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
96 """JSON index function"""
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
97 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
98 json.dump(data, self.REQUEST.RESPONSE)
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
99
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
100 def JSON_schema_table(self,data,tablename):
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
101 """JSON index function"""
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
102 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json")
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
103 json.dump(data, self.REQUEST.RESPONSE)
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
104
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
105
4
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
106 def __init__(self, id, title, connection_id=None):
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
107 """init"""
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
108 self.id = id
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
109 self.title = title
4
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
110 # database connection id
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
111 self.connection_id = connection_id
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
112 # create template folder
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
113 self.manage_addFolder('template')
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
114
4
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
115
22
1a4b56716902 NEW - # 12: create table and upload data
casties
parents: 21
diff changeset
116 def getJsonString(self,object):
1a4b56716902 NEW - # 12: create table and upload data
casties
parents: 21
diff changeset
117 """returns a JSON formatted string from object"""
1a4b56716902 NEW - # 12: create table and upload data
casties
parents: 21
diff changeset
118 return json.dumps(object)
1a4b56716902 NEW - # 12: create table and upload data
casties
parents: 21
diff changeset
119
17
ed997e639cfd more upload table
casties
parents: 16
diff changeset
120 def getCursor(self,autocommit=True):
4
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
121 """returns fresh DB cursor"""
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
122 conn = getattr(self,"_v_database_connection",None)
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
123 if conn is None:
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
124 # create a new connection object
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
125 try:
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
126 if self.connection_id is None:
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
127 # try to take the first existing ID
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
128 connids = SQLConnectionIDs(self)
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
129 if len(connids) > 0:
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
130 connection_id = connids[0][0]
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
131 self.connection_id = connection_id
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
132 logging.debug("connection_id: %s"%repr(connection_id))
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
133
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
134 da = getattr(self, self.connection_id)
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
135 da.connect('')
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
136 # we copy the DAs database connection
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
137 conn = da._v_database_connection
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
138 #conn._register() # register with the Zope transaction system
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
139 self._v_database_connection = conn
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
140 except Exception, e:
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
141 raise IOError("No database connection! (%s)"%str(e))
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
142
5
7539a9e69365 small fix
casties
parents: 4
diff changeset
143 cursor = conn.getcursor()
17
ed997e639cfd more upload table
casties
parents: 16
diff changeset
144 if autocommit:
ed997e639cfd more upload table
casties
parents: 16
diff changeset
145 # is there a better version to get to the connection?
ed997e639cfd more upload table
casties
parents: 16
diff changeset
146 cursor.connection.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
ed997e639cfd more upload table
casties
parents: 16
diff changeset
147
4
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
148 return cursor
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
149
17
ed997e639cfd more upload table
casties
parents: 16
diff changeset
150 def executeSQL(self, query, args=None, hasResult=True, autocommit=True):
4
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
151 """execute query with args on database and return all results.
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
152 result format: {"fields":fields, "rows":data}"""
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
153 logging.debug("executeSQL query=%s args=%s"%(query,args))
17
ed997e639cfd more upload table
casties
parents: 16
diff changeset
154 cur = self.getCursor(autocommit=autocommit)
4
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
155 cur.execute(query, args)
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
156 # description of returned fields
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
157 fields = cur.description
17
ed997e639cfd more upload table
casties
parents: 16
diff changeset
158 if hasResult:
ed997e639cfd more upload table
casties
parents: 16
diff changeset
159 # get all data in an array
ed997e639cfd more upload table
casties
parents: 16
diff changeset
160 data = cur.fetchall()
ed997e639cfd more upload table
casties
parents: 16
diff changeset
161 cur.close()
ed997e639cfd more upload table
casties
parents: 16
diff changeset
162 return {"fields":fields, "rows":data}
ed997e639cfd more upload table
casties
parents: 16
diff changeset
163 else:
ed997e639cfd more upload table
casties
parents: 16
diff changeset
164 cur.close()
ed997e639cfd more upload table
casties
parents: 16
diff changeset
165 return None
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
166
33
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
167 def checkTableMetaPermission(self,action,schema,table,user=None):
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
168 """returns if the requested action on the table is allowed"""
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
169 logging.debug("checktablemetapermissions action=%s schema=%s table=%s user=%s"%(action,schema,table,user))
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
170 if user is None:
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
171 user = self.REQUEST.get('AUTHENTICATED_USER',None)
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
172 logging.debug("user=%s"%user)
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
173 # TODO: what now?
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
174 return True
4
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
175
31
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
176 def setTableMetaTypes(self,schema,table,fields):
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
177 """sets the GIS meta information for table"""
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
178 logging.debug("settablemetatypes schema=%s, table=%s, fields=%s"%(schema,table,fields))
35
55dbaea75e66 more work on types
casties
parents: 34
diff changeset
179 gisIdField = None
55dbaea75e66 more work on types
casties
parents: 34
diff changeset
180 latField = None
55dbaea75e66 more work on types
casties
parents: 34
diff changeset
181 lonField = None
55dbaea75e66 more work on types
casties
parents: 34
diff changeset
182 for f in fields:
55dbaea75e66 more work on types
casties
parents: 34
diff changeset
183 t = f['type']
55dbaea75e66 more work on types
casties
parents: 34
diff changeset
184 if t == 'gis_id':
55dbaea75e66 more work on types
casties
parents: 34
diff changeset
185 gisIdField = f['name']
55dbaea75e66 more work on types
casties
parents: 34
diff changeset
186 elif t == 'coord_lat':
55dbaea75e66 more work on types
casties
parents: 34
diff changeset
187 latField = f['name']
55dbaea75e66 more work on types
casties
parents: 34
diff changeset
188 elif t == 'coord_lon':
55dbaea75e66 more work on types
casties
parents: 34
diff changeset
189 lonField = f['name']
55dbaea75e66 more work on types
casties
parents: 34
diff changeset
190
34
c237699c4752 wokring on meta types
casties
parents: 33
diff changeset
191 res = self.executeSQL("select * from metadata where tablename=%s", table)
c237699c4752 wokring on meta types
casties
parents: 33
diff changeset
192 #if len(res["rows"]) > 0:
31
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
193 # TODO: what now?
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
194
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
195 def publishTraverse(self,request,name):
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
196 """change the traversal"""
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
197 # get stored path
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
198 path = request.get('restdb_path', [])
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
199 logging.debug("publishtraverse: name=%s restdb_path=%s"%(name,path))
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
200
13
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
201 if name in ("index_html", "PUT"):
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
202 # end of traversal
13
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
203 if request.get("method") == "POST" and request.get("action",None) == "PUT":
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
204 # fake PUT by POST with action=PUT
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
205 name = "PUT"
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
206
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
207 return getattr(self, name)
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
208 #TODO: should we check more?
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
209 else:
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
210 # traverse
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
211 if len(path) == 0:
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
212 # first segment
8
a9a49f5765c9 reworking templates and schema
casties
parents: 7
diff changeset
213 if name == 'db':
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
214 # virtual path -- continue traversing
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
215 path = [name]
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
216 request['restdb_path'] = path
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
217 else:
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
218 # try real path
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
219 tr = DefaultPublishTraverse(self, request)
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
220 ob = tr.publishTraverse(request, name)
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
221 return ob
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
222 else:
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
223 path.append(name)
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
224
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
225 # continue traversing
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
226 return self
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
227
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
228 def index_html(self,REQUEST,RESPONSE):
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
229 """index method"""
8
a9a49f5765c9 reworking templates and schema
casties
parents: 7
diff changeset
230 # ReST path was stored in request
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
231 path = REQUEST.get('restdb_path',[])
36
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
232
8
a9a49f5765c9 reworking templates and schema
casties
parents: 7
diff changeset
233 # type and format are real parameter
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
234 resultFormat = REQUEST.get('format','HTML').upper()
27
a2e4ca3f1cff NEW - # 12: create table and upload data
casties
parents: 26
diff changeset
235 queryType = REQUEST.get('type',None)
36
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
236
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
237 logging.debug("index_html path=%s resultFormat=%s queryType=%s"%(path,resultFormat,queryType))
8
a9a49f5765c9 reworking templates and schema
casties
parents: 7
diff changeset
238
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
239 if queryType is not None:
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
240 # non-empty queryType -- look for template
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
241 pt = getattr(self.template, "%s_%s"%(resultFormat,queryType), None)
8
a9a49f5765c9 reworking templates and schema
casties
parents: 7
diff changeset
242 if pt is not None:
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
243 return pt(format=resultFormat,type=queryType,path=path)
8
a9a49f5765c9 reworking templates and schema
casties
parents: 7
diff changeset
244
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
245 if len(path) == 1:
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
246 # list of schemas
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
247 return self.showListOfSchemas(resultFormat=resultFormat)
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
248 elif len(path) == 2:
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
249 # list of tables
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
250 return self.showListOfTables(resultFormat=resultFormat,schema=path[1])
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
251 elif len(path) == 3:
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
252 # table
25
cef1bfa821cb fixed problem with not passing request
casties
parents: 24
diff changeset
253 if REQUEST.get("method") == "POST" and REQUEST.get("create_table_file",None) is not None:
24
f3811d9a36da start adding checkuploadtable
casties
parents: 23
diff changeset
254 # POST to table to check
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
255 return self.checkTable(resultFormat=resultFormat,schema=path[1],table=path[2])
24
f3811d9a36da start adding checkuploadtable
casties
parents: 23
diff changeset
256 # else show table
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
257 return self.showTable(resultFormat=resultFormat,schema=path[1],table=path[2])
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
258
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
259 # don't know what to do
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
260 return str(REQUEST)
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
261
12
0fa22c291ff1 NEW - # 12: create table and upload data
casties
parents: 9
diff changeset
262 def PUT(self, REQUEST, RESPONSE):
0fa22c291ff1 NEW - # 12: create table and upload data
casties
parents: 9
diff changeset
263 """
0fa22c291ff1 NEW - # 12: create table and upload data
casties
parents: 9
diff changeset
264 Implement WebDAV/HTTP PUT/FTP put method for this object.
0fa22c291ff1 NEW - # 12: create table and upload data
casties
parents: 9
diff changeset
265 """
13
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
266 logging.debug("RestDbInterface PUT")
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
267 #logging.debug("req=%s"%REQUEST)
12
0fa22c291ff1 NEW - # 12: create table and upload data
casties
parents: 9
diff changeset
268 #self.dav__init(REQUEST, RESPONSE)
0fa22c291ff1 NEW - # 12: create table and upload data
casties
parents: 9
diff changeset
269 #self.dav__simpleifhandler(REQUEST, RESPONSE)
13
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
270 # ReST path was stored in request
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
271 path = REQUEST.get('restdb_path',[])
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
272 if len(path) == 3:
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
273 schema = path[1]
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
274 tablename = path[2]
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
275 file = REQUEST.get("create_table_file",None)
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
276 if file is None:
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
277 RESPONSE.setStatus(400)
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
278 return
4
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
279
30
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
280 fields = None
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
281 fieldsStr = REQUEST.get("create_table_fields",None)
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
282 logging.debug("put with schema=%s table=%s file=%s fields=%s"%(schema,tablename,file,repr(fieldsStr)))
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
283 if fieldsStr is not None:
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
284 # unpack fields
51db9e78bf98 working on field types
casties
parents: 29
diff changeset
285 fields = [{"name":n, "type": t} for (n,t) in [f.split(":") for f in fieldsStr.split(",")]]
31
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
286
28
9e4f9cfd1edc start adding field structure to xml upload
casties
parents: 27
diff changeset
287 ret = self.createTableFromXML(schema, tablename, file, fields)
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
288 # return the result as JSON
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
289 format = REQUEST.get("format","JSON")
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
290 if format == "JSON":
20
67ca17753cd5 NEW - # 12: create table and upload data
casties
parents: 18
diff changeset
291 RESPONSE.setHeader("Content-Type", "application/json")
67ca17753cd5 NEW - # 12: create table and upload data
casties
parents: 18
diff changeset
292 json.dump(ret, RESPONSE)
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
293
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
294 elif format == "JSONHTML":
20
67ca17753cd5 NEW - # 12: create table and upload data
casties
parents: 18
diff changeset
295 RESPONSE.setHeader("Content-Type", "text/html")
67ca17753cd5 NEW - # 12: create table and upload data
casties
parents: 18
diff changeset
296 RESPONSE.write("<html>\n<body>\n<pre>")
67ca17753cd5 NEW - # 12: create table and upload data
casties
parents: 18
diff changeset
297 json.dump(ret, RESPONSE)
67ca17753cd5 NEW - # 12: create table and upload data
casties
parents: 18
diff changeset
298 RESPONSE.write("</pre>\n</body>\n</html>")
13
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
299
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
300 else:
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
301 # 400 Bad Request
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
302 RESPONSE.setStatus(400)
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
303 return
12
0fa22c291ff1 NEW - # 12: create table and upload data
casties
parents: 9
diff changeset
304
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
305 def showTable(self,resultFormat='XML',schema='public',table=None,REQUEST=None,RESPONSE=None):
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
306 """returns PageTemplate with tables"""
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
307 logging.debug("showtable")
23
860ec92f99df added cross-site access header (for GET)
casties
parents: 22
diff changeset
308 # should be cross-site accessible
25
cef1bfa821cb fixed problem with not passing request
casties
parents: 24
diff changeset
309 if RESPONSE is None:
cef1bfa821cb fixed problem with not passing request
casties
parents: 24
diff changeset
310 RESPONSE = self.REQUEST.RESPONSE
23
860ec92f99df added cross-site access header (for GET)
casties
parents: 22
diff changeset
311 RESPONSE.setHeader('Access-Control-Allow-Origin', '*')
22
1a4b56716902 NEW - # 12: create table and upload data
casties
parents: 21
diff changeset
312 # GIS gets special treatment
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
313 if resultFormat=="GIS":
23
860ec92f99df added cross-site access header (for GET)
casties
parents: 22
diff changeset
314 id = REQUEST.get('id',[])
860ec92f99df added cross-site access header (for GET)
casties
parents: 22
diff changeset
315 doc = REQUEST.get('doc',None)
22
1a4b56716902 NEW - # 12: create table and upload data
casties
parents: 21
diff changeset
316 return self.showGoogleMap(schema=path[1],table=path[2],id=id,doc=doc)
1a4b56716902 NEW - # 12: create table and upload data
casties
parents: 21
diff changeset
317
1a4b56716902 NEW - # 12: create table and upload data
casties
parents: 21
diff changeset
318 # everything else has its own template
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
319 pt = getattr(self.template, '%s_schema_table'%resultFormat, None)
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
320 if pt is None:
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
321 return "ERROR!! template %s_schema_table not found"%resultFormat
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
322
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
323 data = self.getTable(schema,table)
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
324 return pt(data=data,tablename=table)
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
325
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
326 def getTable(self,schema='public',table=None,username='guest'):
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
327 """return table data"""
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
328 logging.debug("gettable")
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
329 data = self.executeSQL('select * from "%s"."%s"'%(schema,table))
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
330 return data
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
331
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
332 def hasTable(self,schema='public',table=None,username='guest'):
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
333 """return if table exists"""
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
334 logging.debug("hastable")
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
335 data = self.executeSQL('select 1 from information_schema.tables where table_schema=%s and table_name=%s',(schema,table))
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
336 ret = bool(data['rows'])
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
337 return ret
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
338
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
339 def showListOfTables(self,resultFormat='XML',schema='public',REQUEST=None,RESPONSE=None):
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
340 """returns PageTemplate with list of tables"""
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
341 logging.debug("showlistoftables")
23
860ec92f99df added cross-site access header (for GET)
casties
parents: 22
diff changeset
342 # should be cross-site accessible
25
cef1bfa821cb fixed problem with not passing request
casties
parents: 24
diff changeset
343 if RESPONSE is None:
cef1bfa821cb fixed problem with not passing request
casties
parents: 24
diff changeset
344 RESPONSE = self.REQUEST.RESPONSE
23
860ec92f99df added cross-site access header (for GET)
casties
parents: 22
diff changeset
345 RESPONSE.setHeader('Access-Control-Allow-Origin', '*')
24
f3811d9a36da start adding checkuploadtable
casties
parents: 23
diff changeset
346
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
347 pt = getattr(self.template, '%s_schema'%resultFormat, None)
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
348 if pt is None:
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
349 return "ERROR!! template %s_schema not found"%resultFormat
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
350
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
351 data = self.getListOfTables(schema)
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
352 return pt(data=data,schema=schema)
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
353
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
354 def getListOfTables(self,schema='public',username='guest'):
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
355 """return list of tables"""
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
356 logging.debug("getlistoftables")
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
357 # get list of fields and types of db table
22
1a4b56716902 NEW - # 12: create table and upload data
casties
parents: 21
diff changeset
358 qstr="""SELECT c.relname AS tablename FROM pg_catalog.pg_class c
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
359 LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
360 WHERE c.relkind IN ('r','') AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
361 AND pg_catalog.pg_table_is_visible(c.oid)"""
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
362 #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"
4
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
363 data=self.executeSQL(qstr)
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
364 return data
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
365
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
366 def showListOfSchemas(self,resultFormat='XML',REQUEST=None,RESPONSE=None):
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
367 """returns PageTemplate with list of schemas"""
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
368 logging.debug("showlistofschemas")
23
860ec92f99df added cross-site access header (for GET)
casties
parents: 22
diff changeset
369 # should be cross-site accessible
25
cef1bfa821cb fixed problem with not passing request
casties
parents: 24
diff changeset
370 if RESPONSE is None:
cef1bfa821cb fixed problem with not passing request
casties
parents: 24
diff changeset
371 RESPONSE = self.REQUEST.RESPONSE
23
860ec92f99df added cross-site access header (for GET)
casties
parents: 22
diff changeset
372 RESPONSE.setHeader('Access-Control-Allow-Origin', '*')
24
f3811d9a36da start adding checkuploadtable
casties
parents: 23
diff changeset
373
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
374 pt = getattr(self.template, '%s_index'%resultFormat, None)
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
375 if pt is None:
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
376 return "ERROR!! template %s_index not found"%resultFormat
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
377
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
378 data = self.getListOfSchemas()
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
379 return pt(data=data)
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
380
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
381 def getListOfSchemas(self,username='guest'):
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
382 """return list of schemas"""
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
383 logging.debug("getlistofschemas")
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
384 # TODO: really look up schemas
9
76ac7a721273 more rework of templates
casties
parents: 8
diff changeset
385 data={'fields': (('schemas',),), 'rows': [('public',),]}
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
386 return data
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
387
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
388 def checkTable(self,resultFormat,schema,table,REQUEST=None,RESPONSE=None):
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
389 """check the table.
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
390 returns valid data fields and table name."""
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
391 if REQUEST is None:
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
392 REQUEST = self.REQUEST
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
393 RESPONSE = REQUEST.RESPONSE
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
394
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
395 file = REQUEST.get("create_table_file",None)
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
396 res = self.checkTableFromXML(schema, table, file)
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
397 logging.debug("checkTable result=%s"%repr(res))
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
398 # return the result as JSON
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
399 if resultFormat == "JSON":
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
400 RESPONSE.setHeader("Content-Type", "application/json")
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
401 json.dump(res, RESPONSE)
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
402
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
403 elif resultFormat == "JSONHTML":
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
404 RESPONSE.setHeader("Content-Type", "text/html")
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
405 RESPONSE.write("<html>\n<body>\n<pre>")
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
406 json.dump(res, RESPONSE)
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
407 RESPONSE.write("</pre>\n</body>\n</html>")
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
408
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
409 else:
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
410 return "ERROR: invalid resultFormat"
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
411
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
412 def checkTableFromXML(self,schema,table,data,REQUEST=None,RESPONSE=None):
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
413 """check the table with the given XML data.
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
414 returns valid data fields and table name."""
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
415 logging.debug("checkTableFromXML schema=%s table=%s"%(schema,table))
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
416 # clean table name
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
417 tablename = sqlName(table)
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
418 tableExists = self.hasTable(schema, table)
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
419 if data is None:
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
420 fieldNames = []
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
421 else:
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
422 # get list of field names from upload file
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
423 fields = self.importExcelXML(schema,tablename,data,fieldsOnly=True)
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
424
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
425 res = {'tablename': tablename, 'table_exists': tableExists}
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
426 res['fields'] = fields
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
427 return res
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
428
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
429 def createEmptyTable(self,schema,table,fields):
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
430 """create a table with the given fields
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
431 returns list of created fields"""
15
5e3edf980813 more work on xml import
casties
parents: 14
diff changeset
432 logging.debug("createEmptyTable")
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
433 sqlFields = []
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
434 for f in fields:
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
435 if isinstance(f,dict):
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
436 # {name: XX, type: YY}
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
437 name = sqlName(f['name'])
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
438 type = f['type']
31
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
439 sqltype = gisToSqlTypeMap[type]
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
440
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
441 else:
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
442 # name only
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
443 name = sqlName(f)
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
444 type = 'text'
31
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
445 sqltype = 'text'
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
446
31
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
447 sqlFields.append({'name':name, 'type':type, 'sqltype':sqltype})
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
448
33
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
449 if self.checkTableMetaPermission("create", schema, table):
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
450 self.executeSQL('drop table if exists "%s"."%s"'%(schema,table),hasResult=False)
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
451 fieldString = ", ".join(['"%s" %s'%(f['name'],f['sqltype']) for f in sqlFields])
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
452 sqlString = 'create table "%s"."%s" (%s)'%(schema,table,fieldString)
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
453 logging.debug("createemptytable: SQL=%s"%sqlString)
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
454 self.executeSQL(sqlString,hasResult=False)
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
455 self.setTableMetaTypes(schema,table,sqlFields)
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
456 return sqlFields
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
457 else:
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
458 logging.warning("create table not allowed!")
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
459 # throw exception?
355b1fa2d78f added meta permissions check
casties
parents: 32
diff changeset
460 return None
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
461
28
9e4f9cfd1edc start adding field structure to xml upload
casties
parents: 27
diff changeset
462 def createTableFromXML(self,schema,table,data, fields=None):
13
e2c73c077533 NEW - # 12: create table and upload data
casties
parents: 12
diff changeset
463 """create or replace a table with the given XML data"""
28
9e4f9cfd1edc start adding field structure to xml upload
casties
parents: 27
diff changeset
464 logging.debug("createTableFromXML schema=%s table=%s data=%s fields=%s"%(schema,table,data,fields))
17
ed997e639cfd more upload table
casties
parents: 16
diff changeset
465 tablename = sqlName(table)
28
9e4f9cfd1edc start adding field structure to xml upload
casties
parents: 27
diff changeset
466 self.importExcelXML(schema, tablename, data, fields)
17
ed997e639cfd more upload table
casties
parents: 16
diff changeset
467 return {"tablename": tablename}
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
468
28
9e4f9cfd1edc start adding field structure to xml upload
casties
parents: 27
diff changeset
469 def importExcelXML(self,schema,table,xmldata,fields=None,fieldsOnly=False):
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
470 '''
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
471 Import XML file in Excel format into the table
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
472 @param table: name of the table the xml shall be imported into
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
473 '''
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
474 from xml.dom.pulldom import parseString,parse
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
475
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
476 namespace = "urn:schemas-microsoft-com:office:spreadsheet"
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
477 containerTagName = "Table"
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
478 rowTagName = "Row"
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
479 colTagName = "Cell"
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
480 dataTagName = "Data"
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
481 xmlFields = []
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
482 sqlFields = []
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
483 numFields = 0
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
484 sqlInsert = None
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
485
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
486 logging.debug("import excel xml")
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
487
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
488 ret=""
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
489 if isinstance(xmldata, str):
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
490 logging.debug("importXML reading string data")
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
491 doc=parseString(xmldata)
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
492 else:
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
493 logging.debug("importXML reading file data")
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
494 doc=parse(xmldata)
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
495
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
496 cnt = 0
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
497 while True:
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
498 node=doc.getEvent()
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
499
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
500 if node is None:
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
501 break
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
502
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
503 else:
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
504 #logging.debug("tag=%s"%node[1].localName)
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
505 if node[1].localName is not None:
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
506 tagName = node[1].localName.lower()
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
507 else:
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
508 # ignore non-tag nodes
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
509 continue
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
510
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
511 if tagName == rowTagName.lower():
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
512 # start of row
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
513 doc.expandNode(node[1])
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
514 cnt += 1
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
515 if cnt == 1:
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
516 # first row -- field names
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
517 names=node[1].getElementsByTagNameNS(namespace, dataTagName)
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
518 for name in names:
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
519 fn = getTextFromNode(name)
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
520 xmlFields.append({'name':sqlName(fn),'type':'text'})
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
521
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
522 if fieldsOnly:
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
523 # return just field names
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
524 return xmlFields
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
525
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
526 # create table
28
9e4f9cfd1edc start adding field structure to xml upload
casties
parents: 27
diff changeset
527 if fields is None:
31
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
528 fields = xmlFields
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
529
6d2055f1b4fa more work on types
casties
parents: 30
diff changeset
530 sqlFields = self.createEmptyTable(schema, table, fields)
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
531 numFields = len(sqlFields)
15
5e3edf980813 more work on xml import
casties
parents: 14
diff changeset
532 fieldString = ", ".join(['"%s"'%f['name'] for f in sqlFields])
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
533 valString = ", ".join(["%s" for f in sqlFields])
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
534 sqlInsert = 'insert into "%s"."%s" (%s) values (%s)'%(schema,table,fieldString,valString)
26
2b73f868d34f NEW - # 12: create table and upload data
casties
parents: 25
diff changeset
535 #logging.debug("importexcelsql: sqlInsert=%s"%sqlInsert)
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
536
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
537 else:
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
538 # following rows are data
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
539 colNodes=node[1].getElementsByTagNameNS(namespace, colTagName)
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
540 data = []
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
541 hasData = False
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
542 for colNode in colNodes:
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
543 dataNodes=colNode.getElementsByTagNameNS(namespace, dataTagName)
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
544 if len(dataNodes) > 0:
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
545 val = getTextFromNode(dataNodes[0])
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
546 hasData = True
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
547 else:
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
548 val = None
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
549
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
550 data.append(val)
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
551
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
552 if not hasData:
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
553 # ignore empty rows
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
554 continue
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
555
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
556 # fix number of data fields
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
557 if len(data) > numFields:
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
558 del data[numFields:]
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
559 elif len(data) < numFields:
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
560 missFields = numFields - len(data)
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
561 data.extend(missFields * [None,])
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
562
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
563 logging.debug("importexcel sqlinsert=%s data=%s"%(sqlInsert,data))
17
ed997e639cfd more upload table
casties
parents: 16
diff changeset
564 self.executeSQL(sqlInsert, data, hasResult=False)
14
05933707897f NEW - # 12: create table and upload data
casties
parents: 13
diff changeset
565
16
cbb73d103152 NEW - # 12: create table and upload data
casties
parents: 15
diff changeset
566 return cnt
21
a67b7c1f7ec5 Merge with Falks GIS stuff 78e70dfa7ad6b27d10d490f9ae8820306e4fe5d4
casties
parents: 20 19
diff changeset
567
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
568
36
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
569 # Methods for GoogleMaps creation
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
570 def showGoogleMap(self,schema='chgis',table='mpdl',id=[],doc=None):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
571 logging.debug("showGoogleMap")
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
572 data = self.getDataForGoogleMap(schema,table,id,doc)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
573 kmlFileName=self.getKMLname(data=data,table=table)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
574 initializeStringForGoogleMaps="""onload=\"initialize(\'http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/daten/"""+kmlFileName+"""\')\""""#+str(data)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
575 initializeStringForGoogleMaps=initializeStringForGoogleMaps.replace("None","0")
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
576 googleMap_page=self.htmlHead()+str(self.getGoogleMapString(kml=initializeStringForGoogleMaps))
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
577 return googleMap_page
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
578
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
579 def getKmlUrl(self,schema='chgis',table='mpdl',id=[],doc=None):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
580 logging.debug("getKmlUrl")
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
581 data = self.getDataForGoogleMap(schema,table,id,doc)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
582 kml=self.getKMLname(data=data,table=table)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
583 return """http://chinagis.mpiwg-berlin.mpg.de/chinagis/REST/daten/"""+kml
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
584
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
585 def getDataForGoogleMap(self,schema='chgis',table='mpdl',id=[],doc=None):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
586 logging.debug("getDataForGoogleMap")
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
587 qstr="SELECT * FROM "+schema+"."+table
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
588 try:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
589 if id!=[]:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
590 qstr=qstr+" WHERE "
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
591 for id_item in id.split(","):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
592 if table=='mpdl':
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
593 qstr=qstr+" mpdl_xmlsource_id = '"+id_item+ "' OR"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
594 else:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
595 qstr=qstr+" cast(id as text) LIKE '"+id_item+ "' OR"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
596 qstr=str(qstr).rsplit(" ",1)[0] #to remove last " and "
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
597 data=self.ZSQLSimpleSearch(qstr)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
598 return data
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
599 except:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
600 return qstr
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
601
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
602 def getKMLname(self,data=[],table=""):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
603 logging.debug("getKMLname")
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
604 #session=context.REQUEST.SESSION
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
605 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"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
606 initializeStringForGoogleMaps=""
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
607 #doLine=container.getVar('doLine')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
608 # Mapping a set of points from table-based SQL-query:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
609 if data!=None:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
610 try:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
611 SQL="""SELECT \"attribute with gis_id\" FROM public.metadata WHERE tablename LIKE '"""+table+"""'"""
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
612 gisIDattribute=self.ZSQLSimpleSearch(SQL)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
613 except:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
614 return "table not registered within metadata"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
615 for dataset in data:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
616 try:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
617 xCoord=getattr(dataset,'longitude')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
618 yCoord=getattr(dataset,'latitude')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
619 except:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
620 try:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
621 xCoord=getattr(dataset,'x_coord')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
622 yCoord=getattr(dataset,'y_coord')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
623 except:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
624 # try:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
625 gisID=getattr(dataset,getattr(gisIDattribute[0],'attribute with gis_id'))
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
626 coords=self.getPoint4GISid(gisID)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
627 if coords!=None:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
628 xCoord=coords[0]
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
629 yCoord=coords[1]
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
630 # except:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
631 # return "no coordinates found"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
632 if float(xCoord)!=0:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
633 if float(yCoord)!=0:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
634 kml4Marker=kml4Marker+"<Placemark>"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
635 kml4Marker=kml4Marker+"<description> <![CDATA[<b>"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
636 for values in dataset:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
637 if values != (None, None):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
638 if str(values).find('name')>-1:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
639 kml4Marker=kml4Marker+"<name>"+str(values[1])+"</name>\n"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
640 continue
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
641 elif str(values).find('place')>-1:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
642 kml4Marker=kml4Marker+"<name>"+str(values[1])+"</name>\n"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
643 continue
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
644
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
645 kml4Marker=kml4Marker+str(values)+": "
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
646 attribute_string=str(values).replace("'","__Apostroph__")
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
647 attribute_string=str(attribute_string).replace('"','__DoubleApostroph__')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
648 attribute_string=str(attribute_string).replace(';','__$$__')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
649 attribute_string=str(attribute_string).replace('&','&amp;')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
650 if str(attribute_string).find('http')>-1:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
651 attribute_string='<A HREF=' + str(attribute_string) + ' target=_blank>' + str(attribute_string) + '</A>'
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
652 kml4Marker=kml4Marker+attribute_string+"</a><br>\n"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
653
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
654 kml4Marker=kml4Marker+"]]></description>\n"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
655 kml4Marker=kml4Marker+"<styleURL>#marker_icon</styleURL>\n"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
656 kml4Marker=kml4Marker+"<Point>"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
657
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
658 kml4Marker=kml4Marker+"<coordinates>"+str(xCoord)+","+str(yCoord)+",0</coordinates>\n"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
659 kml4Marker=kml4Marker+"</Point>\n"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
660 kml4Marker=kml4Marker+"</Placemark>\n"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
661
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
662 kml4Marker=kml4Marker+"</Document>\n</kml>"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
663 kmlFileName="marker"+str(time.time())+".kml"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
664
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
665 # kml4Marker=str(kml4Marker).replace('&','$$')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
666 # kml4Marker=str(kml4Marker).replace(';','__$$__')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
667 # kml4Marker=str(kml4Marker).replace('#','__SHARP__')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
668 isLoadReady='false'
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
669 while isLoadReady=='false':
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
670 isLoadReady=self.RESTwrite2File(self.daten,kmlFileName,kml4Marker)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
671
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
672 return kmlFileName
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
673
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
674 def getGoogleMapString(self,kml):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
675 logging.debug("getGoogleMapString")
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
676 printed= '<body %s> '%kml +"""\n <div id="map_canvas" style="width: 98%; height: 95%"> </div> \n </body>" \n </html>"""
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
677 return printed
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
678
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
679 def getPoint4GISid(self,gis_id):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
680 j=0
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
681 coords=(0,0)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
682 if gis_id != None:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
683 while (True):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
684 j=j+1
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
685 if (j>100): # FJK: just to prevent endless loops
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
686 break
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
687 if (gis_id.isdigit()): # FJK: regular exit from while-loop
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
688 break
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
689 else:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
690 gis_id=gis_id.strip('abcdefghijklmnopqrstuvwxyz_') # FJK: to strip all letters
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
691 gis_id=gis_id.strip() # FJK: to strip all whitespaces
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
692 resultpoint = [0,0]
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
693 results = None
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
694 try:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
695 if int(gis_id)>0:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
696 SQL="SELECT x_coord,y_coord FROM chgis.chgis_coords WHERE gis_id LIKE cast("+ str(gis_id) +" as text);"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
697 results=self.ZSQLSimpleSearch(SQL)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
698 #print results
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
699 if results != None:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
700 for result in results:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
701 resultpoint=[getattr(result,str('x_coord')),getattr(result,str('y_coord'))]
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
702 if resultpoint !=[0,0]:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
703 return resultpoint
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
704 else:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
705 coords=self.getCoordsFromREST_gisID(joinid)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
706 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;"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
707 returnstring=self.ZSQLSimpleSearch(SQL)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
708 return coords[0]
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
709 except:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
710 return "gis_id not to interpretable:"+str(gis_id)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
711 else:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
712 return coords[0]
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
713
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
714 def getCoordsFromREST_gisID(self,gis_id):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
715 coordlist=[]
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
716 i=0
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
717 while (i<5 and coordlist==[]):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
718
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
719 urlresponse=container.urlFunctions.zUrlopenParseString(container.urlFunctions.zUrlopenRead("http://chgis.hmdc.harvard.edu/xml/id/"+gis_id))
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
720 baseDocElement=container.urlFunctions.zUrlopenDocumentElement(urlresponse)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
721 childnodes=container.urlFunctions.zUrlopenChildNodes(baseDocElement)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
722 itemnodes=container.urlFunctions.zUrlopenGetElementsByTagName(baseDocElement,'item')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
723
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
724 for i in range(0,container.urlFunctions.zUrlopenLength(itemnodes)):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
725 itemnode=container.urlFunctions.zUrlopenGetItem(itemnodes,i)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
726 itemspatialnodes=container.urlFunctions.zUrlopenGetElementsByTagName(itemnode,'spatial')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
727 for j in range(0,container.urlFunctions.zUrlopenLength(itemspatialnodes)):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
728 coord=[]
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
729 itemspatialnode= container.urlFunctions.zUrlopenGetItem(itemspatialnodes,j)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
730 itemspatiallatnodes=container.urlFunctions.zUrlopenGetElementsByTagName(itemspatialnode,'degrees_latitude')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
731 for k in range(0,container.urlFunctions.zUrlopenLength(itemspatiallatnodes)):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
732 itemspatiallatnode= container.urlFunctions.zUrlopenGetItem(itemspatiallatnodes,k)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
733 coord.append(container.urlFunctions.zUrlopenGetTextData(itemspatiallatnode))
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
734 itemspatiallngnodes=container.urlFunctions.zUrlopenGetElementsByTagName(itemspatialnode,'degrees_longitude')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
735 for k in range(0,container.urlFunctions.zUrlopenLength(itemspatiallngnodes)):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
736 itemspatiallngnode= container.urlFunctions.zUrlopenGetItem(itemspatiallngnodes,k)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
737 coord.append(container.urlFunctions.zUrlopenGetTextData(itemspatiallngnode))
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
738 coordlist.append(coord)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
739 gis_id= "_"+gis_id
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
740 return coordlist
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
741
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
742 # End for GoogleMaps creation
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
743
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
744 def RESTwrite2File(self,datadir, name,text):
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
745 # try:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
746 fileid=name
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
747 if fileid in datadir.objectIds():
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
748 datadir.manage_delObjects(fileid)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
749 newfile=open(name,'w')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
750 newfile.write(text)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
751 newfile.close()
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
752 file4Read=open(name,'r')
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
753 fileInZope=datadir.manage_addFile(id=fileid,file=file4Read)
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
754 return "Write successful"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
755 # except:
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
756 # return "Could not write"
b915bce65372 added kml url option
fknauft
parents: 9
diff changeset
757
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
758
4
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
759 def manage_editRestDbInterface(self, title=None, connection_id=None,
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
760 REQUEST=None):
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
761 """Change the object"""
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
762 if title is not None:
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
763 self.title = title
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
764
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
765 if connection_id is not None:
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
766 self.connection_id = connection_id
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
767
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
768 #checkPermission=getSecurityManager().checkPermission
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
769 REQUEST.RESPONSE.redirect('manage_main')
e3ee1f358fe6 new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents: 2
diff changeset
770
2
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
771
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
772 manage_addRestDbInterfaceForm=PageTemplateFile('zpt/addRestDbInterface',globals())
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
773
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
774 def manage_addRestDbInterface(self, id, title='', label='', description='',
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
775 createPublic=0,
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
776 createUserF=0,
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
777 REQUEST=None):
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
778 """Add a new object with id *id*."""
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
779
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
780 ob=RestDbInterface(str(id),title)
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
781 self._setObject(id, ob)
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
782
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
783 #checkPermission=getSecurityManager().checkPermission
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
784 REQUEST.RESPONSE.redirect('manage_main')
61a3764cd5fb new version RestDbInterface with working traversal and templates
casties
parents:
diff changeset
785
5
7539a9e69365 small fix
casties
parents: 4
diff changeset
786