[Z3-sqlos] Removing the adding view

Brian Sutherland jinty at web.de
Sun Nov 13 22:22:51 CET 2005


I wrote a testbrowser based functional test for adding SQLObject to see
what I could do about simplifying adding view.

Then I realized that an INameChooser adapter was already defined.

Then I realized that my new test still would pass if I removed the
Adding View, as the default one does everything we need.

So, am I not seeing something, or should I apply the following patch?



Index: src/sqlos/container/__init__.py
===================================================================
--- src/sqlos/container/__init__.py	(revision 19685)
+++ src/sqlos/container/__init__.py	(working copy)
@@ -13,27 +13,20 @@
 import random
 
 from sqlobject import *
-from sqlobject.main import CreateNewSQLObject
 from persistent import Persistent
 from zope.interface import implements
 from zope.component import IFactory
 from zope.app import zapi
-from zope.app.event import publish
-from zope.app.event.objectevent import ObjectCreatedEvent
-from zope.app.container.interfaces import IContainer
 from zope.app.container.interfaces import IContained
 from zope.app.container.contained import ContainedProxy
 from zope.app.container.contained import Contained
-from zope.app.container.browser.adding import Adding
 from zope.app.container.constraints import checkFactory
 from zope.app.location.interfaces import ILocation
-from zope.proxy import removeAllProxies
 from zope.proxy import sameProxiedObjects
 
 from sqlos.interfaces import ISQLObject, ISQLObjectIsolated
 from sqlos.interfaces.container import ISQLObjectContainer
 from sqlos.interfaces.container import IIsolatedSQLContainer
-from sqlos.interfaces.container import ISQLObjectAdding
 from sqlos import getFactory
 
 def contained(obj, parent=None, name=None):
@@ -224,46 +217,3 @@
             if self.container_id in obj.domains:
                 return obj
         raise KeyError, name
-
-
-class SQLObjectAdding(Adding):
-    """Custom adding view for SQLObject objects."""
-
-    implements(ISQLObjectAdding)
-
-    def __init__(self, context, request):
-        super(SQLObjectAdding, self).__init__(context, request)
-
-    def add(self, content):
-        container = IContainer(self.context)
-        klass = content.__class__
-        klass = removeAllProxies(klass)
-        package = klass.__module__.split('.')[0]
-        className = klass.__name__
-        id = content.id
-        name = '%s.%s.%s' % (package, className, id)
-        container[name] = content
-        return container[name]
-
-    def action(self, type_name=''):
-        if not type_name:
-            raise UserError(_(u"You must select the type of object to add."))
-
-        if type_name.startswith('@@'):
-            type_name = type_name[2:]
-
-        if zapi.queryView(self, type_name, self.request) is not None:
-            url = "%s/%s" % (
-                zapi.getView(self, "absolute_url", self.request),
-                type_name)
-            self.request.response.redirect(url)
-            return
-
-        content = zapi.createObject(self, type_name, CreateNewSQLObject)
-        publish(self.context, ObjectCreatedEvent(content))
-
-        self.add(content)
-        self.request.response.redirect(self.nextURL())
-
-    def namesAccepted(self):
-        return not ISQLObjectContainer.providedBy(self.context)
Index: src/sqlos/interfaces/container.py
===================================================================
--- src/sqlos/interfaces/container.py	(revision 19685)
+++ src/sqlos/interfaces/container.py	(working copy)
@@ -9,17 +9,12 @@
 """
 $Id: adapter.py 5212 2004-06-21 18:09:05Z philikon $
 """
-from zope.interface import Interface, Attribute
-from zope.schema import Choice
-from zope.app.i18n import ZopeMessageIDFactory as _
+from zope.interface import Attribute
 from zope.app.container.constraints import ItemTypePrecondition
 from zope.app.annotation.interfaces import IAttributeAnnotatable
-from zope.app.container.interfaces import IAdding
 from zope.app.container.interfaces import IContainerNamesContainer
 from zope.app.container.interfaces import IReadContainer, IContainer
 
-from sqlos.interfaces import ISQLObject
-
 class ISQLObjectReadContainer(IReadContainer, IAttributeAnnotatable):
     """ An SQLObject Container """
 
@@ -36,6 +31,3 @@
     # TODO Attribute -> zope.schema.* - jinty
     container_id = Attribute("The id of the containers, this is a filter on the"
                              "database table.")
-
-class ISQLObjectAdding(IAdding):
-    """A marker interface"""
Index: src/sqlos/configure.zcml
===================================================================
--- src/sqlos/configure.zcml	(revision 19793)
+++ src/sqlos/configure.zcml	(working copy)
@@ -16,18 +16,6 @@
 
   <!-- ISQLObjectContainer Views -->
 
-  <browser:view
-      name="+"
-      for="sqlos.interfaces.container.ISQLObjectContainer"
-      class=".container.SQLObjectAdding"
-      permission="sqlos.AddContent"
-      allowed_attributes="addingInfo"
-      menu="zmi_actions"
-      title="Add">
-    <browser:page name="index.html"  template="add.pt" />
-    <browser:page name="action.html" attribute="action" />
-  </browser:view>
-
   <content class=".container.SQLObjectContainer">
 
     <implements interface="zope.app.container.interfaces.IContentContainer" />
Index: src/sqlos/add.pt
===================================================================
--- src/sqlos/add.pt	(revision 19682)
+++ src/sqlos/add.pt	(working copy)
@@ -1,75 +0,0 @@
-<html metal:use-macro="views/standard_macros/dialog">
-<body>
-
-<div metal:fill-slot="body">
-<form action="action.html" method="POST" i18n:domain="messageboard">
-<table class="TypeListing" cellpadding="3">
-
-  <caption i18n:translate="">Add Content</caption>
-
-    <tbody tal:repeat="info view/addingInfo">
-
-    <tr>
-
-      <td class="Selector">
-        <input type="radio" name="type_name"
-               tal:attributes="value info/action; id info/action" />
-      </td>
-
-      <td class="TypeName">
-        <label style="font-weight: bold;"
-               tal:attributes="for info/action">
-          <span tal:replace="info/title" >Folder</span>
-        </label>
-        <div class="TypeDescription" tal:content="info/description">
-          Folders are generic containers for content, including other
-          folders.
-        </div>
-      </td>
-    </tr>
-
-  </tbody>
-
-  <tbody tal:condition="nothing">
-
-    <tr>
-
-      <td class="Selector">
-        <input type="radio" name="type_name" value="" />
-
-      </td>
-
-      <td class="TypeName">
-        <img alt="Folder" src="../../ZMI/www/document_icon.gif" />
-        Document
-      </td>
-
-    </tr>
-
-    <tr>
-      <td class="Selector"><br /></td>
-      <td class="TypeDescription">
-          Documents are simple textual content.
-      </td>
-    </tr>
-
-  </tbody>
-
-  <tr>
-    <td><br/></td>
-    <td>
-        <input type="text" name="id"
-               tal:condition="view/namesAccepted"
-	       tal:attributes="value request/id | nothing"
-        />
-        <input type="submit" value=" Add " 
-            i18n:attributes="value add-button"/>
-    </td>
-  </tr>
-
-</table>
-</form>
-</div>
-</body>
-</html>
-

-- 
Brian Sutherland

Metropolis - "it's the first movie with a robot. And she's a woman.
              And she's EVIL!!"



More information about the z3-sqlos mailing list