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