Commit 212b2a7f authored by Jim Fulton's avatar Jim Fulton

Brought up to date with latest Principia models.

parent d631b227
......@@ -10,31 +10,13 @@
__doc__='''Generic Database Connection Support
$Id: Connection.py,v 1.3 1997/12/18 13:35:09 jim Exp $'''
__version__='$Revision: 1.3 $'[11:-2]
$Id: Connection.py,v 1.4 1998/01/07 16:27:15 jim Exp $'''
__version__='$Revision: 1.4 $'[11:-2]
import Globals, OFS.SimpleItem, AccessControl.Role, Persistence, Acquisition
from DateTime import DateTime
from App.Dialogs import MessageDialog
from ImageFile import ImageFile
connection_page=Globals.HTMLFile('AqueductDA/connection')
def addForm(self, REQUEST, database_type):
return connection_page(
self, REQUEST,
action='manage_addAqueduct%sConnection' % database_type,
database_type=database_type,
connection_string='',
connected='')
def add(self,class_,connection_string,check,REQUEST):
"""Add a new Folder object"""
i=class_()
i.connection_string=connection_string
if check: i.connect(connection_string)
self._setObject(i.id,i)
return self.manage_main(self,REQUEST)
from Globals import HTMLFile
class Connection(
Persistence.Persistent,
......@@ -42,12 +24,35 @@ class Connection(
OFS.SimpleItem.Item,
Acquisition.Implicit,
):
icon ='Icon'
Icon=ImageFile('www/DBAdapterFolder_icon.gif',globals())
meta_type='Aqueduct Database Adapter Folder'
# Specify definitions for tabs:
manage_options=(
{'label':'Status', 'action':'manage_main'},
{'label':'Properties', 'action':'manage_properties'},
{'label':'Security', 'action':'manage_access'},
)
# Specify how individual operations add up to "permissions":
__ac_permissions__=(
('View management screens', ('manage_tabs','manage_main',
'manage_properties')),
('Change permissions', ('manage_access',) ),
('Change', ('manage_edit',) ),
('Open/Close', ('manage_open_connection',
'manage_close_connection')),
)
# Define pre-defined types of access:
__ac_types__=(('Full Access', map(lambda x: x[0], __ac_permissions__)),
)
_v_connected=''
connection_string=''
def __init__(self, id, title, connection_string, check=None):
self.id=id
self.edit(title, connection_string, check)
def __setstate__(self, state):
Persistence.Persistent.__setstate__(self, state)
if self.connection_string: self.connect(self.connection_string)
......@@ -68,34 +73,39 @@ class Connection(
s="%s (<font color=red> not connected</font>)" % s
return s
def manage(self, REQUEST):
"Change the database connection string"
return connection_page(self, REQUEST, action='manage_connection',
database_type=self.database_type)
def connected(self): return self._v_connected
def edit(self, title, connection_string, check=1):
self.title=title
self.connection_string=connection_string
if check: self.connect(connection_string)
def manage_connection(self,value,check=None,action='',REQUEST=None):
'change database connection data'
if check: self.connect(value)
else: self.manage_close_connection(REQUEST)
self.connection_string=value
if REQUEST: return MessageDialog(
title='Connection Modified',
message='The connection information has been changed',
action='manage',
)
manage_properties=HTMLFile('connectionEdit', globals())
def manage_edit(self, title, connection_string, check=None, REQUEST=None):
"""Change connection
"""
self.edit(title, connection_string, check)
if REQUEST is not None:
return MessageDialog(
title='Edited',
message='<strong>%s</strong> has been edited.' % self.id,
action ='./manage_main',
)
manage_main=HTMLFile('connectionStatus', globals())
def manage_close_connection(self, REQUEST):
" "
try: self._v_database_connection.close()
except: pass
self._v_connected=''
if REQUEST: return MessageDialog(
title='Connection Closed',
message='The connection has been closed',
action='manage',
)
return self.manage_main(self, REQUEST)
def manage_open_connection(self, REQUEST=None):
" "
self.connect(self.connection_string)
return self.manage_main(self, REQUEST)
def __call__(self, v=None):
try: return self._v_database_connection
......@@ -122,6 +132,9 @@ class Connection(
##############################################################################
#
# $Log: Connection.py,v $
# Revision 1.4 1998/01/07 16:27:15 jim
# Brought up to date with latest Principia models.
#
# Revision 1.3 1997/12/18 13:35:09 jim
# Added ImageFile usage.
#
......
......@@ -11,12 +11,12 @@
__doc__='''Generic Database adapter
$Id: DA.py,v 1.17 1997/12/18 13:35:31 jim Exp $'''
__version__='$Revision: 1.17 $'[11:-2]
$Id: DA.py,v 1.18 1998/01/07 16:27:16 jim Exp $'''
__version__='$Revision: 1.18 $'[11:-2]
import OFS.SimpleItem, Aqueduct.Aqueduct, Aqueduct.RDB
import DocumentTemplate, marshal, md5, base64, DateTime, Acquisition, os
from Aqueduct.Aqueduct import quotedHTML, decodestring, parse, Rotor
from Aqueduct.Aqueduct import decodestring, parse, Rotor
from Aqueduct.Aqueduct import custom_default_report, default_input_form
from Globals import HTMLFile, MessageDialog
from cStringIO import StringIO
......@@ -30,17 +30,6 @@ from time import time
from zlib import compress, decompress
md5new=md5.new
addForm=HTMLFile('AqueductDA/daAdd')
from ImageFile import ImageFile
def add(self,klass,id,title,key,arguments,template,REQUEST=None):
'Add a query'
q=klass()
q.id=id
q.manage_edit(title,arguments,template,key)
self._setObject(id,q)
if REQUEST: return self.manage_main(self,REQUEST)
class DA(
Aqueduct.Aqueduct.BaseQuery,Acquisition.Implicit,
Persistence.Persistent,
......@@ -49,8 +38,6 @@ class DA(
):
'Database Adapter'
icon ='Icon'
Icon=ImageFile('www/DBAdapter_icon.gif',globals())
_col=None
sql_delimiter='\0'
max_rows_=1000
......@@ -61,21 +48,30 @@ class DA(
class_name_=class_file_=''
manage_options=(
{'icon':icon, 'label':'Basic',
'action':'manage_main', 'target':'manage_main'},
{'icon':icon, 'label':'Advanced',
'action':'manage_advancedForm',
'target':'manage_main'},
{'icon':'AccessControl/AccessControl_icon.gif',
'label':'Access Control',
'action':'manage_rolesForm', 'target':'manage_main'},
{'icon':icon,
'label':'Try It',
'action':'index_html', 'target':'manage_main'},
{'label':'Edit', 'action':'manage_main'},
{'label':'Test', 'action':'index_html'},
{'label':'Advanced', 'action':'manage_advancedForm'},
{'label':'Access Control', 'action':'manage_access'},
)
# Specify how individual operations add up to "permissions":
__ac_permissions__=(
('View management screens', ('manage_tabs','manage_main', 'index_html',
'manage_properties', 'manage_advancedForm',
)),
('Change permissions', ('manage_access',) ),
('Change', ('manage_edit',) ),
)
# Define pre-defined types of access:
__ac_types__=(('Full Access', map(lambda x: x[0], __ac_permissions__)),
)
def __init__(self, id, title, connection_id, arguments, template):
self.id=id
self.manage_edit(title, connection_id, arguments, template)
manage_main=HTMLFile('AqueductDA/edit')
manage_advancedForm=HTMLFile('AqueductDA/advanced')
test_url___roles__=None
......@@ -83,8 +79,6 @@ class DA(
'Method for testing server connection information'
return 'PING'
def quoted_src(self): return quotedHTML(self.src)
def _setKey(self, key):
if key:
self.key=key
......@@ -93,10 +87,10 @@ class DA(
del self.key
del self.rotor
def manage_edit(self,title,arguments,template,key=None, REQUEST=None):
def manage_edit(self,title,connection_id,arguments,template,REQUEST=None):
'change query properties'
self.title=title
if key is not None: self._setKey(key)
self.connection_id=connection_id
self.arguments_src=arguments
self._arg=parse(arguments)
self.src=template
......@@ -241,6 +235,13 @@ class DA(
self._arg[key] # raise KeyError if not an arg
return Traverse(self,{},key)
def connectionIsValid(self):
return (hasattr(self, self.connection_id) and
hasattr(getattr(self, self.connection_id), 'connected'))
def connected(self):
return getattr(getattr(self, self.connection_id), 'connected')()
class Traverse:
"""Helper class for 'traversing' searches during URL traversal
"""
......@@ -284,6 +285,7 @@ class Traverse:
if hasattr(r, name): return getattr(r,name)
return getattr(self._da, name)
braindir=SOFTWARE_HOME+'/Extensions'
def getBrain(self,
......@@ -323,6 +325,9 @@ def getBrain(self,
##############################################################################
#
# $Log: DA.py,v $
# Revision 1.18 1998/01/07 16:27:16 jim
# Brought up to date with latest Principia models.
#
# Revision 1.17 1997/12/18 13:35:31 jim
# Added ImageFile usage.
#
......
......@@ -11,7 +11,7 @@
<tr> <th>Title</th>
<td><!--#var title--></td></tr>
<tr> <th>Remote access encyption key</th>
<td><input name="key" size="40"
<td><input name="key" size="30"
value="<!--#var key-->"></td></tr>
<tr> <th>Maximum number of rows retrieved</th>
<td><input name="max_rows:int" size="10"
......@@ -30,10 +30,10 @@ class must be defined in a file that resides in the <code>Extensions</code>
directory of this Principia installation.
</td>
<tr> <th>Class name</th>
<td><input name="class_name" size="40"
<td><input name="class_name" size="30"
value="<!--#var class_name_-->"></td></tr>
<tr> <th>Class file</th>
<td><input name="class_file" size="40"
<td><input name="class_file" size="30"
value="<!--#var class_file_-->"></td></tr>
<tr><td> </td></tr>
......
<HTML>
<HEAD>
<TITLE>DA Database Connection Information</TITLE></HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">
<H2><!--#var database_type--> Database Connection</H2>
<form action="<!--#var action-->" method="get">
<strong>Enter the database connection string:</strong><br>
<input name="value" size="60" value="<!--#var connection_string-->"><p>
<strong>Check here to test connection string:</strong>
<input name="check" type="CHECKBOX" value="YES" CHECKED><br>
<input type="SUBMIT" name="SUBMIT" value="Set Database Connection String">
<br>
</form>
<!--#if connected-->
<form action="manage_close_connection" method="get">
<input type="SUBMIT" value="Close Database Connection">
</form>
<!--#/if-->
</body> </html>
<html>
<head><title>Add <!--#var default_title--></title></head>
<body bgcolor="#FFFFFF" link="#000099" vlink="#555555" alink="#77003B">
<h2>Add <!--#var default_title--></h2>
<form action="manage_addAqueduct<!--#var database_type-->Connection"
method="POST">
<table cellspacing="2">
<tr>
<th align="LEFT" valign="TOP">Id</th>
<td align="LEFT" valign="TOP">
<input type="TEXT" name="id" size="40"
value="<!--#var default_id-->">
</td>
</tr>
<tr>
<th align="LEFT" valign="TOP"><em>Title</em></th>
<td align="LEFT" valign="TOP">
<input type="TEXT" name="title" size="40"
value="<!--#var default_title-->">
</td>
</tr>
<tr>
<th align="LEFT" valign="TOP">Database Connection String</th>
<td align="LEFT" valign="TOP">
<input type="TEXT" name="connection_string" size="40">
</td>
</tr>
<tr>
<th align="LEFT" valign="TOP">Connect immediately</th>
<td align="LEFT" valign="TOP">
<input name="check" type="CHECKBOX" value="YES" CHECKED>
</td>
</tr>
<tr>
<td></td>
<td><br><input type="SUBMIT" value="Add"></td>
</tr>
</table>
</form>
</body>
</html>
<html>
<head><title>Edit <!--#var title_or_id--></title></head>
<body bgcolor="#FFFFFF" link="#000099" vlink="#555555" alink="#77003B">
<!--#var manage_tabs-->
<h2>Edit <!--#var title_or_id--></h2>
<form action="manage_edit" method="POST">
<table cellspacing="2">
<tr>
<th align="LEFT" valign="TOP">Id</th>
<td align="LEFT" valign="TOP"><!--#var id--></td>
</tr>
<tr>
<th align="LEFT" valign="TOP"><em>Title</em></th>
<td align="LEFT" valign="TOP">
<input type="TEXT" name="title" size="40"
value="<!--#var title-->">
</td>
</tr>
<tr>
<th align="LEFT" valign="TOP">Database Connection String</th>
<td align="LEFT" valign="TOP">
<input type="TEXT" name="connection_string" size="40"
value="<!--#var connection_string-->">
</td>
</tr>
<tr>
<th align="LEFT" valign="TOP">Connect immediately</th>
<td align="LEFT" valign="TOP">
<input name="check" type="CHECKBOX" value="YES" CHECKED>
</td>
</tr>
<tr>
<td></td>
<td><br><input type="SUBMIT" value="Change"></td>
</tr>
</table>
</form>
</body>
</html>
<html>
<head><title><!--#var title_or_id--> Status</title></head>
<body bgcolor="#FFFFFF" link="#000099" vlink="#555555" alink="#77003B">
<!--#var manage_tabs-->
<h2><!--#var title_or_id--> Status</h2>
<table cellspacing="2">
<tr>
<th align="LEFT" valign="TOP">Id</th>
<td align="LEFT" valign="TOP"><!--#var id--></td>
</tr>
<tr>
<th align="LEFT" valign="TOP"><em>Title</em></th>
<td align="LEFT" valign="TOP"><!--#var title--></td>
</tr>
<tr>
<th align="LEFT" valign="TOP">Database Connection String</th>
<td align="LEFT" valign="TOP"><!--#var connection_string--></td>
</tr>
<tr></tr><tr>
<td colspan=2>
<!--#if connected-->
The database connection is <em>open</em>.<br>
<form action="manage_close_connection" method="get">
<input type="SUBMIT" value="Close Database Connection">
</form>
<!--#else-->
The database connection is <em>not open</em>.<br>
<form action="manage_open_connection" method="get">
<input type="SUBMIT" value="Open Database Connection">
</form>
<!--#/if-->
</td>
<tr>
</table>
</body>
</html>
<HTML><HEAD><TITLE>New <!--#var database_type--> Database Adapter</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">
<H2>New <!--#var database_type--> Database Adapter</H2>
<!--#if whine-->
<em><strong>Warning:</strong>
There is no <!--#var database_type--> database connection. You need
to add an Aqueduct <!--#var database_type--> database connection
before you can use an Aqueduct <!--#var database_type--> database adapter.
</em>
<!--#/if-->
<form action="manage_addAqueduct<!--#var database_type-->DA" method="post">
<table>
<tr> <th>Id</th>
<td><input name="id" size="40"></td></tr>
<tr> <th>Title</th>
<td><input name="title" size="40"></td></tr>
<tr> <th>Arguments</th>
<td><input name="arguments" size="40"></td></tr>
<tr> <td colspan=2><strong>Query template</strong><br>
<textarea name="template:text" rows=10 cols=60>
select *
from data
</textarea></td></tr>
<tr><td><input type="hidden" name="key" value=""></td><td>
<input type="SUBMIT" name="SUBMIT" value="Add Server Query">
</td></tr>
</table>
</form>
</body></html>
<HTML><HEAD><TITLE>Edit <!--#var title_or_id--></TITLE></HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">
<!--#var manage_tabs-->
<H2>Edit <!--#var title_or_id--></H2>
<!--#if whine-->
<em><strong>Warning:</strong>
There is no <!--#var database_type--> database connection. You need
to add an Aqueduct <!--#var database_type--> database connection
before you can use an Aqueduct <!--#var database_type--> database adapter.
</em>
<!--#/if-->
<form action="manage_edit" method="POST">
<table>
<tr> <th>ID</th>
<td><!--#var id--></td></tr>
<tr> <th>Title</th>
<td><input name="title" size="40"
value="<!--#var title-->"></td></tr>
<tr> <th>Arguments</th>
<td><input name="arguments" size="40"
value="<!--#var arguments_src-->"></td>
</tr>
<tr> <td colspan=2><strong>Query template</strong><br>
<textarea name="template:text" rows=10 cols=60>
<!--#var quoted_src-->
</textarea></td></tr>
<tr><td></td><td><input type="SUBMIT" name="SUBMIT" value="Change"></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