Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Static Private Attributes
Archetypes.SQLStorageConfig.SQLStorageConfig Class Reference
Inheritance diagram for Archetypes.SQLStorageConfig.SQLStorageConfig:
Inheritance graph
[legend]
Collaboration diagram for Archetypes.SQLStorageConfig.SQLStorageConfig:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def manage_selectConnections
def manage_changeConnections
def setDefaultConn
def getDefaultConnFor
def getConfigurableTypes
def getInstalledTypes
def setConnForPortalTypes
def getConnectionById
def getConnFor

Static Public Attributes

string meta_type = 'SQL Storage Config'
tuple security = ClassSecurityInfo()
tuple manage_options

Static Private Attributes

 _conn_by_type = None
 _default_conn = None
tuple _manage_selectConnections = DTMLFile('www/selectConnections', globals())

Detailed Description

Map Archetypes to SQL Database Connections.

Definition at line 14 of file SQLStorageConfig.py.


Member Function Documentation

Get a list of types that can be configured for SQL Storage.

Definition at line 113 of file SQLStorageConfig.py.

00113 
00114     def getConfigurableTypes(self):
00115         """ Get a list of types that can be configured for SQL Storage.
00116         """
00117         c_types = []
00118         ti = self.getInstalledTypes()
00119         for t in ti:
00120             for field in t['type'].fields():
00121                 if IObjectField.isImplementedBy(field) and \
00122                    ISQLStorage.isImplementedBy(field.getStorage()):
00123                     c_types.append(t)
00124                     break
00125         return c_types
00126 

Here is the call graph for this function:

Here is the caller graph for this function:

Retrieve a given Connection.

Definition at line 167 of file SQLStorageConfig.py.

00167 
00168     def getConnectionById(self, conn_id):
00169         """ Retrieve a given Connection.
00170         """
00171         conn = getattr(self, conn_id, None)
00172         return conn

Here is the caller graph for this function:

Returns the conn that applies to the given object.
    If we get a string as the ob parameter, use it as
    the portal_type.

Definition at line 174 of file SQLStorageConfig.py.

00174 
00175     def getConnFor(self, ob):
00176         """ Returns the conn that applies to the given object.
00177             If we get a string as the ob parameter, use it as
00178             the portal_type.
00179         """
00180         cbt = self._conn_by_type
00181         if type(ob) == type(''):
00182             pt = ob
00183         elif hasattr(aq_base(ob), '_getPortalTypeName'):
00184             pt = ob._getPortalTypeName()
00185         else:
00186             pt = None
00187 
00188         if pt is None:
00189             return None
00190 
00191         conn = None
00192         if cbt is not None:
00193             conn = cbt.get(pt, None)
00194             # Note that if conn is not in cbt or has a value of
00195             # None, we use a default conn.
00196         if conn is None:
00197             conn = self.getDefaultConnFor(ob)
00198             if conn is None:
00199                 return ''
00200         return conn
00201 
00202 InitializeClass(SQLStorageConfig)

Here is the call graph for this function:

Return the default conn, if applicable, for ob.

Definition at line 102 of file SQLStorageConfig.py.

00102 
00103     def getDefaultConnFor(self, ob):
00104         """ Return the default conn, if applicable, for ob.
00105         """
00106     
00107         types_tool = getToolByName( self, 'portal_types', None )
00108         if ( types_tool is not None
00109             and types_tool.getTypeInfo( ob ) is not None ):
00110             return self._default_conn
00111         return None

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 128 of file SQLStorageConfig.py.

00128 
00129     def getInstalledTypes(self):
00130         pt = getToolByName(self, 'portal_types', None)
00131         at = getToolByName(self, TOOL_NAME, None)
00132         if pt is None:
00133             return ()
00134         if at is None:
00135             return ()
00136         pt = pt.listTypeInfo()
00137         pt = [t.getId() for t in pt]
00138 
00139         ti = at.listRegisteredTypes()
00140 
00141         installed_types = [t for t in ti if t['name'] in pt]
00142         return installed_types
00143 

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.SQLStorageConfig.SQLStorageConfig.manage_changeConnections (   self,
  default_conn,
  props = None,
  REQUEST = None 
)
Changes which connectionss apply to objects of which type.

Definition at line 65 of file SQLStorageConfig.py.

