Mercurial > hg > ChinaGisRestApi
annotate RestDbInterface.py @ 252:efd2469d1722
geometry-column of tables will be displayed as string
author | fknauft |
---|---|
date | Tue, 20 Sep 2011 11:19:35 +0200 |
parents | 9e34cd7b2e57 |
children | 901c1f745d13 |
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 |
60 | 9 from AccessControl import getSecurityManager, Unauthorized |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
10 from Products.ZSQLExtend import ZSQLExtend |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
11 import logging |
15 | 12 import re |
18 | 13 import json |
19 | 14 import time |
70 | 15 import psycopg2 |
16 # make psycopg use unicode objects | |
17 import psycopg2.extensions | |
18 psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) | |
19 psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY) | |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
20 |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
21 from zope.interface import implements |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
22 from zope.publisher.interfaces import IPublishTraverse |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
23 from ZPublisher.BaseRequest import DefaultPublishTraverse |
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 |
70 | 26 def unicodify(s,alternate='latin-1'): |
27 """decode str (utf-8 or latin-1 representation) into unicode object""" | |
28 if not s: | |
29 return u"" | |
30 if isinstance(s, str): | |
31 try: | |
32 return s.decode('utf-8') | |
33 except: | |
34 return s.decode(alternate) | |
35 else: | |
36 return s | |
37 | |
38 def utf8ify(s): | |
39 """encode unicode object or string into byte string in utf-8 representation. | |
40 assumes string objects to be utf-8""" | |
41 if not s: | |
42 return "" | |
43 if isinstance(s, str): | |
44 return s | |
45 else: | |
46 return s.encode('utf-8') | |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
47 |
16 | 48 def getTextFromNode(node): |
14 | 49 """get the cdata content of a XML node""" |
16 | 50 if node is None: |
14 | 51 return "" |
16 | 52 |
53 if isinstance(node, list): | |
54 nodelist = node | |
55 else: | |
56 nodelist=node.childNodes | |
57 | |
14 | 58 rc = "" |
59 for node in nodelist: | |
60 if node.nodeType == node.TEXT_NODE: | |
61 rc = rc + node.data | |
62 return rc | |
63 | |
16 | 64 def sqlName(s,lc=True): |
65 """returns restricted ASCII-only version of string""" | |
15 | 66 if s is None: |
67 return "" | |
68 | |
69 # all else -> "_" | |
16 | 70 s = re.sub(r'[^A-Za-z0-9_]','_',s) |
15 | 71 if lc: |
72 return s.lower() | |
73 | |
74 return s | |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
75 |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
76 |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
77 class RestDbInterface(Folder): |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
78 """Object for RESTful database queries |
7 | 79 path schema: /db/{schema}/{table}/ |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
80 omitting table gives a list of schemas |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
81 omitting table and schema gives a list of schemas |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
82 """ |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
83 implements(IPublishTraverse) |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
84 |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
85 meta_type="RESTdb" |
4
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
86 manage_options=Folder.manage_options+( |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
87 {'label':'Config','action':'manage_editRestDbInterfaceForm'}, |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
88 ) |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
89 |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
90 # management templates |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
91 manage_editRestDbInterfaceForm=PageTemplateFile('zpt/editRestDbInterface',globals()) |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
92 |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
93 # data templates |
8 | 94 XML_index = PageTemplateFile('zpt/XML_index', globals()) |
95 XML_schema = PageTemplateFile('zpt/XML_schema', globals()) | |
96 XML_schema_table = PageTemplateFile('zpt/XML_schema_table', globals()) | |
97 HTML_index = PageTemplateFile('zpt/HTML_index', globals()) | |
98 HTML_schema = PageTemplateFile('zpt/HTML_schema', globals()) | |
99 HTML_schema_table = PageTemplateFile('zpt/HTML_schema_table', globals()) | |
22 | 100 JSONHTML_index = PageTemplateFile('zpt/JSONHTML_index', globals()) |
101 JSONHTML_schema = PageTemplateFile('zpt/JSONHTML_schema', globals()) | |
102 JSONHTML_schema_table = PageTemplateFile('zpt/JSONHTML_schema_table', globals()) | |
24 | 103 # JSON_* templates are scripts |
45 | 104 def JSON_index(self): |
30 | 105 """JSON index function""" |
106 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") | |
45 | 107 json.dump(self.getListOfSchemas(), self.REQUEST.RESPONSE) |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
108 |
45 | 109 def JSON_schema(self,schema): |
30 | 110 """JSON index function""" |
111 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") | |
45 | 112 json.dump(self.getListOfTables(schema), self.REQUEST.RESPONSE) |
30 | 113 |
44 | 114 def JSON_schema_table(self,schema,table): |
30 | 115 """JSON index function""" |
116 self.REQUEST.RESPONSE.setHeader("Content-Type", "application/json") | |
44 | 117 json.dump(self.getTable(schema, table), self.REQUEST.RESPONSE) |
30 | 118 |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
119 |
4
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
120 def __init__(self, id, title, connection_id=None): |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
121 """init""" |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
122 self.id = id |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
123 self.title = title |
4
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
124 # database connection id |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
125 self.connection_id = connection_id |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
126 # create template folder |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
127 self.manage_addFolder('template') |
44 | 128 |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
129 |
44 | 130 def getRestDbUrl(self): |
131 """returns url to the RestDb instance""" | |
132 return self.absolute_url() | |
133 | |
22 | 134 def getJsonString(self,object): |
135 """returns a JSON formatted string from object""" | |
136 return json.dumps(object) | |
4
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
137 |
17 | 138 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
|
139 """returns fresh DB cursor""" |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
140 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
|
141 if conn is None: |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
142 # create a new connection object |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
143 try: |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
144 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
|
145 # 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
|
146 connids = SQLConnectionIDs(self) |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
147 if len(connids) > 0: |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
148 connection_id = connids[0][0] |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
149 self.connection_id = connection_id |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
150 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
|
151 |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
152 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
|
153 da.connect('') |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
154 # 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
|
155 conn = da._v_database_connection |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
156 #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
|
157 self._v_database_connection = conn |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
158 except Exception, e: |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
159 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
|
160 |
5 | 161 cursor = conn.getcursor() |
17 | 162 if autocommit: |
163 # is there a better version to get to the connection? | |
164 cursor.connection.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT) | |
165 | |
4
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
166 return cursor |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
167 |
55 | 168 def getFieldNameMap(self,fields): |
169 """returns a dict mapping field names to row indexes""" | |
170 map = {} | |
171 i = 0 | |
172 for f in fields: | |
173 map[f[0]] = i | |
174 i += 1 | |
175 | |
176 return map | |
177 | |
17 | 178 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
|
179 """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
|
180 result format: {"fields":fields, "rows":data}""" |
16 | 181 logging.debug("executeSQL query=%s args=%s"%(query,args)) |
17 | 182 cur = self.getCursor(autocommit=autocommit) |
53 | 183 if args is not None: |
184 # make sure args is a list | |
185 if isinstance(args,basestring): | |
186 args = (args,) | |
187 | |
4
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
188 cur.execute(query, args) |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
189 # description of returned fields |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
190 fields = cur.description |
17 | 191 if hasResult: |
192 # get all data in an array | |
193 data = cur.fetchall() | |
194 cur.close() | |
55 | 195 #logging.debug("fields: %s"%repr(fields)) |
58 | 196 #logging.debug("rows: %s"%repr(data)) |
17 | 197 return {"fields":fields, "rows":data} |
198 else: | |
199 cur.close() | |
200 return None | |
16 | 201 |
60 | 202 def isAllowed(self,action,schema,table,user=None): |
203 """returns if the requested action on the table is allowed""" | |
204 if user is None: | |
205 user = self.REQUEST.get('AUTHENTICATED_USER',None) | |
206 logging.debug("isAllowed action=%s schema=%s table=%s user=%s"%(action,schema,table,user)) | |
207 # no default policy! | |
208 return True | |
209 | |
210 | |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
211 def publishTraverse(self,request,name): |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
212 """change the traversal""" |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
213 # get stored path |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
214 path = request.get('restdb_path', []) |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
215 logging.debug("publishtraverse: name=%s restdb_path=%s"%(name,path)) |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
216 |
13 | 217 if name in ("index_html", "PUT"): |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
218 # end of traversal |
13 | 219 if request.get("method") == "POST" and request.get("action",None) == "PUT": |
220 # fake PUT by POST with action=PUT | |
221 name = "PUT" | |
222 | |
223 return getattr(self, name) | |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
224 #TODO: should we check more? |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
225 else: |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
226 # traverse |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
227 if len(path) == 0: |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
228 # first segment |
8 | 229 if name == 'db': |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
230 # virtual path -- continue traversing |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
231 path = [name] |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
232 request['restdb_path'] = path |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
233 else: |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
234 # try real path |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
235 tr = DefaultPublishTraverse(self, request) |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
236 ob = tr.publishTraverse(request, name) |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
237 return ob |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
238 else: |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
239 path.append(name) |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
240 |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
241 # continue traversing |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
242 return self |
44 | 243 |
244 | |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
245 def index_html(self,REQUEST,RESPONSE): |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
246 """index method""" |
8 | 247 # ReST path was stored in request |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
248 path = REQUEST.get('restdb_path',[]) |
19 | 249 |
8 | 250 # type and format are real parameter |
26 | 251 resultFormat = REQUEST.get('format','HTML').upper() |
27 | 252 queryType = REQUEST.get('type',None) |
19 | 253 |
26 | 254 logging.debug("index_html path=%s resultFormat=%s queryType=%s"%(path,resultFormat,queryType)) |
8 | 255 |
26 | 256 if queryType is not None: |
257 # non-empty queryType -- look for template | |
258 pt = getattr(self.template, "%s_%s"%(resultFormat,queryType), None) | |
8 | 259 if pt is not None: |
26 | 260 return pt(format=resultFormat,type=queryType,path=path) |
8 | 261 |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
262 if len(path) == 1: |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
263 # list of schemas |
61 | 264 return self.showListOfSchemas(format=resultFormat) |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
265 elif len(path) == 2: |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
266 # list of tables |
61 | 267 return self.showListOfTables(format=resultFormat,schema=path[1]) |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
268 elif len(path) == 3: |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
269 # table |
25 | 270 if REQUEST.get("method") == "POST" and REQUEST.get("create_table_file",None) is not None: |
24 | 271 # POST to table to check |
61 | 272 return self.checkTable(format=resultFormat,schema=path[1],table=path[2]) |
24 | 273 # else show table |
61 | 274 return self.showTable(format=resultFormat,schema=path[1],table=path[2]) |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
275 |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
276 # don't know what to do |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
277 return str(REQUEST) |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
278 |
12 | 279 def PUT(self, REQUEST, RESPONSE): |
280 """ | |
281 Implement WebDAV/HTTP PUT/FTP put method for this object. | |
282 """ | |
13 | 283 logging.debug("RestDbInterface PUT") |
284 #logging.debug("req=%s"%REQUEST) | |
12 | 285 #self.dav__init(REQUEST, RESPONSE) |
286 #self.dav__simpleifhandler(REQUEST, RESPONSE) | |
13 | 287 # ReST path was stored in request |
288 path = REQUEST.get('restdb_path',[]) | |
289 if len(path) == 3: | |
290 schema = path[1] | |
291 tablename = path[2] | |
292 file = REQUEST.get("create_table_file",None) | |
293 if file is None: | |
294 RESPONSE.setStatus(400) | |
295 return | |
4
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
296 |
30 | 297 fields = None |
298 fieldsStr = REQUEST.get("create_table_fields",None) | |
299 logging.debug("put with schema=%s table=%s file=%s fields=%s"%(schema,tablename,file,repr(fieldsStr))) | |
300 if fieldsStr is not None: | |
301 # unpack fields | |
302 fields = [{"name":n, "type": t} for (n,t) in [f.split(":") for f in fieldsStr.split(",")]] | |
31 | 303 |
28 | 304 ret = self.createTableFromXML(schema, tablename, file, fields) |
26 | 305 # return the result as JSON |
306 format = REQUEST.get("format","JSON") | |
307 if format == "JSON": | |
20 | 308 RESPONSE.setHeader("Content-Type", "application/json") |
309 json.dump(ret, RESPONSE) | |
26 | 310 |
311 elif format == "JSONHTML": | |
20 | 312 RESPONSE.setHeader("Content-Type", "text/html") |
313 RESPONSE.write("<html>\n<body>\n<pre>") | |
314 json.dump(ret, RESPONSE) | |
315 RESPONSE.write("</pre>\n</body>\n</html>") | |
13 | 316 |
317 else: | |
318 # 400 Bad Request | |
319 RESPONSE.setStatus(400) | |
320 return | |
252
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
321 def getAttributeNames(self,schema='public',table=None): |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
322 return self.executeSQL("SELECT attname FROM pg_attribute, pg_class WHERE pg_class.oid = attrelid AND attnum>0 AND relname = '%s';"%(table)) |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
323 |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
324 def getAttributeTypes(self,schema='public',table=None): |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
325 return self.executeSQL("SELECT field_name, gis_type FROM public.gis_table_meta_rows WHERE table_name = '%s';"%(table)) |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
326 |
61 | 327 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
|
328 """returns PageTemplate with tables""" |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
329 logging.debug("showtable") |
38 | 330 if REQUEST is None: |
331 REQUEST = self.REQUEST | |
332 | |
23 | 333 # should be cross-site accessible |
25 | 334 if RESPONSE is None: |
335 RESPONSE = self.REQUEST.RESPONSE | |
38 | 336 |
23 | 337 RESPONSE.setHeader('Access-Control-Allow-Origin', '*') |
38 | 338 |
22 | 339 # everything else has its own template |
9 | 340 pt = getattr(self.template, '%s_schema_table'%format, None) |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
341 if pt is None: |
9 | 342 return "ERROR!! template %s_schema_table not found"%format |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
343 |
44 | 344 #data = self.getTable(schema,table) |
345 return pt(schema=schema,table=table) | |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
346 |
58 | 347 def getTable(self,schema='public',table=None,sortBy=1,username='guest'): |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
348 """return table data""" |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
349 logging.debug("gettable") |
252
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
350 attrNames=self.getAttributeNames(schema,table) |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
351 attrTypes=self.getAttributeTypes(schema,table) |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
352 attrString="" |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
353 # try: |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
354 for name in attrNames['rows']: |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
355 logging.debug("name: ", name[0]) |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
356 not_added=True |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
357 if name[0] == "the_geom": #FJK: the table column is "the_geom" |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
358 attrString=attrString+"ST_AsText("+name[0]+")," |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
359 not_added=False |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
360 break |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
361 for a_iter in attrTypes['rows']: |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
362 not_added = True |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
363 logging.debug("attrTypes.field_name: ", a_iter[0]) |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
364 if a_iter[0]==name[0]: |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
365 logging.debug("attrTypes.gis_type: ", a_iter[1]) |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
366 if a_iter[1] == "the_geom": #FJK: the table column is registered in gis_table_meta_rows as type "the_geom" |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
367 attrString=attrString+"ST_AsText("+name[0]+")," |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
368 not_added=False |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
369 if not_added: |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
370 attrString=attrString+name[0]+"," |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
371 attrString=str(attrString).rsplit(",",1)[0] #to remove last "," |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
372 if sortBy: |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
373 data = self.executeSQL('select %s from "%s"."%s" order by %s'%(attrString,schema,table,sortBy)) |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
374 else: |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
375 data = self.executeSQL('select %s from "%s"."%s"'%(attrString,schema,table)) |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
376 # except: |
227 | 377 """ table does not exist """ |
252
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
378 # fields=self.get |
efd2469d1722
geometry-column of tables will be displayed as string
fknauft
parents:
230
diff
changeset
|
379 # self.createEmptyTable(schema, table, fields) |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
380 return data |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
381 |
26 | 382 def hasTable(self,schema='public',table=None,username='guest'): |
383 """return if table exists""" | |
384 logging.debug("hastable") | |
385 data = self.executeSQL('select 1 from information_schema.tables where table_schema=%s and table_name=%s',(schema,table)) | |
386 ret = bool(data['rows']) | |
387 return ret | |
388 | |
61 | 389 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
|
390 """returns PageTemplate with list of tables""" |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
391 logging.debug("showlistoftables") |
23 | 392 # should be cross-site accessible |
25 | 393 if RESPONSE is None: |
394 RESPONSE = self.REQUEST.RESPONSE | |
23 | 395 RESPONSE.setHeader('Access-Control-Allow-Origin', '*') |
24 | 396 |
9 | 397 pt = getattr(self.template, '%s_schema'%format, None) |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
398 if pt is None: |
9 | 399 return "ERROR!! template %s_schema not found"%format |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
400 |
45 | 401 #data = self.getListOfTables(schema) |
402 return pt(schema=schema) | |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
403 |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
404 def getListOfTables(self,schema='public',username='guest'): |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
405 """return list of tables""" |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
406 logging.debug("getlistoftables") |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
407 # get list of fields and types of db table |
61 | 408 #qstr="""SELECT c.relname AS tablename FROM pg_catalog.pg_class c |
409 # LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace | |
410 # WHERE c.relkind IN ('r','') AND n.nspname NOT IN ('pg_catalog', 'pg_toast') | |
411 # AND pg_catalog.pg_table_is_visible(c.oid) | |
412 # AND c.relname ORDER BY 1""" | |
413 qstr = """SELECT table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' | |
414 AND table_schema = %s ORDER BY 1""" | |
415 data=self.executeSQL(qstr,(schema,)) | |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
416 return data |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
417 |
61 | 418 def showListOfSchemas(self,format='XML',REQUEST=None,RESPONSE=None): |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
419 """returns PageTemplate with list of schemas""" |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
420 logging.debug("showlistofschemas") |
23 | 421 # should be cross-site accessible |
25 | 422 if RESPONSE is None: |
423 RESPONSE = self.REQUEST.RESPONSE | |
23 | 424 RESPONSE.setHeader('Access-Control-Allow-Origin', '*') |
24 | 425 |
9 | 426 pt = getattr(self.template, '%s_index'%format, None) |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
427 if pt is None: |
9 | 428 return "ERROR!! template %s_index not found"%format |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
429 |
45 | 430 #data = self.getListOfSchemas() |
431 return pt() | |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
432 |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
433 def getListOfSchemas(self,username='guest'): |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
434 """return list of schemas""" |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
435 logging.debug("getlistofschemas") |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
436 # TODO: really look up schemas |
9 | 437 data={'fields': (('schemas',),), 'rows': [('public',),]} |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
438 return data |
26 | 439 |
61 | 440 def checkTable(self,format,schema,table,REQUEST=None,RESPONSE=None): |
26 | 441 """check the table. |
442 returns valid data fields and table name.""" | |
443 if REQUEST is None: | |
444 REQUEST = self.REQUEST | |
445 RESPONSE = REQUEST.RESPONSE | |
74 | 446 |
26 | 447 file = REQUEST.get("create_table_file",None) |
448 res = self.checkTableFromXML(schema, table, file) | |
449 logging.debug("checkTable result=%s"%repr(res)) | |
450 # return the result as JSON | |
61 | 451 if format == "JSON": |
26 | 452 RESPONSE.setHeader("Content-Type", "application/json") |
453 json.dump(res, RESPONSE) | |
454 | |
61 | 455 elif format == "JSONHTML": |
26 | 456 RESPONSE.setHeader("Content-Type", "text/html") |
457 RESPONSE.write("<html>\n<body>\n<pre>") | |
458 json.dump(res, RESPONSE) | |
459 RESPONSE.write("</pre>\n</body>\n</html>") | |
460 | |
461 else: | |
61 | 462 return "ERROR: invalid format" |
74 | 463 |
26 | 464 def checkTableFromXML(self,schema,table,data,REQUEST=None,RESPONSE=None): |
465 """check the table with the given XML data. | |
466 returns valid data fields and table name.""" | |
467 logging.debug("checkTableFromXML schema=%s table=%s"%(schema,table)) | |
468 # clean table name | |
469 tablename = sqlName(table) | |
470 tableExists = self.hasTable(schema, table) | |
471 if data is None: | |
472 fieldNames = [] | |
473 else: | |
474 # get list of field names from upload file | |
475 fields = self.importExcelXML(schema,tablename,data,fieldsOnly=True) | |
14 | 476 |
26 | 477 res = {'tablename': tablename, 'table_exists': tableExists} |
478 res['fields'] = fields | |
479 return res | |
19 | 480 |
14 | 481 def createEmptyTable(self,schema,table,fields): |
482 """create a table with the given fields | |
483 returns list of created fields""" | |
15 | 484 logging.debug("createEmptyTable") |
19 | 485 |
14 | 486 sqlFields = [] |
487 for f in fields: | |
488 if isinstance(f,dict): | |
489 # {name: XX, type: YY} | |
490 name = sqlName(f['name']) | |
491 type = f['type'] | |
70 | 492 if hasattr(self, 'toSqlTypeMap'): |
493 sqltype = self.toSqlTypeMap[type] | |
494 else: | |
495 sqltype = 'text' | |
14 | 496 |
497 else: | |
498 # name only | |
499 name = sqlName(f) | |
500 type = 'text' | |
31 | 501 sqltype = 'text' |
14 | 502 |
31 | 503 sqlFields.append({'name':name, 'type':type, 'sqltype':sqltype}) |
14 | 504 |
60 | 505 if self.hasTable(schema,table): |
506 # TODO: find owner | |
507 if not self.isAllowed("update", schema, table): | |
508 raise Unauthorized | |
509 self.executeSQL('drop table "%s"."%s"'%(schema,table),hasResult=False) | |
510 else: | |
511 if not self.isAllowed("create", schema, table): | |
512 raise Unauthorized | |
513 | |
43 | 514 fieldString = ", ".join(['"%s" %s'%(f['name'],f['sqltype']) for f in sqlFields]) |
515 sqlString = 'create table "%s"."%s" (%s)'%(schema,table,fieldString) | |
516 logging.debug("createemptytable: SQL=%s"%sqlString) | |
517 self.executeSQL(sqlString,hasResult=False) | |
518 self.setTableMetaTypes(schema,table,sqlFields) | |
519 return sqlFields | |
19 | 520 |
28 | 521 def createTableFromXML(self,schema,table,data, fields=None): |
13 | 522 """create or replace a table with the given XML data""" |
28 | 523 logging.debug("createTableFromXML schema=%s table=%s data=%s fields=%s"%(schema,table,data,fields)) |
17 | 524 tablename = sqlName(table) |
28 | 525 self.importExcelXML(schema, tablename, data, fields) |
17 | 526 return {"tablename": tablename} |
76 | 527 |
28 | 528 def importExcelXML(self,schema,table,xmldata,fields=None,fieldsOnly=False): |
14 | 529 ''' |
530 Import XML file in Excel format into the table | |
531 @param table: name of the table the xml shall be imported into | |
532 ''' | |
533 from xml.dom.pulldom import parseString,parse | |
534 | |
60 | 535 if not (fieldsOnly or self.isAllowed("create", schema, table)): |
536 raise Unauthorized | |
537 | |
14 | 538 namespace = "urn:schemas-microsoft-com:office:spreadsheet" |
539 containerTagName = "Table" | |
540 rowTagName = "Row" | |
16 | 541 colTagName = "Cell" |
14 | 542 dataTagName = "Data" |
26 | 543 xmlFields = [] |
14 | 544 sqlFields = [] |
16 | 545 numFields = 0 |
14 | 546 sqlInsert = None |
547 | |
548 logging.debug("import excel xml") | |
76 | 549 |
14 | 550 ret="" |
16 | 551 if isinstance(xmldata, str): |
14 | 552 logging.debug("importXML reading string data") |
16 | 553 doc=parseString(xmldata) |
73 | 554 else: |
14 | 555 logging.debug("importXML reading file data") |
16 | 556 doc=parse(xmldata) |
14 | 557 |
558 cnt = 0 | |
559 while True: | |
560 node=doc.getEvent() | |
16 | 561 |
14 | 562 if node is None: |
563 break | |
564 | |
565 else: | |
16 | 566 #logging.debug("tag=%s"%node[1].localName) |
14 | 567 if node[1].localName is not None: |
568 tagName = node[1].localName.lower() | |
76 | 569 else: |
14 | 570 # ignore non-tag nodes |
571 continue | |
16 | 572 |
14 | 573 if tagName == rowTagName.lower(): |
574 # start of row | |
575 doc.expandNode(node[1]) | |
576 cnt += 1 | |
577 if cnt == 1: | |
578 # first row -- field names | |
579 names=node[1].getElementsByTagNameNS(namespace, dataTagName) | |
580 for name in names: | |
581 fn = getTextFromNode(name) | |
26 | 582 xmlFields.append({'name':sqlName(fn),'type':'text'}) |
14 | 583 |
26 | 584 if fieldsOnly: |
14 | 585 # return just field names |
26 | 586 return xmlFields |
14 | 587 |
588 # create table | |
28 | 589 if fields is None: |
31 | 590 fields = xmlFields |
591 | |
592 sqlFields = self.createEmptyTable(schema, table, fields) | |
16 | 593 numFields = len(sqlFields) |
15 | 594 fieldString = ", ".join(['"%s"'%f['name'] for f in sqlFields]) |
14 | 595 valString = ", ".join(["%s" for f in sqlFields]) |
16 | 596 sqlInsert = 'insert into "%s"."%s" (%s) values (%s)'%(schema,table,fieldString,valString) |
26 | 597 #logging.debug("importexcelsql: sqlInsert=%s"%sqlInsert) |
14 | 598 |
599 else: | |
600 # following rows are data | |
16 | 601 colNodes=node[1].getElementsByTagNameNS(namespace, colTagName) |
14 | 602 data = [] |
16 | 603 hasData = False |
227 | 604 lineIndex=0 |
16 | 605 for colNode in colNodes: |
227 | 606 lineIndex+=1 |
16 | 607 dataNodes=colNode.getElementsByTagNameNS(namespace, dataTagName) |
608 if len(dataNodes) > 0: | |
227 | 609 dataIndex=0 |
228 | 610 if colNode.hasAttribute(u'ss:Index'): |
230 | 611 dataIndex=int(colNode.getAttribute(u'ss:Index')) |
612 while dataIndex>lineIndex: | |
228 | 613 data.append(None) |
230 | 614 lineIndex+=1 |
615 else: | |
616 val = getTextFromNode(dataNodes[0]) | |
617 hasData = True | |
16 | 618 else: |
619 val = None | |
19 | 620 |
14 | 621 data.append(val) |
622 | |
16 | 623 if not hasData: |
624 # ignore empty rows | |
625 continue | |
626 | |
627 # fix number of data fields | |
628 if len(data) > numFields: | |
629 del data[numFields:] | |
630 elif len(data) < numFields: | |
631 missFields = numFields - len(data) | |
632 data.extend(missFields * [None,]) | |
633 | |
634 logging.debug("importexcel sqlinsert=%s data=%s"%(sqlInsert,data)) | |
17 | 635 self.executeSQL(sqlInsert, data, hasResult=False) |
14 | 636 |
16 | 637 return cnt |
38 | 638 |
4
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
639 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
|
640 REQUEST=None): |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
641 """Change the object""" |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
642 if title is not None: |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
643 self.title = title |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
644 |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
645 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
|
646 self.connection_id = connection_id |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
647 |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
648 #checkPermission=getSecurityManager().checkPermission |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
649 REQUEST.RESPONSE.redirect('manage_main') |
e3ee1f358fe6
new version that doesn't use ZSQLExtend but the database connection more directly.
casties
parents:
2
diff
changeset
|
650 |
2
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
651 |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
652 manage_addRestDbInterfaceForm=PageTemplateFile('zpt/addRestDbInterface',globals()) |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
653 |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
654 def manage_addRestDbInterface(self, id, title='', label='', description='', |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
655 createPublic=0, |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
656 createUserF=0, |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
657 REQUEST=None): |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
658 """Add a new object with id *id*.""" |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
659 |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
660 ob=RestDbInterface(str(id),title) |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
661 self._setObject(id, ob) |
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 #checkPermission=getSecurityManager().checkPermission |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
664 REQUEST.RESPONSE.redirect('manage_main') |
61a3764cd5fb
new version RestDbInterface with working traversal and templates
casties
parents:
diff
changeset
|
665 |
5 | 666 |