[Checkins] SVN: z3c.preference/branches/icemac-dev/s first working draft: preferences are editable in browser
Michael Howitz
mh at gocept.com
Sat Jul 10 09:36:47 EDT 2010
Log message for revision 114520:
first working draft: preferences are editable in browser
Changed:
U z3c.preference/branches/icemac-dev/setup.py
U z3c.preference/branches/icemac-dev/src/z3c/preference/README.txt
A z3c.preference/branches/icemac-dev/src/z3c/preference/browser.py
U z3c.preference/branches/icemac-dev/src/z3c/preference/configure.zcml
U z3c.preference/branches/icemac-dev/src/z3c/preference/ftesting.zcml
A z3c.preference/branches/icemac-dev/src/z3c/preference/i18n.py
A z3c.preference/branches/icemac-dev/src/z3c/preference/interfaces.py
A z3c.preference/branches/icemac-dev/src/z3c/preference/test-layout.pt
U z3c.preference/branches/icemac-dev/src/z3c/preference/testing.py
U z3c.preference/branches/icemac-dev/src/z3c/preference/tests.py
-=-
Modified: z3c.preference/branches/icemac-dev/setup.py
===================================================================
--- z3c.preference/branches/icemac-dev/setup.py 2010-07-10 13:29:52 UTC (rev 114519)
+++ z3c.preference/branches/icemac-dev/setup.py 2010-07-10 13:36:47 UTC (rev 114520)
@@ -53,20 +53,22 @@
namespace_packages = ['z3c'],
extras_require = dict(
test = [
- # 'z3c.testing',
- 'zope.app.testing',
- # 'zope.publisher',
- 'zope.testbrowser',
- # 'zope.testing',
+ 'zope.app.wsgi >= 3.7',
+ 'zope.browserresource',
+ 'zope.login',
'zope.principalregistry',
+ 'zope.app.principalannotation',
'zope.securitypolicy',
+ 'zope.testbrowser',
+ 'zope.testing',
],
),
install_requires = [
'setuptools',
+ 'z3c.form',
+ 'z3c.formui',
+ 'z3c.pagelet',
'zope.preference',
- 'z3c.pagelet',
- 'z3c.form',
],
zip_safe = False,
)
Modified: z3c.preference/branches/icemac-dev/src/z3c/preference/README.txt
===================================================================
--- z3c.preference/branches/icemac-dev/src/z3c/preference/README.txt 2010-07-10 13:29:52 UTC (rev 114519)
+++ z3c.preference/branches/icemac-dev/src/z3c/preference/README.txt 2010-07-10 13:36:47 UTC (rev 114520)
@@ -2,7 +2,94 @@
z3c.preference
==============
->>> from zope.testbrowser.testing import Browser
+``z3c.preference`` renders forms for the preferences defined using
+``zope.preference``.
+
+
+Set up
+======
+
+At first we have to define a preference interface:
+
+ >>> import zope.interface
+ >>> import zope.schema
+ >>> class IBackEndSettings(zope.interface.Interface):
+ ... """Backend 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 back end.",
+ ... values=['Hipp', 'Lame', 'Basic'],
+ ... default='Basic')
+ ...
+ ... showLogo = zope.schema.Bool(
+ ... title=u"Show Logo",
+ ... description=u"Specifies whether the logo should be displayed.",
+ ... default=True)
+
+The interface must be registered for preferenes:
+
+ >>> from zope.configuration import xmlconfig
+ >>> import zope.preference
+ >>> context = xmlconfig.file('meta.zcml', zope.preference)
+
+ >>> context = xmlconfig.string('''
+ ... <configure
+ ... xmlns="http://namespaces.zope.org/zope"
+ ... i18n_domain="test">
+ ...
+ ... <preferenceGroup
+ ... id="BackEndSettings"
+ ... title="Back End Settings"
+ ... schema="z3c.preference.README.IBackEndSettings"
+ ... category="true"
+ ... />
+ ...
+ ... </configure>''', context)
+
+
+To access the forms a browser is needed, the user must be autorized as
+the preferences are stored in the principal annotations:
+
+>>> from zope.app.wsgi.testlayer import Browser
>>> browser = Browser()
->>> browser.handleErrors = False
->>> browser.open('http://localhost/++preferences++')
+>>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+
+
+Editing preferences
+-------------------
+
+There is a name space to access the preferences. On the page a form is
+displayed which show the default values:
+
+>>> browser.open('http://localhost/++preferences++/BackEndSettings')
+>>> browser.getControl('E-mail Address').value
+''
+>>> browser.getControl('Skin').displayValue
+['Basic']
+>>> browser.getControl('yes').selected
+True
+>>> browser.getControl('no').selected
+False
+
+The values can be changed and submitting the form makes them persistent:
+
+>>> browser.getControl('E-mail Address').value = 'me at example.com'
+>>> browser.getControl('Skin').displayValue = ['Hipp']
+>>> browser.getControl('no').click()
+>>> browser.getControl('Apply').click()
+
+After submitting the form gets displayed again and shown the changed values:
+
+>>> 'Data successfully updated.' in browser.contents
+True
+>>> browser.getControl('E-mail Address').value
+'me at example.com'
+>>> browser.getControl('Skin').displayValue
+['Hipp']
+>>> browser.getControl('no').selected
+True
Added: z3c.preference/branches/icemac-dev/src/z3c/preference/browser.py
===================================================================
--- z3c.preference/branches/icemac-dev/src/z3c/preference/browser.py (rev 0)
+++ z3c.preference/branches/icemac-dev/src/z3c/preference/browser.py 2010-07-10 13:36:47 UTC (rev 114520)
@@ -0,0 +1,32 @@
+##############################################################################
+#
+# Copyright (c) 2010 Zope Foundation 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.
+#
+#############################################################################
+
+import z3c.form.field
+import z3c.formui.form
+import zope.i18n
+import zope.security.proxy
+
+class EditForm(z3c.formui.form.EditForm):
+
+ def __init__(self, *args, **kw):
+ super(EditForm, self).__init__(*args, **kw)
+ self.label = self.context.__title__
+
+ @property
+ def fields(self):
+ schema = zope.security.proxy.getObject(self.context.__schema__)
+ if schema is None:
+ # no schema set on prefence group, so we have no fields
+ return z3c.form.field.Fields()
+ return z3c.form.field.Fields(schema)
Property changes on: z3c.preference/branches/icemac-dev/src/z3c/preference/browser.py
___________________________________________________________________
Added: svn:keywords
+ Id Rev Date
Added: svn:eol-style
+ native
Modified: z3c.preference/branches/icemac-dev/src/z3c/preference/configure.zcml
===================================================================
--- z3c.preference/branches/icemac-dev/src/z3c/preference/configure.zcml 2010-07-10 13:29:52 UTC (rev 114519)
+++ z3c.preference/branches/icemac-dev/src/z3c/preference/configure.zcml 2010-07-10 13:36:47 UTC (rev 114520)
@@ -1,6 +1,22 @@
<configure
xmlns="http://namespaces.zope.org/zope"
+ xmlns:z3c="http://namespaces.zope.org/z3c"
+ xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="z3c">
+ <permission
+ id="z3c.preference.EditPreference"
+ title="EditPreferences" />
+ <z3c:pagelet
+ for="zope.preference.interfaces.IPreferenceGroup"
+ layer=".interfaces.IPreferenceLayer"
+ name="index.html"
+ permission="z3c.preference.EditPreference"
+ class=".browser.EditForm" />
+
+ <browser:defaultView
+ layer=".interfaces.IPreferenceLayer"
+ name="index.html" />
+
</configure>
Modified: z3c.preference/branches/icemac-dev/src/z3c/preference/ftesting.zcml
===================================================================
--- z3c.preference/branches/icemac-dev/src/z3c/preference/ftesting.zcml 2010-07-10 13:29:52 UTC (rev 114519)
+++ z3c.preference/branches/icemac-dev/src/z3c/preference/ftesting.zcml 2010-07-10 13:36:47 UTC (rev 114520)
@@ -1,78 +1,80 @@
<configure
xmlns="http://namespaces.zope.org/zope"
- i18n_domain="icemac.install">
+ xmlns:browser="http://namespaces.zope.org/browser"
+ xmlns:z3c="http://namespaces.zope.org/z3c"
+ i18n_domain="z3c.preference">
- <!-- <exclude package="zope.app.authentication.browser" file="session.zcml" /> -->
- <!-- <exclude package="zope.app.authentication.browser" file="httpplugins.zcml" /> -->
- <!-- <exclude package="zope.app.authentication.browser" file="principalfolder.zcml" /> -->
- <!-- <exclude package="zope.app.authentication.browser" file="groupfolder.zcml" /> -->
- <!-- <exclude package="zope.app.authentication.browser" /> -->
- <!-- <exclude package="zc.catalog.browser" /> -->
- <!-- <exclude package="zope.dublincore.browser" /> -->
- <!-- <exclude package="zope.app.publisher.xmlrpc" /> -->
- <!-- <exclude package="z3c.form" file="file.zcml" /> -->
-
-
- <include package="zope.security" file="meta.zcml" />
+ <include package="zope.app.publication" file="meta.zcml" />
+ <include package="zope.browserpage" file="meta.zcml" />
+ <include package="zope.browserresource" file="meta.zcml" />
<include package="zope.component" file="meta.zcml" />
- <!-- <include package="zope.app.publisher.browser" file="meta.zcml" /> -->
- <include package="zope.browserpage" file="meta.zcml" />
- <include package="zope.app.pagetemplate" file="meta.zcml" />
- <include package="zope.app.publication" file="meta.zcml" />
- <include package="zope.principalregistry" file="meta.zcml" />
+ <include package="zope.principalregistry" file="meta.zcml" />
<include package="zope.publisher" file="meta.zcml" />
+ <include package="zope.security" file="meta.zcml" />
+ <include package="zope.securitypolicy" file="meta.zcml" />
+ <include package="zope.viewlet" file="meta.zcml" />
+ <include package="z3c.form" file="meta.zcml" />
+ <include package="z3c.macro" file="meta.zcml" />
+ <include package="z3c.template" file="meta.zcml" />
+ <include package="z3c.pagelet" file="meta.zcml" />
+ <include package="zope.preference" file="meta.zcml" />
+ <include package="zope.i18n" file="meta.zcml"/>
- <!-- <include package="zope.app.generations" file="subscriber.zcml" /> -->
+ <include package="zope.app.principalannotation" file="bootstrap.zcml"/>
+
+ <include package="z3c.form" />
+ <include package="z3c.formui" />
+ <include package="z3c.macro" />
+ <include package="z3c.pagelet" />
+ <include package="z3c.preference" />
+ <include package="zope.annotation" />
<include package="zope.app.appsetup" />
+ <include package="zope.app.publication" />
+ <include package="zope.component" />
+ <include package="zope.container" />
+ <include package="zope.contentprovider" />
+ <include package="zope.location" />
+ <include package="zope.login" />
+ <include package="zope.password" />
+ <include package="zope.preference" />
+ <include package="zope.principalannotation" />
+ <include package="zope.principalregistry" />
+ <include package="zope.publisher" />
<include package="zope.security" />
<include package="zope.site" />
- <include package="zope.error" />
- <!-- <include package="zope.dublincore" /> -->
- <include package="zope.publisher" />
<include package="zope.traversing" />
- <!-- <include package="zope.traversing.browser" /> -->
- <!-- <include package="zope.session" /> -->
- <!-- <include package="zope.keyreference" /> -->
- <!-- <include package="zope.intid" /> -->
- <!-- <include package="zope.catalog" /> -->
- <include package="zope.principalregistry" />
- <include package="zope.container" />
- <include package="zope.app.publication" />
- <!-- <include package="zope.i18n" /> -->
- <!-- <include package="zope.app.principalannotation" file="bootstrap.zcml"/> -->
- <include package="zope.location" />
- <include package="zope.component" />
- <!-- <include package="zope.app.authentication" /> -->
- <!-- <include package="zope.app.publisher" /> -->
- <!-- <include package="zope.authentication" /> -->
- <include package="zope.password" />
- <include package="zope.annotation" />
- <!-- own component registrations -->
- <include package="zope.securitypolicy" file="meta.zcml" />
- <!-- <include package="zope.viewlet" file="meta.zcml" /> -->
- <!-- <include package="z3c.form" file="meta.zcml" /> -->
- <!-- <include package="z3c.macro" file="meta.zcml" /> -->
- <include package="z3c.template" file="meta.zcml" />
- <include package="z3c.pagelet" file="meta.zcml" />
- <!-- <include package="zope.mimetype" file="meta.zcml" /> -->
+ <securityPolicy
+ component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
- <!-- <include package="z3c.layer.pagelet" /> -->
- <!-- <include package="z3c.form" /> -->
- <!-- <include package="z3c.formui" /> -->
- <!-- <include package="z3c.macro" /> -->
- <!-- <include package="z3c.menu.ready2go"/> -->
- <include package="z3c.pagelet" />
- <!-- <include package="z3c.table" /> -->
- <!-- <include package="zc.catalog"/> -->
- <!-- <include package="zc.sourcefactory" /> -->
- <include package="zope.contentprovider" />
- <include package="zope.securitypolicy" />
- <!-- <include package="z3c.pt" /> -->
+ <role id="zope.Manager" title="Site Manager" />
+ <grantAll role="zope.Manager" />
- <include package="zope.preference" file="meta.zcml" />
- <include package="zope.preference" />
+ <!-- Principal that tests generally run as -->
+ <principal
+ id="zope.mgr"
+ title="Manager"
+ login="mgr"
+ password="mgrpw" />
+ <grant role="zope.Manager" principal="zope.mgr" />
+
+ <!-- Test infrastructure -->
+
+ <interface
+ interface=".interfaces.IPreferenceSkin"
+ type="zope.publisher.interfaces.browser.IBrowserSkinType"
+ name="Preferences"
+ />
+
+ <browser:defaultSkin name="Preferences" />
+
+ <z3c:layout
+ for="*"
+ layer=".interfaces.IPreferenceLayer"
+ template="test-layout.pt"
+ />
+
</configure>
Added: z3c.preference/branches/icemac-dev/src/z3c/preference/i18n.py
===================================================================
--- z3c.preference/branches/icemac-dev/src/z3c/preference/i18n.py (rev 0)
+++ z3c.preference/branches/icemac-dev/src/z3c/preference/i18n.py 2010-07-10 13:36:47 UTC (rev 114520)
@@ -0,0 +1,17 @@
+##############################################################################
+#
+# Copyright (c) 2010 Zope Foundation 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.
+#
+#############################################################################
+
+import zope.i18nmessageid
+
+_ = MessageFactory = zope.i18nmessageid.MessageFactory('z3c')
Property changes on: z3c.preference/branches/icemac-dev/src/z3c/preference/i18n.py
___________________________________________________________________
Added: svn:keywords
+ Id Rev Date
Added: svn:eol-style
+ native
Added: z3c.preference/branches/icemac-dev/src/z3c/preference/interfaces.py
===================================================================
--- z3c.preference/branches/icemac-dev/src/z3c/preference/interfaces.py (rev 0)
+++ z3c.preference/branches/icemac-dev/src/z3c/preference/interfaces.py 2010-07-10 13:36:47 UTC (rev 114520)
@@ -0,0 +1,25 @@
+##############################################################################
+#
+# Copyright (c) 2010 Zope Foundation 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.
+#
+#############################################################################
+
+import z3c.form.interfaces
+import z3c.formui.interfaces
+
+
+class IPreferenceLayer(z3c.form.interfaces.IFormLayer):
+ """Layer for z3c.preference."""
+
+
+class IPreferenceSkin(z3c.formui.interfaces.IDivFormLayer,
+ IPreferenceLayer):
+ """Skin for z3c.preference."""
Property changes on: z3c.preference/branches/icemac-dev/src/z3c/preference/interfaces.py
___________________________________________________________________
Added: svn:keywords
+ Id Rev Date
Added: svn:eol-style
+ native
Added: z3c.preference/branches/icemac-dev/src/z3c/preference/test-layout.pt
===================================================================
--- z3c.preference/branches/icemac-dev/src/z3c/preference/test-layout.pt (rev 0)
+++ z3c.preference/branches/icemac-dev/src/z3c/preference/test-layout.pt 2010-07-10 13:36:47 UTC (rev 114520)
@@ -0,0 +1,10 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+ <head>
+ <title>z3c.preference</title>
+ </head>
+ <body>
+ <div tal:content="structure provider:pagelet" />
+ </body>
+</html>
Property changes on: z3c.preference/branches/icemac-dev/src/z3c/preference/test-layout.pt
___________________________________________________________________
Added: svn:keywords
+ Id Rev Date
Added: svn:eol-style
+ native
Modified: z3c.preference/branches/icemac-dev/src/z3c/preference/testing.py
===================================================================
--- z3c.preference/branches/icemac-dev/src/z3c/preference/testing.py 2010-07-10 13:29:52 UTC (rev 114519)
+++ z3c.preference/branches/icemac-dev/src/z3c/preference/testing.py 2010-07-10 13:36:47 UTC (rev 114520)
@@ -12,9 +12,7 @@
#
##############################################################################
-import os.path
-import zope.app.testing.functional
+import z3c.preference
+import zope.app.wsgi.testlayer
-Layer = zope.app.testing.functional.ZCMLLayer(
- os.path.join(os.path.split(__file__)[0], 'ftesting.zcml'),
- __name__, 'z3c.preference-layer', allow_teardown=True)
+Layer = zope.app.wsgi.testlayer.BrowserLayer(z3c.preference)
Modified: z3c.preference/branches/icemac-dev/src/z3c/preference/tests.py
===================================================================
--- z3c.preference/branches/icemac-dev/src/z3c/preference/tests.py 2010-07-10 13:29:52 UTC (rev 114519)
+++ z3c.preference/branches/icemac-dev/src/z3c/preference/tests.py 2010-07-10 13:36:47 UTC (rev 114520)
@@ -14,9 +14,20 @@
import doctest
import z3c.preference.testing
+import zope.component.testing
+import zope.testing.module
+def setUp(test):
+ zope.testing.module.setUp(test, 'z3c.preference.README')
+
+
+def tearDown(test):
+ zope.component.testing.tearDown(test)
+ zope.testing.module.tearDown(test)
+
+
def test_suite():
- suite = doctest.DocFileSuite('README.txt')
+ suite = doctest.DocFileSuite('README.txt', setUp=setUp, tearDown=tearDown)
suite.layer = z3c.preference.testing.Layer
return suite
More information about the checkins
mailing list