Commit 83a58eff authored by Jeffrey Shell's avatar Jeffrey Shell

Added new test-tab-feature on database connection objects

parent 2d5ab3c7
############################################################################## 7##############################################################################
# #
# Zope Public License (ZPL) Version 1.0 # Zope Public License (ZPL) Version 1.0
# ------------------------------------- # -------------------------------------
...@@ -84,8 +84,8 @@ ...@@ -84,8 +84,8 @@
############################################################################## ##############################################################################
__doc__='''Shared classes and functions __doc__='''Shared classes and functions
$Id: Aqueduct.py,v 1.36 1999/07/21 19:43:39 michel Exp $''' $Id: Aqueduct.py,v 1.37 1999/09/21 15:43:18 jeffrey Exp $'''
__version__='$Revision: 1.36 $'[11:-2] __version__='$Revision: 1.37 $'[11:-2]
import Globals, os import Globals, os
from Globals import HTMLFile, Persistent from Globals import HTMLFile, Persistent
...@@ -289,8 +289,8 @@ def custom_default_report(id, result, action='', no_table=0, ...@@ -289,8 +289,8 @@ def custom_default_report(id, result, action='', no_table=0,
row=[] row=[]
for c in columns: for c in columns:
n=c['name'] n=c['name']
if goofy(n) >= 0: n='expr="_vars[\'%s]"' % (`'"'+n`[2:]) if goofy(n) >= 0: n='expr="_[\'%s]"' % (`'"'+n`[2:])
row.append(' %s<!--#var %s%s-->%s' row.append(' %s<dtml-var %s%s>%s'
% (td,n,c['type']!='s' and ' null=""' or '',_td)) % (td,n,c['type']!='s' and ' null=""' or '',_td))
row=(' %s\n%s\n %s' % (tr,string.joinfields(row,delim), _tr)) row=(' %s\n%s\n %s' % (tr,string.joinfields(row,delim), _tr))
......
...@@ -85,14 +85,17 @@ ...@@ -85,14 +85,17 @@
__doc__='''Generic Database Connection Support __doc__='''Generic Database Connection Support
$Id: Connection.py,v 1.18 1999/03/25 16:07:28 jim Exp $''' $Id: Connection.py,v 1.19 1999/09/21 15:43:18 jeffrey Exp $'''
__version__='$Revision: 1.18 $'[11:-2] __version__='$Revision: 1.19 $'[11:-2]
import Globals, OFS.SimpleItem, AccessControl.Role, Acquisition, sys import Globals, OFS.SimpleItem, AccessControl.Role, Acquisition, sys
from DateTime import DateTime from DateTime import DateTime
from App.Dialogs import MessageDialog from App.Dialogs import MessageDialog
from Globals import HTMLFile from Globals import HTMLFile
from string import find, join, split from string import find, join, split
from Aqueduct import custom_default_report
from Results import Results
import DocumentTemplate
class Connection( class Connection(
Globals.Persistent, Globals.Persistent,
...@@ -105,6 +108,7 @@ class Connection( ...@@ -105,6 +108,7 @@ class Connection(
manage_options=( manage_options=(
{'label':'Status', 'action':'manage_main'}, {'label':'Status', 'action':'manage_main'},
{'label':'Properties', 'action':'manage_properties'}, {'label':'Properties', 'action':'manage_properties'},
{'label':'Test', 'action':'manage_testForm'},
{'label':'Security', 'action':'manage_access'}, {'label':'Security', 'action':'manage_access'},
) )
...@@ -112,6 +116,7 @@ class Connection( ...@@ -112,6 +116,7 @@ class Connection(
__ac_permissions__=( __ac_permissions__=(
('View management screens', ('manage_main',)), ('View management screens', ('manage_main',)),
('Change Database Connections', ('manage_edit',)), ('Change Database Connections', ('manage_edit',)),
('Test Database Connections', ('manage_testForm','manage_test')),
('Open/Close Database Connection', ('Open/Close Database Connection',
('manage_open_connection', 'manage_close_connection')), ('manage_open_connection', 'manage_close_connection')),
) )
...@@ -164,6 +169,31 @@ class Connection( ...@@ -164,6 +169,31 @@ class Connection(
action ='./manage_main', action ='./manage_main',
) )
manage_testForm=HTMLFile('connectionTestForm', globals())
def manage_test(self, query, REQUEST=None):
"Executes the SQL in parameter 'query' and returns results"
dbc=self() #get our connection
res=dbc.query(query)
result=Results(res)
if REQUEST is None:
return result #return unadulterated result objects
if result._searchable_result_columns():
r=custom_default_report(self.id, result)
else:
r='This was not a query.'
report=DocumentTemplate.HTML(
'<html><body bgcolor="#ffffff" link="#000099" vlink="#555555">\n'
'<dtml-var name="manage_tabs">\n<hr>\n%s\n\n'
'<hr><h4>SQL Used:</strong><br>\n<pre>\n%s\n</pre>\n<hr>\n'
'</body></html>'
% (r, query))
report=apply(report,(self,REQUEST),{self.id:result})
return report
manage_main=HTMLFile('connectionStatus', globals()) manage_main=HTMLFile('connectionStatus', globals())
......
<html>
<head><title>Test &dtml-title_or_id;</title></head>
<body bgcolor="#FFFFFF" link="#000099" vlink="#555555" alink="#77003B">
<dtml-var manage_tabs>
<h2>Test query on <dtml-var title_or_id></h2>
<form action="manage_test" method="post">
<table border="0">
<tr valign="top">
<th align="left">Query:</th>
<td><textarea rows="10" cols="60" name="query:text" wrap="off" accesskey="e" tabindex="1"></textarea></td>
</tr>
<tr>
<th align="left">&nbsp;</th>
<td><input type="submit" value="Submit Query"></td>
</tr>
</table>
</form>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment