[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services - configure.zcml:1.69 connection.py:1.15 connection.zcml:1.10 connections.pt:1.15 service.py:1.36 configureConnection.pt:NONE

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Aug 19 04:10:16 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/browser/services
In directory cvs.zope.org:/tmp/cvs-serv15967/browser/services

Modified Files:
	configure.zcml connection.py connection.zcml connections.pt 
	service.py 
Removed Files:
	configureConnection.pt 
Log Message:
Heads up, this is the beginning of Servicegeddon. We noticed that named 
components are a pain in the butt and that we can simpluify our code a lot
by making these named components local utilities. 

So I started with the SQL Connection service and database adapters and 
simplified the code greatly. Database Adaptors are now just simple 
utilities.

I also took the oppurtunity and updated all database adapters. 

This change is not backward compatible and you will have to toss your ZODB.
Although all tests pass, I expect there to be some hickups, so feel free to 
fix or report these. 

Next I will fix up the front screen a bit and try to factor some other 
pieces. I also still miss some functionality in the Utilities, which I plan
to add.




=== Zope3/src/zope/app/browser/services/configure.zcml 1.68 => 1.69 ===
--- Zope3/src/zope/app/browser/services/configure.zcml:1.68	Fri Aug 15 20:42:54 2003
+++ Zope3/src/zope/app/browser/services/configure.zcml	Tue Aug 19 03:09:37 2003
@@ -455,19 +455,6 @@
 
   </view>
 
-<!-- "Add Connection" menu -->
-
-  <view
-    name="AddConnection"
-     for="zope.app.interfaces.services.folder.ISiteManagementFolder"
-     permission="zope.ManageServices"
-     class="zope.app.browser.services.service.ConnectionAdding">
-
-    <page name="index.html"  attribute="index"  />
-    <page name="action.html" attribute="action" />
-
-  </view>
-
 <!-- "Add Cache" menu -->
 
   <view


=== Zope3/src/zope/app/browser/services/connection.py 1.14 => 1.15 ===
--- Zope3/src/zope/app/browser/services/connection.py:1.14	Thu Aug  7 13:41:03 2003
+++ Zope3/src/zope/app/browser/services/connection.py	Tue Aug 19 03:09:38 2003
@@ -11,160 +11,50 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""Connection registry support classes.
+"""Connection View classes
 
 $Id$
 """
-from zope.app.browser.services.registration import AddComponentRegistration
+from zope.app import zapi
+from zope.app.component.nextservice import queryNextService
 from zope.app.i18n import ZopeMessageIDFactory as _
-from zope.app.interfaces.container import IZopeContainer
-from zope.app.interfaces.services.registration import IRegistered
-from zope.app.interfaces.services.registration import ActiveStatus
-from zope.app.interfaces.services.registration import RegisteredStatus
-from zope.app.interfaces.services.registration import UnregisteredStatus
-from zope.app.traversing import traverse, getPath, getParent, getName
-from zope.component import getAdapter, getView
+from zope.app.interfaces.rdb import IZopeDatabaseAdapter
+from zope.app.services.servicenames import SQLDatabaseConnections, Utilities
 
 class Connections:
+    """Connection Overview"""
 
-    # self.context is the local connection service
+    def getLocalConnections(self):
+        conns = []
+        utilities = zapi.getService(self.context, Utilities)
+        matching = utilities.getRegisteredMatching(IZopeDatabaseAdapter)
+        for match in matching:
+            conns.append(self.buildInfo(match))
+        return conns
+
+
+    def getInheritedConnections(self):
+        conns = []
+        next = queryNextService(self.context, Utilities)
+        while next is not None:
+            matching = next.getRegisteredMatching(IZopeDatabaseAdapter)
+            for match in matching:
+                conns.append(self.buildInfo(match))
+            next = queryNextService(next, Utilities)
+        return conns
+
+
+    def buildInfo(self, match):
+        info = {}
+        info['id'] = match[1]
+        info['url'] = str(zapi.getView(match[2].active().getComponent(),
+                                       'absolute_url', self.request))
 
-    def update(self):
-        """Possibly deactivate or delete one or more connections.
+        info['dsn'] = match[2].active().getComponent().dsn    
+        return info
 
-        In that case, issue a message.
-        """
-        todo = self.request.get("selected")
-        doActivate = self.request.get("Activate")
-        doDeactivate = self.request.get("Deactivate")
-        doDelete = self.request.get("Delete")
-        if not todo:
-            if doDeactivate or doDelete:
-                return _("Please select at least one checkbox")
-            return None
-        if doActivate:
-            return self._activate(todo)
-        if doDeactivate:
-            return self._deactivate(todo)
-        if doDelete:
-            return self._delete(todo)
-
-    def _activate(self, todo):
-        done = []
-        for name in todo:
-            registry = self.context.queryRegistrations(name)
-            obj = registry.active()
-            if obj is None:
-                # Activate the first registered registration
-                obj = registry.info()[0]['registration']
-                obj.status = ActiveStatus
-                done.append(name)
-        if done:
-            s = _("Activated: ${activated_connections}")
-            s.mapping = {'activated_connections': ", ".join(done)}
-            return s
-        else:
-            return _("All of the checked connections were already active")
-
-    def _deactivate(self, todo):
-        done = []
-        for name in todo:
-            registry = self.context.queryRegistrations(name)
-            obj = registry.active()
-            if obj is not None:
-                obj.status = RegisteredStatus
-                done.append(name)
-        if done:
-            s = _("Deactivated: ${deactivated_connections}")
-            s.mapping = {'deactivated_connections': ", ".join(done)}
-            return s
-        else:
-            return _("None of the checked connections were active")
-
-    def _delete(self, todo):
-        errors = []
-        for name in todo:
-            registry = self.context.queryRegistrations(name)
-            assert registry
-            if registry.active() is not None:
-                errors.append(name)
-                continue
-        if errors:
-            s = _("Can't delete active connection(s): ${connection_names}; "
-                  "use the Deactivate button to deactivate")
-            s.mapping = {'connection_names': ", ".join(errors)}
-            return s
-
-        # 1) Delete the registrations
-        connections = {}
-        for name in todo:
-            registry = self.context.queryRegistrations(name)
-            assert registry
-            assert registry.active() is None # Phase error
-            for info in registry.info():
-                conf = info['registration']
-                obj = conf.getComponent()
-                path = getPath(obj)
-                connections[path] = obj
-                conf.status = UnregisteredStatus
-                parent = getParent(conf)
-                name = getName(conf)
-                container = getAdapter(parent, IZopeContainer)
-                del container[name]
-
-        # 2) Delete the connection objects
-        for path, obj in connections.items():
-            parent = getParent(obj)
-            name = getName(obj)
-            container = getAdapter(parent, IZopeContainer)
-            del container[name]
-
-        s = _("Deleted: ${connection_names}")
-        s.mapping = {'connection_names': ", ".join(todo)}
-        return s
-
-    def getConfigs(self):
-        L = []
-        for name in self.context.listRegistrationNames():
-            cr = self.context.queryRegistrations(name)
-            active = cr.active()
-            d = {"name": name,
-                 "url": "",
-                 "configurl": ("@@configureConnection.html?name=%s" % name),
-                 }
-            if active is not None:
-                d["url"] = str(getView(active.getComponent(),
-                                       "absolute_url",
-                                       self.request))
-            L.append((name, d))
-        L.sort()
-        return [d for name, d in L]
-
-class ConfigureConnection:
-
-    def update(self):
-        cr = self.context.queryRegistrations(self.request['name'])
-        form = getView(cr, "ChangeRegistrations", self.request)
-        form.update()
-        return form
-
-class Registered:
-    """View for displaying the registrations for a connection."""
-
-    def uses(self):
-        """Get a sequence of registration summaries."""
-        component = self.context
-        useconfig = getAdapter(component, IRegistered)
-        result = []
-        for path in useconfig.usages():
-            config = traverse(component, path)
-            url = getView(config, 'absolute_url', self.request)
-            result.append({'name': config.name,
-                           'path': path,
-                           'url': url(),
-                           'status': config.status,
-                           })
-        return result
+from zope.app.browser.services.service import ComponentAdding
 
-class AddConnectionRegistration(AddComponentRegistration):
-    pass
+class ConnectionAdding(ComponentAdding):
+
+    menu_id = "add_connection"


=== Zope3/src/zope/app/browser/services/connection.zcml 1.9 => 1.10 ===
--- Zope3/src/zope/app/browser/services/connection.zcml:1.9	Thu Aug  7 13:41:03 2003
+++ Zope3/src/zope/app/browser/services/connection.zcml	Tue Aug 19 03:09:38 2003
@@ -2,18 +2,34 @@
 
 <!-- Browser directives for the connection service -->
 
+  <view
+      for="zope.app.interfaces.services.folder.ISiteManagementFolder"
+      name="AddSQLConnection"
+      class=".connection.ConnectionAdding"
+      permission="zope.ManageContent"
+      allowed_attributes="addingInfo">
+      
+    <page name="index.html"  attribute="index" />
+    <page name="action.html" attribute="action" />
+      
+  </view>
+
+  <menuItem
+      for="zope.app.interfaces.services.connection.ILocalConnectionService"
+      menu="zmi_actions" title="Add DA"
+      action="../AddSQLConnection"
+      permission="zope.ManageServices" />
+
   <!-- "Add service" menu entry to add a connection service.
        The action attribute matches a factory name defined in
        zope/app/services/configure.zcml. -->
   <menuItem
       for="zope.app.interfaces.container.IAdding"
       menu="add_service" title="SQL Connection Service"
-      action="ConnectionService"
       description="A Persistent SQL Connection Service for TTW development"
-      permission="zope.ManageServices"
-      />
+      action="zope.services.ConnectionService"
+      permission="zope.ManageServices" />
 
-  <!-- ZMI tab named "Connections" for the connection service -->
   <page
       for="zope.app.interfaces.services.connection.ILocalConnectionService"
       name="index.html"
@@ -21,50 +37,5 @@
       class=".connection.Connections"
       permission="zope.ManageServices"
       menu="zmi_views" title="Connections" />
-
-<!-- Browser directives for registering individual connection objects -->
-
-  <!-- Registration page for connection objects.  You get here by
-       clicking on the (change registration) link for a particular
-       connection in the "Connections" tab of the connection service.
-       It shows a menu of different registration, at most one of which
-       is active.  You can activate a different registration, or click
-       on an individual registration to edit it.  (Note that this page
-       doesn't really apply to a single connection, it applies to a
-       single connection name. -->
-  <page
-      for="zope.app.interfaces.services.connection.ILocalConnectionService"
-      name="configureConnection.html"
-      template="configureConnection.pt"
-      class=".connection.ConfigureConnection"
-      permission="zope.ManageServices" />
-
-  <!-- When creating a new connection object, you are taken to this
-       form to register it.  The form lets you define the connection
-       name, a permission, and a registration status (Unregistered,
-       Registered or Active). -->
-  <addform
-      label="New Connection Registration"
-      for="zope.app.interfaces.rdb.IZopeDatabaseAdapter"
-      name="addRegistration.html"
-      schema="zope.app.interfaces.services.connection.IConnectionRegistration"
-      class=".connection.AddConnectionRegistration"
-      permission="zope.ManageServices"
-      content_factory="zope.app.services.connection.ConnectionRegistration"
-      arguments="name componentPath"
-      set_after_add="status"
-      fields="name componentPath permission status" />
-
-  <!-- When editing the registration of an existing connection object,
-       you are taken to this form.  It is similar to the above add
-       form, but doesn't let you change the name or path.
-       (Thus leaving only permission and registration status.) -->
-  <editform
-      menu="zmi_views" title="Edit"
-      label="Edit Connection Registration"
-      name="index.html"
-      schema="zope.app.interfaces.services.connection.IConnectionRegistration"
-      permission="zope.ManageServices"
-      fields="name componentPath permission status" />
 
 </configure>


=== Zope3/src/zope/app/browser/services/connections.pt 1.14 => 1.15 ===
--- Zope3/src/zope/app/browser/services/connections.pt:1.14	Thu Aug  7 13:41:03 2003
+++ Zope3/src/zope/app/browser/services/connections.pt	Tue Aug 19 03:09:38 2003
@@ -1,63 +1,25 @@
 <html metal:use-macro="context/@@standard_macros/page">
 <body>
-<div metal:fill-slot="body"
-     tal:define="message view/update; configs view/getConfigs">
-
-  <h2 i18n:translate="">Connections registered in this connection service:</h2>
-
-  <div class="message" tal:condition="message">
-     <span tal:replace="message">view/update message here</span>
-     <br /><br />
-     <i><a href="" i18n:translate="">(click to clear message)</a></i>
-  </div>
-
-  <p tal:condition="not:configs">None</p>
-
-  <form method="POST" action="index.html" tal:condition="configs">
-
-    <table>
-      <tr tal:repeat="config configs">
-        <td><input type="checkbox" name="selected:list"
-                   tal:attributes="value config/name" />
-        </td>
-        <td>
-
-          <a href="."
-             tal:condition="config/url"
-             tal:attributes="href config/url">
-            <span tal:replace="config/name" />
-          </a>
-
-          <span tal:condition="not:config/url">
-            <span tal:replace="config/name" />
-            <span i18n:translate="">(inactive)</span>
-          </span>
-
-        </td>
-        <td>
-          <a href="."
-             tal:attributes="href config/configurl"
-             i18n:translate="">(change registration)</a>
-        </td>
-      </tr>
-    </table>
-
-    <input type="submit" name="Activate" value="Activate" 
-           i18n:attributes="value activate-button"/>
-    <input type="submit" name="Deactivate" value="Deactivate"
-           i18n:attributes="value deactivate-button"/>
-    &nbsp;
-    <input type="submit" name="Delete" value="Delete"
-           i18n:attributes="value delete-button"/>
-    &nbsp;
-    <input type="submit" name="Refresh" value="Refresh"
-           i18n:attributes="value refresh-button"/>
-
-  </form>
-
-  <p><a href="../AddConnection" i18n:translate="">Add a connection to this
-  connection service</a></p>
+<div metal:fill-slot="body">
 
+  <h2 i18n:translate="">Local Connections</h2>
+  <ul>
+    <li tal:repeat="conn view/getLocalConnections">
+      <a href="" tal:attributes="href conn/url">
+        <b tal:content="conn/id" /> (<span tal:replace="conn/dsn"/>)
+      </a>
+    </li>
+  </ul>
+  <a href="../AddSQLConnection">Add Connection</a>
+
+  <h2 i18n:translate="">Inherited Connections</h2>
+  <ul>
+    <li tal:repeat="conn view/getInheritedConnections">
+      <a href="" tal:attributes="href conn/url">
+        <b tal:content="conn/id" /> (<span tal:replace="conn/dsn"/>)
+      </a>
+    </li>
+  </ul>
 
 </div>
 </body>


=== Zope3/src/zope/app/browser/services/service.py 1.35 => 1.36 ===
--- Zope3/src/zope/app/browser/services/service.py:1.35	Sun Aug 17 02:05:47 2003
+++ Zope3/src/zope/app/browser/services/service.py	Tue Aug 19 03:09:38 2003
@@ -99,10 +99,6 @@
             raise TypeError("%s is not a local utility" % content)
         return zapi.ContextSuper(UtilityAdding, self).add(content)
 
-class ConnectionAdding(ComponentAdding):
-    """Adding subclass used for adding database connections."""
-
-    menu_id = "add_connection"
 
 class CacheAdding(ComponentAdding):
     """Adding subclass used for adding caches."""

=== Removed File Zope3/src/zope/app/browser/services/configureConnection.pt ===




More information about the Zope3-Checkins mailing list