00065 
00066     def manage_changeConnections(self, default_conn, props=None, REQUEST=None):
00067         """ Changes which connectionss apply to objects of which type.
00068         """
00069         if props is None:
00070             props = REQUEST
00071         cbt = self._conn_by_type
00072         if cbt is None:
00073             self._conn_by_type = cbt = PersistentMapping()
00074         ti = self.getConfigurableTypes()
00075         types_info = []
00076         for t in ti:
00077             id = t['name']
00078             field_name = 'conn_%s' % id
00079             conn = props.get(field_name, '(Default)').strip()
00080             self.setConnForPortalTypes((id, ), conn)
00081 
00082         # Set up the default conn.
00083         self.setDefaultConn(default_conn)
00084         if REQUEST is not None:
00085             return self.manage_selectConnections(REQUEST,
00086                             manage_tabs_message='Changed.')

Here is the call graph for this function:

def Archetypes.SQLStorageConfig.SQLStorageConfig.manage_selectConnections (   self,
  REQUEST,
  manage_tabs_message = None 
)
Show a management screen for changing type to workflow connections.

Definition at line 40 of file SQLStorageConfig.py.

00040 
00041     def manage_selectConnections(self, REQUEST, manage_tabs_message=None):
00042 
00043         """ Show a management screen for changing type to workflow connections.
00044         """
00045         cbt = self._conn_by_type
00046         ti = self.getConfigurableTypes()
00047         types_info = []
00048         for t in ti:
00049             id = t['name']
00050             title = None
00051             if cbt is not None and cbt.has_key(id):
00052                 conn = cbt[id]
00053             else:
00054                 conn = '(Default)'
00055             types_info.append({'id': id,
00056                                'title': title,
00057                                'conn': conn})
00058         return self._manage_selectConnections(
00059             REQUEST,
00060             default_conn=self._default_conn,
00061             types_info=types_info,
00062             management_view='Connections',
00063             manage_tabs_message=manage_tabs_message)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.SQLStorageConfig.SQLStorageConfig.setConnForPortalTypes (   self,
  type_names,
  conn 
)
Set a conn for a specific portal type.

Definition at line 145 of file SQLStorageConfig.py.

00145 
00146     def setConnForPortalTypes(self, type_names, conn):
00147         """ Set a conn for a specific portal type.
00148         """
00149         cbt = self._conn_by_type
00150 
00151         if cbt is None:
00152             self._conn_by_type = cbt = PersistentMapping()
00153 
00154         for id in type_names:
00155             if conn == '(Default)':
00156                 # Remove from cbt.
00157                 if cbt.has_key(id):
00158                     del cbt[id]
00159             else:
00160                 conn = conn.strip()
00161                 if conn:
00162                     if not self.getConnectionById(conn):
00163                         raise ValueError, (
00164                             '"%s" is not a valid SQL Connector.' % conn)
00165                 cbt[id] = conn

Here is the call graph for this function:

Here is the caller graph for this function:

Set the default conn for this tool

Definition at line 91 of file SQLStorageConfig.py.

00091 
00092     def setDefaultConn(self, default_conn):
00093         """ Set the default conn for this tool
00094         """
00095         default_conn = default_conn.strip()
00096         if default_conn:
00097             if not self.getConnectionById(default_conn):
00098                 raise ValueError, (
00099                     '"%s" is not a valid SQL Connector.' % default_conn)
00100         self._default_conn = default_conn

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 21 of file SQLStorageConfig.py.

Definition at line 22 of file SQLStorageConfig.py.

tuple Archetypes.SQLStorageConfig.SQLStorageConfig._manage_selectConnections = DTMLFile('www/selectConnections', globals()) [static, private]

Definition at line 37 of file SQLStorageConfig.py.

Initial value:
(({ 'label' : 'Connections'
                         , 'action' : 'manage_selectConnections'
                         }
                       ),
                      )

Definition at line 26 of file SQLStorageConfig.py.

string Archetypes.SQLStorageConfig.SQLStorageConfig.meta_type = 'SQL Storage Config' [static]

Definition at line 19 of file SQLStorageConfig.py.

tuple Archetypes.SQLStorageConfig.SQLStorageConfig.security = ClassSecurityInfo() [static]

Definition at line 24 of file SQLStorageConfig.py.


The documentation for this class was generated from the following file: