[Checkins] SVN: zope.app.preference/trunk/ - Added HTML labels to ZMI forms.

Michael Howitz mh at gocept.com
Fri Jun 11 13:11:19 EDT 2010


Log message for revision 113357:
  - Added HTML labels to ZMI forms.
  
  - Removed `edit.pt` as it seems to be unused.
  
  - Added tests for the ZMI views.
  
  

Changed:
  U   zope.app.preference/trunk/CHANGES.txt
  U   zope.app.preference/trunk/setup.py
  D   zope.app.preference/trunk/src/zope/app/preference/edit.pt
  A   zope.app.preference/trunk/src/zope/app/preference/ftesting.zcml
  U   zope.app.preference/trunk/src/zope/app/preference/macros.pt
  A   zope.app.preference/trunk/src/zope/app/preference/testing.py
  U   zope.app.preference/trunk/src/zope/app/preference/tests.py
  A   zope.app.preference/trunk/src/zope/app/preference/zmi.txt

-=-
Modified: zope.app.preference/trunk/CHANGES.txt
===================================================================
--- zope.app.preference/trunk/CHANGES.txt	2010-06-11 15:44:28 UTC (rev 113356)
+++ zope.app.preference/trunk/CHANGES.txt	2010-06-11 17:11:19 UTC (rev 113357)
@@ -2,20 +2,26 @@
 CHANGES
 =======
 
-3.6.0 (unreleased)
+3.7.0 (unreleased)
 ------------------
 
-- ...
+- Added HTML labels to ZMI forms.
 
+- Removed `edit.pt` as it seems to be unused.
+
+- Added tests for the ZMI views.
+
+
 3.6.0 (2009-02-01)
 ------------------
 
 - Use ``zope.container`` instead of ``zope.app.container``.
 
+
 3.5.0 (2009-01-17)
 ------------------
 
-- Get rid of ``zope.app.zapi`` dependency, replacing its uses with direct
+- Got rid of ``zope.app.zapi`` dependency, replacing its uses with direct
   imports from original places.
 
 - Change mailing address from zope3-dev to zope-dev, as the first one
@@ -26,6 +32,7 @@
 - Remove zpkg stuff and zcml include files for
   old mkzopeinstance-based instances.
 
+
 3.4.1 (2007-10-30)
 ------------------
 

Modified: zope.app.preference/trunk/setup.py
===================================================================
--- zope.app.preference/trunk/setup.py	2010-06-11 15:44:28 UTC (rev 113356)
+++ zope.app.preference/trunk/setup.py	2010-06-11 17:11:19 UTC (rev 113357)
@@ -57,8 +57,13 @@
       packages=find_packages('src'),
       package_dir = {'': 'src'},
       namespace_packages=['zope', 'zope.app'],
