[Checkins] SVN: zmi.core/trunk/src/zmi/core/intid/ Copy browser code from zope.app.intid.

Yusei Tahara yusei at domen.cx
Sun Jun 7 11:28:18 EDT 2009


Log message for revision 100698:
  Copy browser code from zope.app.intid.
  

Changed:
  A   zmi.core/trunk/src/zmi/core/intid/
  A   zmi.core/trunk/src/zmi/core/intid/__init__.py
  A   zmi.core/trunk/src/zmi/core/intid/configure.zcml
  A   zmi.core/trunk/src/zmi/core/intid/intids.png
  A   zmi.core/trunk/src/zmi/core/intid/registrations.pt
  A   zmi.core/trunk/src/zmi/core/intid/tests.py
  A   zmi.core/trunk/src/zmi/core/intid/tracking.txt

-=-
Added: zmi.core/trunk/src/zmi/core/intid/__init__.py
===================================================================
--- zmi.core/trunk/src/zmi/core/intid/__init__.py	                        (rev 0)
+++ zmi.core/trunk/src/zmi/core/intid/__init__.py	2009-06-07 15:28:18 UTC (rev 100698)
@@ -0,0 +1,35 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Unique id utility views.
+
+$Id: __init__.py 85661 2008-04-23 19:07:02Z lgs $
+"""
+from zope.security.proxy import removeSecurityProxy
+from zope.traversing.api import traverse, getPath
+
+
+class IntIdsView(object):
+
+    def len(self):
+        return len(removeSecurityProxy(self.context).refs)
+
+    def populate(self):
+        # TODO: I think this should be moved to the functional test.
+        self.context.register(traverse(self.context, "/"))
+        self.context.register(traverse(self.context, "/++etc++site"))
+        self.request.response.redirect('index.html')
+
+    def _items(self):
+        """return all items and their path (for testing only!)"""
+        return [(uid, getPath(ref())) for uid, ref in self.context.items()]

Added: zmi.core/trunk/src/zmi/core/intid/configure.zcml
===================================================================
--- zmi.core/trunk/src/zmi/core/intid/configure.zcml	                        (rev 0)
+++ zmi.core/trunk/src/zmi/core/intid/configure.zcml	2009-06-07 15:28:18 UTC (rev 100698)
@@ -0,0 +1,37 @@
+<zope:configure
+    xmlns:zope="http://namespaces.zope.org/zope"
+    xmlns="http://namespaces.zope.org/browser"
+    i18n_domain="zope"
+    >
+
+  <addMenuItem
+      title="Unique Id Utility"
+      description="A utility that provides unique ids to objects"
+      class="zope.intid.IntIds"
+      permission="zope.ManageSite"
+      />
+
+  <page
+      name="index.html"
+      menu="zmi_views" title="Registered Objects"
+      for="zope.intid.interfaces.IIntIds"
+      permission="zope.ManageServices"
+      class=".IntIdsView"
+      template="registrations.pt"
+      />
+
+  <page
+      name="populate"
+      for="zope.intid.interfaces.IIntIds"
+      permission="zope.ManageServices"
+      class=".IntIdsView"
+      attribute="populate"
+      />
+
+  <icon
+      name="zmi_icon"
+      file="intids.png"
+      for="zope.intid.interfaces.IIntIds"
+      />
+
+</zope:configure>

Added: zmi.core/trunk/src/zmi/core/intid/intids.png
===================================================================
(Binary files differ)


Property changes on: zmi.core/trunk/src/zmi/core/intid/intids.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

Added: zmi.core/trunk/src/zmi/core/intid/registrations.pt
===================================================================
--- zmi.core/trunk/src/zmi/core/intid/registrations.pt	                        (rev 0)
+++ zmi.core/trunk/src/zmi/core/intid/registrations.pt	2009-06-07 15:28:18 UTC (rev 100698)
@@ -0,0 +1,24 @@
+<html metal:use-macro="context/@@standard_macros/view"
+    i18n:domain="zope">
+  <body>
+  <div metal:fill-slot="body">
+  <div metal:define-macro="body">
+      <p i18n:translate=""><span i18n:name="count"
+         tal:replace="view/len" /> objects</p>
+
+      <table id="sortable" class="listing" summary="Content listing"
+             tal:condition="request/testing|nothing"
+             i18n:attributes="summary">
+        <tr><th i18n:translate="">ID</th><th
+                i18n:translate="">Object</th></tr>
+        <tr tal:repeat="row view/_items">
+          <td tal:content="python:row[0]" />
+          <td><a tal:content="python:row[1]"
+                 tal:attributes="href python:row[1]" /></td>
+        </tr>
+      </table>
+  </div>
+  </div>
+  </body>
+
+</html>

Added: zmi.core/trunk/src/zmi/core/intid/tests.py
===================================================================
--- zmi.core/trunk/src/zmi/core/intid/tests.py	                        (rev 0)
+++ zmi.core/trunk/src/zmi/core/intid/tests.py	2009-06-07 15:28:18 UTC (rev 100698)
@@ -0,0 +1,81 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Int Id Utility Functional Tests
+
+$Id: tests.py 95789 2009-01-31 20:19:05Z nadako $
+"""
+import unittest
+from zope.app.testing import functional
+from zope.app.intid.testing import IntIdLayer
+
+from transaction import commit
+
+from zope.app.testing import setup, ztapi
+from zope.app.testing.functional import BrowserTestCase
+
+from zope.intid import IntIds, intIdEventNotify
+from zope.intid.interfaces import IIntIds
+from zope.traversing.api import traverse
+
+class TestFunctionalIntIds(BrowserTestCase):
+
+    def setUp(self):
+        BrowserTestCase.setUp(self)
+
+        self.basepath = '/++etc++site/default'
+        root = self.getRootFolder()
+
+        sm = traverse(root, '/++etc++site')
+        setup.addUtility(sm, 'intid', IIntIds, IntIds())
+        commit()
+
+        type_name = 'BrowserAdd__zope.intid.IntIds'
+
+        response = self.publish(
+            self.basepath + '/contents.html',
+            basic='mgr:mgrpw',
+            form={'type_name': type_name,
+                  'new_value': 'mgr' })
+
+    def test(self):
+        response = self.publish(self.basepath + '/intid/@@index.html',
+                                basic='mgr:mgrpw')
+        self.assertEquals(response.getStatus(), 200)
+        # The utility registers in itself when it is being added
+        self.assert_(response.getBody().find('1 objects') > 0)
+        self.assert_('<a href="/++etc++site">/++etc++site</a>'
+                     not in response.getBody())
+
+        response = self.publish(self.basepath + '/intid/@@populate',
+                                basic='mgr:mgrpw')
+        self.assertEquals(response.getStatus(), 302)
+
+        response = self.publish(self.basepath
+                                + '/intid/@@index.html?testing=1',
+                                basic='mgr:mgrpw')
+        self.assertEquals(response.getStatus(), 200)
+        body = response.getBody()
+        self.assert_('3 objects' in body)
+        self.assert_('<a href="/++etc++site">/++etc++site</a>' in body)
+        self.checkForBrokenLinks(body, response.getPath(), basic='mgr:mgrpw')
+
+def test_suite():
+    TestFunctionalIntIds.layer = IntIdLayer
+    browser = unittest.makeSuite(TestFunctionalIntIds)
+    tracking = functional.FunctionalDocFileSuite('tracking.txt')
+    tracking.layer = IntIdLayer
+    return unittest.TestSuite((browser, tracking))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')