-      extras_require=dict(test=['zope.app.testing',
-                                'zope.testing']),
+      extras_require=dict(test=[
+          'zope.app.testing',
+          'zope.app.zcmlfiles',
+          'zope.securitypolicy',
+          'zope.testbrowser',
+          'zope.testing',
+          ]),
       install_requires = ['setuptools',
                           'ZODB3',
                           'zope.annotation',

Deleted: zope.app.preference/trunk/src/zope/app/preference/edit.pt
===================================================================
--- zope.app.preference/trunk/src/zope/app/preference/edit.pt	2010-06-11 15:44:28 UTC (rev 113356)
+++ zope.app.preference/trunk/src/zope/app/preference/edit.pt	2010-06-11 17:11:19 UTC (rev 113357)
@@ -1,123 +0,0 @@
-<html metal:use-macro="context/@@apidoc_macros/details">
-<head>
-  <style type="text/css" media="all"
-         metal:fill-slot="style_slot">
- 
-table.prefs {
-  border: 0pt;
-  width: 80%;
-}    
-
-tr {
-  margin: 0pt;
-  padding: 0pt;
-  border: 0pt;
-}
-
-tr.odd {
-  background: #fffbbe;
-}
-
-tr.first td {
-  border-top: 1pt solid #0000C0;
-}
-
-td {
-  padding: 3pt;
-  border-bottom: 1pt solid #0000C0;
-}
-
-td.input {
-  vertical-align: middle;
-  text-align: center;
-}
-
-td.description {
-
-}
-
-td.controls {
-  margin-top: 10pt;
-  border: 0pt;
-  padding: 4pt;
-  background: #ccf;
-  text-align: right;
-}
-
-td.spacer {
-  padding: 5pt;
-  border: 0pt;
-}
-
-div.documentation blockquote {
-  margin: 0pt;
-  padding: 0pt;
-}
-
-div.error {
-  font-weight: bold;
-  margin: 3pt 0pt;
-  color: #ffaa22;
-}
-  </style>
-</head>
-<body metal:fill-slot="contents">
-
-  <h1 tal:content="view/label">Edit something</h1>
-
-  <div class="documentation" tal:content="structure view/getIntroduction">
-    Here is the doc string
-  </div>
-
-  <p tal:define="status view/update"
-     tal:condition="status"
-     tal:content="status" />
-
-  <p tal:condition="view/errors" i18n:translate="">
-    There are <strong tal:content="python:len(view.errors)"
-                      i18n:name="num_errors">6</strong> input errors.
-  </p>
-  <br />
-
-  <form action="." tal:attributes="action request/URL" method="post"
-        enctype="multipart/form-data">
-      
-  <table class="prefs" cellspacing="0" cellpadding="0">
-    <tal:block repeat="widget view/widgets" >
-    <tr class=""
-        tal:define="parity repeat/widget/parity;
-                    firstrow repeat/widget/start"
-        tal:attributes="class python: parity + 
-                                      (firstrow and ' first' or '')">
-      <td class="description">
-        <b tal:content="widget/label">Option</b>
-        <div class="indent small">
-          <div tal:content="widget/hint">
-            Explanation
-          </div>
-          <div class="error" tal:define="error widget/error"
-            tal:condition="error" tal:content="structure error">
-            The Error
-          </div>
-        </div>
-      </td>
-      <td class="input" tal:content="structure widget">
-        <input type="text" style="width:100%"/>
-      </td>
-    </tr>
-    </tal:block>
-    <tr><td class="spacer"></td></tr>
-    <tr>
-      <td colspan="2" class="controls">
-        <input type="submit" value="Refresh" 
-            i18n:attributes="value refresh-button" />
-        <input type="submit" name="UPDATE_SUBMIT" value="Change" 
-            i18n:attributes="value submit-button"/>
-      </td>
-    </tr>
-  </table>
-
-  </form>
-
-</body>
-</html>

Added: zope.app.preference/trunk/src/zope/app/preference/ftesting.zcml
===================================================================
--- zope.app.preference/trunk/src/zope/app/preference/ftesting.zcml	                        (rev 0)
+++ zope.app.preference/trunk/src/zope/app/preference/ftesting.zcml	2010-06-11 17:11:19 UTC (rev 113357)
@@ -0,0 +1,13 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+  <!-- This file is the equivalent of site.zcml and it is -->
+  <!-- used for functional testing setup -->
+
+  <include package="zope.app.zcmlfiles" />
+  <include package="zope.app.tree" />
+  <include package="zope.app.renderer" />
+
+  <include package="zope.app.preference" file="meta.zcml"/>
+  <include package="zope.app.preference" />
+
+</configure>


Property changes on: zope.app.preference/trunk/src/zope/app/preference/ftesting.zcml
___________________________________________________________________
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native

Modified: zope.app.preference/trunk/src/zope/app/preference/macros.pt
===================================================================
--- zope.app.preference/trunk/src/zope/app/preference/macros.pt	2010-06-11 15:44:28 UTC (rev 113356)
+++ zope.app.preference/trunk/src/zope/app/preference/macros.pt	2010-06-11 17:11:19 UTC (rev 113357)
@@ -49,7 +49,7 @@
   <td class="list-item"
       tal:attributes="colspan python:maxDepth-len(nodeInfo['row-state'])+1">
     &nbsp;<a href=""
-       tal:attributes="href 
+       tal:attributes="href
            string:${node/context/@@absolute_url}/@@index.html"
        tal:content="node/context/zope:name">
       node/id
@@ -60,7 +60,7 @@
 </tr>
 
 </table>
-  
+
 </metal:block>
 
 
@@ -100,7 +100,7 @@
 
   <div tal:content="structure view/getIntroduction">
     Category Description goes here.
-  </div>  
+  </div>
   <br/>
 
   <p tal:define="status view/update"
@@ -111,7 +111,7 @@
     There are <strong tal:content="python:len(view.errors)"
                       i18n:name="num_errors">6</strong> input errors.
   </p>
-      
+
   <table class="listing" width="90%" cellspacing="0" cellpadding="0"
          tal:condition="view/widgets">
 
@@ -128,16 +128,18 @@
                     firstrow repeat/widget/start"
         tal:attributes="class python:oddrow and 'even' or 'odd'">
       <td class="description">
-        <b tal:content="widget/label">Option</b>
-        <div class="indent small">
-          <div tal:content="widget/hint">
-            Explanation
+        <label tal:attributes="for widget/name">
+          <b tal:content="widget/label">Option</b>
+          <div class="indent small">
+            <div tal:content="widget/hint">
+              Explanation
+            </div>
+            <div class="error" tal:define="error widget/error"
+                 tal:condition="error" tal:content="structure error">
+              The Error
+            </div>
           </div>
-          <div class="error" tal:define="error widget/error"
-            tal:condition="error" tal:content="structure error">
-            The Error
-          </div>
-        </div>
+        </label>
       </td>
       <td class="input" tal:content="structure widget">
         <input type="text" style="width:100%"/>

Copied: zope.app.preference/trunk/src/zope/app/preference/testing.py (from rev 110945, zope.app.generations/trunk/src/zope/app/generations/testing.py)
===================================================================
--- zope.app.preference/trunk/src/zope/app/preference/testing.py	                        (rev 0)
+++ zope.app.preference/trunk/src/zope/app/preference/testing.py	2010-06-11 17:11:19 UTC (rev 113357)
@@ -0,0 +1,26 @@
+##############################################################################
+#
+# Copyright (c) 2007 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.
+#
+##############################################################################
+"""zope.app.preferences common test related classes/functions/objects.
+
+$Id$
+"""
+
+__docformat__ = "reStructuredText"
+
+import os
+from zope.app.testing.functional import ZCMLLayer
+
+PreferencesLayer = ZCMLLayer(
+    os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
+    __name__, 'PreferencesLayer', allow_teardown=True)

Modified: zope.app.preference/trunk/src/zope/app/preference/tests.py
===================================================================
--- zope.app.preference/trunk/src/zope/app/preference/tests.py	2010-06-11 15:44:28 UTC (rev 113356)
+++ zope.app.preference/trunk/src/zope/app/preference/tests.py	2010-06-11 17:11:19 UTC (rev 113357)
@@ -15,22 +15,35 @@
 
 $Id$
 """
-from zope.app.testing import setup
+from zope.app.testing import setup, functional
 from zope.component import testing
 import doctest
 import unittest
+import zope.app.preference.testing
 
+
 def setUp(test):
     testing.setUp(test)
     setup.setUpTestAsModule(test, 'zope.app.preference.README')
 
+
+def ftest_setUp(test):
+    setup.setUpTestAsModule(test, 'zope.app.preference.zmi')
+
+
 def tearDown(test):
     testing.tearDown(test)
     setup.tearDownTestAsModule(test)
 
+
 def test_suite():
+    browser_tests = functional.FunctionalDocFileSuite(
+        'zmi.txt', setUp=ftest_setUp, tearDown=tearDown)
+    browser_tests.layer = zope.app.preference.testing.PreferencesLayer
+
     return unittest.TestSuite((
         doctest.DocFileSuite('README.txt',
                              setUp=setUp, tearDown=tearDown,
                              optionflags=doctest.NORMALIZE_WHITESPACE),
+        browser_tests,
         ))

Added: zope.app.preference/trunk/src/zope/app/preference/zmi.txt
===================================================================
--- zope.app.preference/trunk/src/zope/app/preference/zmi.txt	                        (rev 0)
+++ zope.app.preference/trunk/src/zope/app/preference/zmi.txt	2010-06-11 17:11:19 UTC (rev 113357)
@@ -0,0 +1,153 @@
+=======
+Browser
+=======
+
+This package also provides a user interface, so the user can edit the
+preferences.
+
+Set up
+------
+
+To show the user interface functions we need some setup beforehand:
+
+  >>> from zope.testbrowser.testing import Browser
+  >>> browser = Browser()
+
+As the preferences cannot be defined through the web we have to define
+them in python code:
+
+  >>> import zope.interface
+  >>> import zope.schema
+  >>> class IZMIUserSettings(zope.interface.Interface):
+  ...     """Basic User Preferences"""
+  ...
+  ...     email = zope.schema.TextLine(
+  ...         title=u"E-mail Address",
+  ...         description=u"E-mail Address used to send notifications")
+  ...
+  ...     skin = zope.schema.Choice(
+  ...         title=u"Skin",
+  ...         description=u"The skin that should be used for the ZMI.",
+  ...         values=['Rotterdam', 'ZopeTop', 'Basic'],
+  ...         default='Rotterdam')
+  ...
+  ...     showZopeLogo = zope.schema.Bool(
+  ...         title=u"Show Zope Logo",
+  ...         description=u"Specifies whether Zope logo should be displayed "
+  ...                     u"at the top of the screen.",
+  ...         default=True)
+
+The preference schema is usually registered using a ZCML statement:
+
+  >>> from zope.configuration import xmlconfig
+  >>> import zope.app.preference
+  >>> context = xmlconfig.file('meta.zcml', zope.app.preference)
+
+  >>> context = xmlconfig.string('''
+  ...     <configure
+  ...         xmlns="http://namespaces.zope.org/zope"
+  ...         i18n_domain="test">
+  ...
+  ...       <preferenceGroup
+  ...           id="ZMISettings"
+  ...           title="ZMI Settings"
+  ...           schema="zope.app.preference.zmi.IZMIUserSettings"
+  ...           category="true"
+  ...           />
+  ...
+  ...     </configure>''', context)
+
+Editing Preferences
+-------------------
+
+The preferences are accessable in the ``++preferences++`` namespace:
+
+  >>> browser.open('http://localhost/++preferences++')
+
+The page shows a form which allows editing the preference values:
+
+  >>> browser.getControl('E-mail').value = 'hans at example.com'
+  >>> browser.getControl('Skin').displayOptions
+  ['Rotterdam', 'ZopeTop', 'Basic']
+  >>> browser.getControl('Skin').displayValue = ['ZopeTop']
+  >>> browser.getControl('Show Zope Logo').selected
+  True
+  >>> browser.getControl('Show Zope Logo').click()
+
+After selecting `Change` the values get persisted:
+
+  >>> browser.getControl('Change').click()
+  >>> browser.url
+  'http://localhost/++preferences++/@@index.html'
+  >>> browser.getControl('E-mail').value
+  'hans at example.com'
+  >>> browser.getControl('Skin').displayValue
+  ['ZopeTop']
+  >>> browser.getControl('Show Zope Logo').selected
+  False
+
+The preference group is shown in a tree. It has a link to the form:
+
+  >>> browser.getLink('ZMISettings').click()
+  >>> browser.url
+  'http://localhost/++preferences++/ZMISettings/@@index.html'
+  >>> browser.getControl('E-mail').value
+  'hans at example.com'
+
+
+Preference Group Trees
+----------------------
+
+The preferences would not be very powerful, if you could create a full
+preferences. So let's create a sub-group for our ZMI user settings, where we
+can adjust the look and feel of the folder contents view:
+
+  >>> class IFolderSettings(zope.interface.Interface):
+  ...     """Basic Folder Settings"""
+  ...
+  ...     shownFields = zope.schema.Set(
+  ...         title=u"Shown Fields",
+  ...         description=u"Fields shown in the table.",
+  ...         value_type=zope.schema.Choice(['name', 'size', 'creator']),
+  ...         default=set(['name', 'size']))
+  ...
+  ...     sortedBy = zope.schema.Choice(
+  ...         title=u"Sorted By",
+  ...         description=u"Data field to sort by.",
+  ...         values=['name', 'size', 'creator'],
+  ...         default='name')
+
+And register it:
+
+  >>> context = xmlconfig.string('''
+  ...     <configure
+  ...         xmlns="http://namespaces.zope.org/zope"
+  ...         i18n_domain="test">
+  ...
+  ...       <preferenceGroup
+  ...           id="ZMISettings.Folder"
+  ...           title="Folder Content View Settings"
+  ...           schema="zope.app.preference.zmi.IFolderSettings"
+  ...           />
+  ...
+  ...     </configure>''', context)
+
+The sub-group is displayed inside the parent group as a form:
+
+  >>> browser.reload()
+  >>> browser.getControl('Shown Fields').displayOptions
+  ['name', 'size', 'creator']
+  >>> browser.getControl('Shown Fields').displayValue
+  ['name', 'size']
+  >>> browser.getControl('Shown Fields').displayValue = ['size', 'creator']
+  >>> browser.getControl('Sorted By').displayOptions
+  ['name', 'size', 'creator']
+  >>> browser.getControl('Sorted By').displayValue = ['creator']
+
+Selecing `Change` persists these values, too:
+
+  >>> browser.getControl('Change').click()
+  >>> browser.getControl('Shown Fields').displayValue
+  ['size', 'creator']
+  >>> browser.getControl('Sorted By').displayValue
+  ['creator']


Property changes on: zope.app.preference/trunk/src/zope/app/preference/zmi.txt
___________________________________________________________________
Added: svn:keywords
   + Id Rev Date
Added: svn:eol-style
   + native



More information about the checkins mailing list