Added: zmi.core/trunk/src/zmi/core/intid/tracking.txt
===================================================================
--- zmi.core/trunk/src/zmi/core/intid/tracking.txt	                        (rev 0)
+++ zmi.core/trunk/src/zmi/core/intid/tracking.txt	2009-06-07 15:28:18 UTC (rev 100698)
@@ -0,0 +1,154 @@
+Tracking Object Additions, Deletions, and Moves
+===============================================
+
+Unique ID utilities track object add moves.  Let's look at an
+example. First, we'll create a unique Id utility:
+
+  >>> print http(r"""
+  ... POST /++etc++site/default/@@contents.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Referer: http://localhost:8081/++etc++site/default/@@contents.html
+  ...
+  ... type_name=BrowserAdd__zope.intid.IntIds&new_value=""")
+  HTTP/1.1 303 ...
+  ...
+  Location: http://localhost/++etc++site/default/IntIds/@@registration.html
+  ...
+
+  >>> print http(r"""
+  ... POST /++etc++site/default/IntIds/addRegistration.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Referer: http://localhost:8081/++etc++site/default/IntIds/
+  ... Content-Type: multipart/form-data; boundary=----------CedQTrEQIEPbgfYhvcITAhQi2aJdgu3tYfJ0WYQmkpLQTt6OTOpd5GJ
+  ... 
+  ... ------------CedQTrEQIEPbgfYhvcITAhQi2aJdgu3tYfJ0WYQmkpLQTt6OTOpd5GJ
+  ... Content-Disposition: form-data; name="field.name"
+  ... 
+  ... IntIds
+  ... ------------CedQTrEQIEPbgfYhvcITAhQi2aJdgu3tYfJ0WYQmkpLQTt6OTOpd5GJ
+  ... Content-Disposition: form-data; name="field.provided"
+  ... 
+  ... zope.intid.interfaces.IIntIds
+  ... ------------CedQTrEQIEPbgfYhvcITAhQi2aJdgu3tYfJ0WYQmkpLQTt6OTOpd5GJ
+  ... Content-Disposition: form-data; name="field.provided-empty-marker"
+  ... 
+  ... 1
+  ... ------------CedQTrEQIEPbgfYhvcITAhQi2aJdgu3tYfJ0WYQmkpLQTt6OTOpd5GJ
+  ... Content-Disposition: form-data; name="field.comment"
+  ... 
+  ... 
+  ... ------------CedQTrEQIEPbgfYhvcITAhQi2aJdgu3tYfJ0WYQmkpLQTt6OTOpd5GJ
+  ... Content-Disposition: form-data; name="field.actions.register"
+  ... 
+  ... Register
+  ... ------------CedQTrEQIEPbgfYhvcITAhQi2aJdgu3tYfJ0WYQmkpLQTt6OTOpd5GJ--
+  ... """)
+  HTTP/1.1 303 ...
+  ...
+
+Now, we'll add a few folders:
+
+  >>> print http(r"""
+  ... POST /@@contents.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Content-Length: 64
+  ... Content-Type: application/x-www-form-urlencoded
+  ... 
+  ... type_name=BrowserAdd__zope.site.folder.Folder&new_value=f1""")
+  HTTP/1.1 303 ...
+  ...
+
+  >>> print http(r"""
+  ... POST /f1/@@contents.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Content-Length: 64
+  ... Content-Type: application/x-www-form-urlencoded
+  ... 
+  ... type_name=BrowserAdd__zope.site.folder.Folder&new_value=f1""")
+  HTTP/1.1 303 ...
+  ...
+
+  >>> print http(r"""
+  ... POST /f1/@@contents.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Content-Length: 64
+  ... Content-Type: application/x-www-form-urlencoded
+  ... 
+  ... type_name=BrowserAdd__zope.site.folder.Folder&new_value=f2""")
+  HTTP/1.1 303 ...
+  ...
+
+  >>> print http(r"""
+  ... POST /f1/f1/@@contents.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Content-Length: 64
+  ... Content-Type: application/x-www-form-urlencoded
+  ... 
+  ... type_name=BrowserAdd__zope.site.folder.Folder&new_value=f1""")
+  HTTP/1.1 303 ...
+  ...
+
+Now, if we look at the index page for the unique id utility, we'll see
+the objects we added:
+
+  >>> print http(r"""
+  ... GET /++etc++site/default/IntIds/@@index.html?testing=1 HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Referer: http://localhost:8081/++etc++site/default/@@contents.html
+  ... """)
+  HTTP/1.1 200 ...
+  ...4 objects...
+  .../f1...
+  .../f1/f1...
+  .../f1/f2...
+  .../f1/f1/f1...
+
+If we move the top object:
+
+  >>> print http(r"""
+  ... POST /@@contents.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Content-Length: 40
+  ... Content-Type: application/x-www-form-urlencoded
+  ... Referer: http://localhost:8081/@@contents.html
+  ... 
+  ... new_value%3Alist=f2&rename_ids%3Alist=f1""")
+  HTTP/1.1 303 ...
+  ...
+
+We'll see that reflected in the utility:
+
+  >>> print http(r"""
+  ... GET /++etc++site/default/IntIds/@@index.html?testing=1 HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Referer: http://localhost:8081/++etc++site/default/@@contents.html
+  ... """)
+  HTTP/1.1 200 ...
+  ...4 objects...
+  .../f2...
+  .../f2/f1...
+  .../f2/f2...
+  .../f2/f1/f1...
+
+And if we delete the top object:
+
+  >>> print http(r"""
+  ... POST /@@contents.html HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Content-Length: 44
+  ... Content-Type: application/x-www-form-urlencoded
+  ... Referer: http://localhost:8081/@@contents.html
+  ... 
+  ... ids%3Alist=f2&container_delete_button=Delete""")
+  HTTP/1.1 303 ...
+  ...
+
+all of the objects will go away:
+
+  >>> print http(r"""
+  ... GET /++etc++site/default/IntIds/@@index.html?testing=1 HTTP/1.1
+  ... Authorization: Basic mgr:mgrpw
+  ... Referer: http://localhost:8081/++etc++site/default/@@contents.html
+  ... """)
+  HTTP/1.1 200 ...
+  ...0 objects...


Property changes on: zmi.core/trunk/src/zmi/core/intid/tracking.txt
___________________________________________________________________
Added: svn:eol-style
   + native



More information about the Checkins mailing list