[Checkins] SVN: z3ext.preferences/tags/1.3.1/ tag for 1.3.1 egg
Nikolay Kim
fafhrd at datacom.kz
Wed May 7 05:37:09 EDT 2008
Log message for revision 86524:
tag for 1.3.1 egg
Changed:
A z3ext.preferences/tags/1.3.1/
D z3ext.preferences/tags/1.3.1/CHANGES.txt
A z3ext.preferences/tags/1.3.1/CHANGES.txt
D z3ext.preferences/tags/1.3.1/setup.py
A z3ext.preferences/tags/1.3.1/setup.py
D z3ext.preferences/tags/1.3.1/src/z3ext/preferences/README.txt
A z3ext.preferences/tags/1.3.1/src/z3ext/preferences/README.txt
A z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/category.pt
A z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/category.py
D z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/configure.zcml
A z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/configure.zcml
D z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/edit.pt
D z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/group.pt
A z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/group.pt
D z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/group.py
A z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/group.py
D z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/interfaces.py
A z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/interfaces.py
D z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/layout.pt
A z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/layout.pt
D z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/navigation.pt
A z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/navigation.pt
D z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/navigation.py
A z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/navigation.py
D z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/view.pt
D z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/view.py
D z3ext.preferences/tags/1.3.1/src/z3ext/preferences/zcml.py
A z3ext.preferences/tags/1.3.1/src/z3ext/preferences/zcml.py
-=-
Copied: z3ext.preferences/tags/1.3.1 (from rev 86482, z3ext.preferences/trunk)
Deleted: z3ext.preferences/tags/1.3.1/CHANGES.txt
===================================================================
--- z3ext.preferences/trunk/CHANGES.txt 2008-05-06 01:41:40 UTC (rev 86482)
+++ z3ext.preferences/tags/1.3.1/CHANGES.txt 2008-05-07 09:37:09 UTC (rev 86524)
@@ -1,68 +0,0 @@
-=======
-CHANGES
-=======
-
-1.2.1 (2008-04-22)
-------------------
-
-- Added permission checker to directive
-
-
-1.2.0 (2008-04-18)
-------------------
-
-- 'schema' field for z3ext:preferenceGroup is required now
-
-- Added adapter for IPrincipal to 'schema' with automatic binding
-
-
-1.1.1 (2008-04-15)
-------------------
-
-- Use 'z3ext.ManagePreference' as default preference permission
-
-
-1.1.0 (2008-04-11)
-------------------
-
-- Added 'for' field to z3ext:preferenceGroup directive
-
-
-1.0.2 (2008-04-07)
-------------------
-
-- Fix UI in navigation
-
-
-1.0.1 (2008-04-04)
-------------------
-
-- Fixed group category layout
-
-
-1.0.0 (2008-03-25)
-------------------
-
-- Tests added
-
-- Code moved to svn.zope.org
-
-
-0.9.2 (2008-02-29)
-------------------
-
-- Use z3c.autoinclude
-
-- Added z3c.baseregistry support
-
-
-0.9.1 (2008-02-20)
-------------------
-
-- Use z3ext.layoutform
-
-
-0.9.0 (2008-02-01)
-------------------
-
-- Initial release
Copied: z3ext.preferences/tags/1.3.1/CHANGES.txt (from rev 86523, z3ext.preferences/trunk/CHANGES.txt)
===================================================================
--- z3ext.preferences/tags/1.3.1/CHANGES.txt (rev 0)
+++ z3ext.preferences/tags/1.3.1/CHANGES.txt 2008-05-07 09:37:09 UTC (rev 86524)
@@ -0,0 +1,82 @@
+=======
+CHANGES
+=======
+
+1.3.1 (2008-05-07)
+------------------
+
+- Fix category rendering
+
+
+1.3.0 (2008-05-06)
+------------------
+
+- UI refactoring
+
+- Do not include permission checker for zope.Public permission
+
+
+1.2.1 (2008-04-22)
+------------------
+
+- Added permission checker to directive
+
+
+1.2.0 (2008-04-18)
+------------------
+
+- 'schema' field for z3ext:preferenceGroup is required now
+
+- Added adapter for IPrincipal to 'schema' with automatic binding
+
+
+1.1.1 (2008-04-15)
+------------------
+
+- Use 'z3ext.ManagePreference' as default preference permission
+
+
+1.1.0 (2008-04-11)
+------------------
+
+- Added 'for' field to z3ext:preferenceGroup directive
+
+
+1.0.2 (2008-04-07)
+------------------
+
+- Fix UI in navigation
+
+
+1.0.1 (2008-04-04)
+------------------
+
+- Fixed group category layout
+
+
+1.0.0 (2008-03-25)
+------------------
+
+- Tests added
+
+- Code moved to svn.zope.org
+
+
+0.9.2 (2008-02-29)
+------------------
+
+- Use z3c.autoinclude
+
+- Added z3c.baseregistry support
+
+
+0.9.1 (2008-02-20)
+------------------
+
+- Use z3ext.layoutform
+
+
+0.9.0 (2008-02-01)
+------------------
+
+- Initial release
Deleted: z3ext.preferences/tags/1.3.1/setup.py
===================================================================
--- z3ext.preferences/trunk/setup.py 2008-05-06 01:41:40 UTC (rev 86482)
+++ z3ext.preferences/tags/1.3.1/setup.py 2008-05-07 09:37:09 UTC (rev 86524)
@@ -1,85 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2008 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.
-#
-##############################################################################
-"""Setup for z3ext.preferences package
-
-$Id$
-"""
-import sys, os
-from setuptools import setup, find_packages
-
-def read(*rnames):
- return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-
-version='1.2.2dev'
-
-
-setup(name = 'z3ext.preferences',
- version = version,
- author = 'Nikolay Kim',
- author_email = 'fafhrd91 at gmail.com',
- description = "z3ext principal preferences",
- long_description = (
- 'Detailed Documentation\n' +
- '======================\n'
- + '\n\n' +
- read('src', 'z3ext', 'preferences', 'README.txt')
- + '\n\n' +
- read('CHANGES.txt')
- ),
- classifiers=[
- 'Development Status :: 5 - Production/Stable',
- 'Environment :: Web Environment',
- 'Intended Audience :: Developers',
- 'License :: OSI Approved :: Zope Public License',
- 'Programming Language :: Python',
- 'Natural Language :: English',
- 'Operating System :: OS Independent',
- 'Topic :: Internet :: WWW/HTTP',
- 'Framework :: Zope3'],
- url='http://z3ext.net/',
- license='ZPL 2.1',
- packages=find_packages('src'),
- package_dir = {'':'src'},
- namespace_packages=['z3ext'],
- install_requires = ['setuptools',
- 'ZODB3',
- 'zope.component',
- 'zope.interface',
- 'zope.annotation',
- 'zope.publisher',
- 'zope.configuration',
- 'zope.schema',
- 'zope.location',
- 'zope.security',
- 'zope.securitypolicy',
- 'zope.cachedescriptors',
- 'zope.pagetemplate',
- 'zope.i18nmessageid',
- 'zope.app.security',
- 'zope.app.component',
- 'zope.app.publisher',
- 'zope.app.pagetemplate',
- 'zope.app.principalannotation',
- 'z3c.traverser',
- 'z3c.autoinclude',
- 'z3ext.layout',
- 'z3ext.layoutform',
- 'z3ext.statusmessage',
- ],
- extras_require = dict(test=['zope.app.testing',
- 'zope.testing',
- ]),
- include_package_data = True,
- zip_safe = False
- )
Copied: z3ext.preferences/tags/1.3.1/setup.py (from rev 86489, z3ext.preferences/trunk/setup.py)
===================================================================
--- z3ext.preferences/tags/1.3.1/setup.py (rev 0)
+++ z3ext.preferences/tags/1.3.1/setup.py 2008-05-07 09:37:09 UTC (rev 86524)
@@ -0,0 +1,87 @@
+##############################################################################
+#
+# Copyright (c) 2008 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.
+#
+##############################################################################
+"""Setup for z3ext.preferences package
+
+$Id$
+"""
+import sys, os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+ return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+version='1.3.1'
+
+
+setup(name = 'z3ext.preferences',
+ version = version,
+ author = 'Nikolay Kim',
+ author_email = 'fafhrd91 at gmail.com',
+ description = "z3ext principal preferences",
+ long_description = (
+ 'Detailed Documentation\n' +
+ '======================\n'
+ + '\n\n' +
+ read('src', 'z3ext', 'preferences', 'README.txt')
+ + '\n\n' +
+ read('CHANGES.txt')
+ ),
+ classifiers=[
+ 'Development Status :: 5 - Production/Stable',
+ 'Environment :: Web Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Zope Public License',
+ 'Programming Language :: Python',
+ 'Natural Language :: English',
+ 'Operating System :: OS Independent',
+ 'Topic :: Internet :: WWW/HTTP',
+ 'Framework :: Zope3'],
+ url='http://z3ext.net/',
+ license='ZPL 2.1',
+ packages=find_packages('src'),
+ package_dir = {'':'src'},
+ namespace_packages=['z3ext'],
+ install_requires = ['setuptools',
+ 'ZODB3',
+ 'zope.component',
+ 'zope.interface',
+ 'zope.annotation',
+ 'zope.publisher',
+ 'zope.configuration',
+ 'zope.schema',
+ 'zope.location',
+ 'zope.security',
+ 'zope.securitypolicy',
+ 'zope.cachedescriptors',
+ 'zope.pagetemplate',
+ 'zope.i18nmessageid',
+ 'zope.viewlet',
+ 'zope.contentprovider',
+ 'zope.app.security',
+ 'zope.app.component',
+ 'zope.app.publisher',
+ 'zope.app.pagetemplate',
+ 'zope.app.principalannotation',
+ 'z3c.traverser',
+ 'z3c.autoinclude',
+ 'z3ext.layout',
+ 'z3ext.layoutform',
+ 'z3ext.statusmessage',
+ ],
+ extras_require = dict(test=['zope.app.testing',
+ 'zope.testing',
+ ]),
+ include_package_data = True,
+ zip_safe = False
+ )
Deleted: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/README.txt
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/README.txt 2008-05-06 01:41:40 UTC (rev 86482)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/README.txt 2008-05-07 09:37:09 UTC (rev 86524)
@@ -1,492 +0,0 @@
-================
-User Preferences
-================
-
-Implementing user preferences is usually a painful task, since it requires a
-lot of custom coding and constantly changing preferences makes it hard to
-maintain the data and UI. The `preference` package
-
- >>> from z3ext.preferences import interfaces, preference, preferencetype
-
-eases this pain by providing a generic user preferences framework that uses
-schemas to categorize and describe the preferences.
-
-We also have to do some additional setup beforehand:
-
- >>> from zope.app.testing import setup
-
- >>> import zope.app.component.hooks
- >>> zope.app.component.hooks.setHooks()
- >>> setup.setUpTraversal()
- >>> setup.setUpSiteManagerLookup()
-
-
-Preference Groups
-------------------
-
-Preferences are grouped in preference groups and the preferences inside a
-group are specified via the preferences group schema:
-
- >>> import zope.schema
- >>> import zope.interface
-
- >>> 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)
-
-Each preference group must have an
-ID by which it can be accessed and optional title and description fields for UI
-purposes. Before create preference group we should create unique class for
-our preferences:
-
- >>> settingsClass = preferencetype.PreferenceType(
- ... "ZMISettings",
- ... IZMIUserSettings,
- ... title=u"ZMI User Settings", description=u"")
-
-We should set 'preferenceID' to schema with preference group id,
-This value is used by data storage to store data in annotations
-
- >>> IZMIUserSettings.setTaggedValue('preferenceID', 'ZMISettings')
-
-Now we can instantiate the preference group.
-
- >>> settings = settingsClass()
-
-We can't change schema for preference group:
-
- >>> settings.__schema__ = IZMIUserSettings
- Traceback (most recent call last):
- ...
- AttributeError: Can't change __schema__
-
-
-Note that the preferences group provides the interface it is representing:
-
- >>> IZMIUserSettings.providedBy(settings)
- True
-
-and the id, schema and title of the group are directly available:
-
- >>> settings.__id__
- u'ZMISettings'
- >>> settings.__schema__
- <InterfaceClass z3ext.preferences.README.IZMIUserSettings>
- >>> settings.__title__
- u'ZMI User Settings'
-
-So let's ask the preference group for the `skin` setting:
-
- >>> settings.skin
- Traceback (most recent call last):
- ...
- UnboundPreferenceGroup
-
-
-So why did the lookup fail? Because we have not specified a principal yet, for
-which we want to lookup the preferences. To do that, we have to create a principal:
-
- >>> class Principal:
- ... def __init__(self, id):
- ... self.id = id
- >>> principal = Principal('zope.user')
-
- >>> class Participation:
- ... interaction = None
- ... def __init__(self, principal):
- ... self.principal = principal
-
- >>> participation = Participation(principal)
-
- >>> import zope.security.management
- >>> zope.security.management.newInteraction(participation)
-
-We also need an IAnnotations adapter for principals, so we can store the
-settings:
-
- >>> from zope.annotation.interfaces import IAnnotations
- >>> class PrincipalAnnotations(dict):
- ... zope.interface.implements(IAnnotations)
- ... data = {}
- ... def __new__(class_, principal):
- ... try:
- ... annotations = class_.data[principal.id]
- ... except KeyError:
- ... annotations = dict.__new__(class_)
- ... class_.data[principal.id] = annotations
- ... return annotations
- ... def __init__(self, principal):
- ... pass
-
- >>> from zope import component
- >>> component.provideAdapter(PrincipalAnnotations, (Principal,), IAnnotations)
-
-Also we need IDataStorage for preferenceGroup schema, because preference group
-doesn't use IAnnotations directly.
-
- >>> from z3ext.preferences import storage
- >>> component.provideAdapter(
- ... storage.getDefaultStorage, (Principal, zope.interface.Interface))
-
-And now we need bind preferences to principal. We can just call __bind__
-method in this case preference will use principal from current interaction.
-
- >>> nsettings = settings.__bind__()
- >>> interfaces.IBound.providedBy(nsettings)
- True
-
- >>> nsettings.__principal__ == principal
- True
-
-Or we can explicitly set principal, this is usefull when we want to know
-preferences for principal.
-
- >>> settings = settings.__bind__(principal)
- >>> interfaces.IBound.providedBy(nsettings)
- True
-
-Let's now try to access the settings again:
-
- >>> settings.skin
- 'Rotterdam'
-
-which is the default value, since we have not set it yet. We can now reassign
-the value:
-
- >>> settings.skin = 'Basic'
- >>> settings.skin
- 'Basic'
-
-However, you cannot just enter any value, since it is validated before the
-assignment:
-
- >>> settings.skin = 'MySkin'
- Traceback (most recent call last):
- ...
- ConstraintNotSatisfied: MySkin
-
-
-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:
-
- >>> import sets
- >>> class IFolderSettings(zope.interface.Interface):
- ... """Basic User Preferences"""
- ...
- ... shownFields = zope.schema.Set(
- ... title=u"Shown Fields",
- ... description=u"Fields shown in the table.",
- ... value_type=zope.schema.Choice(['name', 'size', 'creator']),
- ... default=sets.Set(['name', 'size']))
- ...
- ... sortedBy = zope.schema.Choice(
- ... title=u"Sorted By",
- ... description=u"Data field to sort by.",
- ... values=['name', 'size', 'creator'],
- ... default='name')
-
- >>> folderSettingsClass = preferencetype.PreferenceType(
- ... "ZMISettings.Folder",
- ... IFolderSettings,
- ... title=u"Folder Content View Settings")
-
- >>> IFolderSettings.setTaggedValue('preferenceID', 'ZMISettings.Folder')
-
- >>> folderSettings = folderSettingsClass()
-
-Note that the id was chosen so that the parent id is the prefix of the child's
-id. Our new preference sub-group should now be available as an attribute or an
-item on the parent group ...
-
- >>> settings['Folder']
- Traceback (most recent call last):
- ...
- KeyError: 'Folder'
-
-but not before we register the groups as utilities:
-
- >>> from zope import component
- >>> siteManager = component.getSiteManager()
-
- >>> siteManager.registerUtility(
- ... settings, interfaces.IPreferenceGroup, 'ZMISettings')
- >>> siteManager.registerUtility(
- ... folderSettings, interfaces.IPreferenceGroup, 'ZMISettings.Folder')
-
-If we now try to lookup the sub-group again, we should be successful:
-
- >>> settings['Folder']
- <z3ext.preferences.preferencetype.Preference<ZMISettings.Folder> ...>
-
-In z3ext.preferences we can't access to subfolder as attribute, this
-is one of difference from zope.app.preference.
-
- >>> settings['Folder'].sortedBy = 'size'
- >>> settings['Folder'].sortedBy
- 'size'
-
-While the registry of the preference groups is flat, the careful naming of the
-ids allows us to have a tree of preferences. Note that this pattern is very
-similar to the way modules are handled in Python; they are stored in a flat
-dictionary in ``sys.modules``, but due to the naming they appear to be in a
-namespace tree.
-
-While we are at it, there are also preference categories that can be compared
-to Python packages. They basically are just a higher level grouping concept
-that is used by the UI to better organize the preferences. A preference group
-can be converted to a category by simply providing an additional interface:
-
- >>> zope.interface.alsoProvides(settings, interfaces.IPreferenceCategory)
-
- >>> interfaces.IPreferenceCategory.providedBy(settings)
- True
-
-Clear:
-
- >>> t = siteManager.unregisterUtility(
- ... settings, interfaces.IPreferenceGroup, 'ZMISettings')
- >>> t = siteManager.unregisterUtility(
- ... folderSettings, interfaces.IPreferenceGroup, 'ZMISettings.Folder')
-
-
-Creating Preference Groups Using ZCML
--------------------------------------
-
-If you are using the user preference system in Zope 3, you will not have to
-manually setup the preference groups as we did above (of course). We will use
-ZCML instead. First, we need to register the directives:
-
- >>> from zope.configuration import xmlconfig
- >>> import z3ext.preferences
- >>> context = xmlconfig.file('meta.zcml', z3ext.preferences)
-
-Second we need root preference group:
-
- >>> from z3ext.preferences.root import PersonalPreferences
-
- >>> siteManager.registerUtility(
- ... PersonalPreferences(), interfaces.IPreferenceGroup)
-
-Then the system sets up a root preference group:
-
- >>> context = xmlconfig.string('''
- ... <configure
- ... xmlns:z3ext="http://namespaces.zope.org/z3ext" i18n_domain="test">
- ...
- ... <z3ext:preferenceGroup
- ... id="ZMISettings"
- ... schema="z3ext.preferences.README.IZMIUserSettings"
- ... title="ZMI User Settings" />
- ...
- ... <z3ext:preferenceGroup
- ... id="ZMISettings.Folder"
- ... schema="z3ext.preferences.README.IFolderSettings"
- ... title="Folder Content View Settings" />
- ...
- ... </configure>''', context)
-
-Now we can use the preference system in its intended way. We access the folder
-settings as follows:
-
- >>> prefs = component.getUtility(interfaces.IPreferenceGroup)
- >>> prefs.isAvailable()
- False
-
- >>> prefs['ZMISettings']['Folder'].isAvailable()
- False
-
-
-Don't forget to bind preferences to principal
-
- >>> prefs = prefs.__bind__(principal)
- >>> prefs.isAvailable()
- True
-
- >>> p = prefs['ZMISettings']['Folder'].__bind__(parent=prefs)
-
- >>> prefs['ZMISettings']['Folder'].isAvailable()
- True
-
- >>> prefs['ZMISettings']['Folder'].sortedBy
- 'size'
-
- >>> prefs.items()
- [(u'ZMISettings', <z3ext.preferences.preferencetype.Preference<ZMISettings> ...>)]
-
- >>> u'ZMISettings' in prefs
- True
-
- >>> prefs.keys()
- (u'ZMISettings',)
-
- >>> prefs.values()
- [<z3ext.preferences.preferencetype.Preference<ZMISettings> ...>]
-
- >>> list(iter(prefs))
- [<z3ext.preferences.preferencetype.Preference<ZMISettings> ...>]
-
- >>> len(prefs)
- 1
-
-
-Let's register the ZMI settings again under a new name via ZCML:
-
- >>> class IZMIUserSettings2(IZMIUserSettings):
- ... pass
-
- >>> IZMIUserSettings2.setTaggedValue('preferenceID', 'ZMISettings.Folder')
-
- >>> context = xmlconfig.string('''
- ... <configure
- ... xmlns:z3ext="http://namespaces.zope.org/z3ext"
- ... i18n_domain="test">
- ...
- ... <z3ext:preferenceGroup
- ... id="ZMISettings2"
- ... title="ZMI Settings NG"
- ... schema="z3ext.preferences.README.IZMIUserSettings"
- ... provides="z3ext.preferences.interfaces.IPreferenceCategory" />
- ...
- ... </configure>''', context)
-
- >>> prefs['ZMISettings2']
- <z3ext.preferences.preferencetype.Preference<ZMISettings2> ...>
-
- >>> prefs['ZMISettings2'].__title__
- u'ZMI Settings NG'
-
- >>> IZMIUserSettings.providedBy(prefs['ZMISettings2'])
- True
- >>> interfaces.IPreferenceCategory.providedBy(prefs['ZMISettings2'])
- True
-
-And the tree can built again by carefully constructing the id:
-
- >>> context = xmlconfig.string('''
- ... <configure
- ... xmlns:z3ext="http://namespaces.zope.org/z3ext"
- ... i18n_domain="test">
- ...
- ... <z3ext:preferenceGroup
- ... id="ZMISettings2.Folder"
- ... title="Folder Settings"
- ... schema="z3ext.preferences.README.IFolderSettings" />
- ...
- ... </configure>''', context)
-
- >>> prefs['ZMISettings2']
- <z3ext.preferences.preferencetype.Preference<ZMISettings2> ...>
-
- >>> prefs['ZMISettings2'].items()
- [(u'ZMISettings2.Folder', <z3ext.preferences.preferencetype.Preference<ZMISettings2.Folder> ...)]
-
- >>> list(iter(prefs['ZMISettings2']))
- [<z3ext.preferences.preferencetype.Preference<ZMISettings2.Folder> ...>]
-
- >>> prefs['ZMISettings2']['Folder'].__title__
- u'Folder Settings'
-
- >>> IFolderSettings.providedBy(prefs['ZMISettings2']['Folder'])
- True
- >>> interfaces.IPreferenceCategory.providedBy(prefs['ZMISettings2']['Folder'])
- False
-
-We can define preference group for principal type
-
- >>> class IMyPrincipal(zope.interface.Interface):
- ... pass
-
-Now let's register preference for for this type of principal
-
- >>> context = xmlconfig.string('''
- ... <configure
- ... xmlns:z3ext="http://namespaces.zope.org/z3ext"
- ... i18n_domain="test">
- ...
- ... <z3ext:preferenceGroup
- ... id="ZMISettings2.Folder10"
- ... for="z3ext.preferences.README.IMyPrincipal"
- ... title="Folder Settings"
- ... schema="z3ext.preferences.README.IFolderSettings" />
- ...
- ... </configure>''', context)
-
- >>> p = component.getUtility(interfaces.IPreferenceGroup, 'ZMISettings2.Folder10')
- >>> new_prefs = p.__bind__()
- >>> new_prefs.isAvailable()
- False
-
-Now let's mark our principal
-
- >>> zope.interface.alsoProvides(principal, IMyPrincipal)
- >>> new_prefs = p.__bind__()
- >>> new_prefs.isAvailable()
- True
-
- >>> prefs['ZMISettings2'].remove('Folder10')
-
-
-Simple Python-Level Access
---------------------------
-
-If a site is set, getting the user preferences is very simple:
-
- >>> prefs2 = IFolderSettings(principal)
-
- >>> prefs2.sortedBy
- 'name'
-
-
-Security
---------
-
-You might already wonder under which permissions the preferences are
-available. They are actually available with z3ext.ManagePreference
-permission. But sometimes we need preferences which can be changed
-only by manager. In this case we can provide default permission or
-even set security checks on attribute level, like in <class /> directive.
-
- >>> import zope.security
- >>> context = xmlconfig.file('meta.zcml', zope.security, context)
-
- >>> context = xmlconfig.string('''
- ... <configure
- ... xmlns="http://namespaces.zope.org/zope"
- ... xmlns:z3ext="http://namespaces.zope.org/z3ext"
- ... i18n_domain="z3ext">
- ...
- ... <permission id="zope.View" title="zope view" />
- ... <permission id="zope.Manage" title="zope manage" />
- ...
- ... <z3ext:preferenceGroup
- ... id="ZMISettings3"
- ... title="ZMI Settings 3"
- ... schema="z3ext.preferences.README.IZMIUserSettings"
- ... provides="z3ext.preferences.interfaces.IPreferenceCategory"
- ... permission="zope.View">
- ... <allow attributes="email" />
- ... <require
- ... attributes="showZopeLogo" permission="zope.Manage" set_attributes="skin" />
- ... </z3ext:preferenceGroup>
- ...
- ... </configure>''', context)
-
Copied: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/README.txt (from rev 86487, z3ext.preferences/trunk/src/z3ext/preferences/README.txt)
===================================================================
--- z3ext.preferences/tags/1.3.1/src/z3ext/preferences/README.txt (rev 0)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/README.txt 2008-05-07 09:37:09 UTC (rev 86524)
@@ -0,0 +1,496 @@
+================
+User Preferences
+================
+
+Implementing user preferences is usually a painful task, since it requires a
+lot of custom coding and constantly changing preferences makes it hard to
+maintain the data and UI. The `preference` package
+
+ >>> from z3ext.preferences import interfaces, preference, preferencetype
+
+eases this pain by providing a generic user preferences framework that uses
+schemas to categorize and describe the preferences.
+
+We also have to do some additional setup beforehand:
+
+ >>> from zope.app.testing import setup
+
+ >>> import zope.app.component.hooks
+ >>> zope.app.component.hooks.setHooks()
+ >>> setup.setUpTraversal()
+ >>> setup.setUpSiteManagerLookup()
+
+
+Preference Groups
+------------------
+
+Preferences are grouped in preference groups and the preferences inside a
+group are specified via the preferences group schema:
+
+ >>> import zope.schema
+ >>> import zope.interface
+
+ >>> 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)
+
+Each preference group must have an
+ID by which it can be accessed and optional title and description fields for UI
+purposes. Before create preference group we should create unique class for
+our preferences:
+
+ >>> settingsClass = preferencetype.PreferenceType(
+ ... "ZMISettings",
+ ... IZMIUserSettings,
+ ... title=u"ZMI User Settings", description=u"")
+
+We should set 'preferenceID' to schema with preference group id,
+This value is used by data storage to store data in annotations
+
+ >>> IZMIUserSettings.setTaggedValue('preferenceID', 'ZMISettings')
+
+Now we can instantiate the preference group.
+
+ >>> settings = settingsClass()
+
+We can't change schema for preference group:
+
+ >>> settings.__schema__ = IZMIUserSettings
+ Traceback (most recent call last):
+ ...
+ AttributeError: Can't change __schema__
+
+
+Note that the preferences group provides the interface it is representing:
+
+ >>> IZMIUserSettings.providedBy(settings)
+ True
+
+and the id, schema and title of the group are directly available:
+
+ >>> settings.__id__
+ u'ZMISettings'
+ >>> settings.__schema__
+ <InterfaceClass z3ext.preferences.README.IZMIUserSettings>
+ >>> settings.__title__
+ u'ZMI User Settings'
+
+So let's ask the preference group for the `skin` setting:
+
+ >>> settings.skin
+ Traceback (most recent call last):
+ ...
+ UnboundPreferenceGroup
+
+
+So why did the lookup fail? Because we have not specified a principal yet, for
+which we want to lookup the preferences. To do that, we have to create a principal:
+
+ >>> class Principal:
+ ... def __init__(self, id):
+ ... self.id = id
+ >>> principal = Principal('zope.user')
+
+ >>> class Participation:
+ ... interaction = None
+ ... def __init__(self, principal):
+ ... self.principal = principal
+
+ >>> participation = Participation(principal)
+
+ >>> import zope.security.management
+ >>> zope.security.management.newInteraction(participation)
+
+We also need an IAnnotations adapter for principals, so we can store the
+settings:
+
+ >>> from zope.annotation.interfaces import IAnnotations
+ >>> class PrincipalAnnotations(dict):
+ ... zope.interface.implements(IAnnotations)
+ ... data = {}
+ ... def __new__(class_, principal):
+ ... try:
+ ... annotations = class_.data[principal.id]
+ ... except KeyError:
+ ... annotations = dict.__new__(class_)
+ ... class_.data[principal.id] = annotations
+ ... return annotations
+ ... def __init__(self, principal):
+ ... pass
+
+ >>> from zope import component
+ >>> component.provideAdapter(PrincipalAnnotations, (Principal,), IAnnotations)
+
+Also we need IDataStorage for preferenceGroup schema, because preference group
+doesn't use IAnnotations directly.
+
+ >>> from z3ext.preferences import storage
+ >>> component.provideAdapter(
+ ... storage.getDefaultStorage, (Principal, zope.interface.Interface))
+
+And now we need bind preferences to principal. We can just call __bind__
+method in this case preference will use principal from current interaction.
+
+ >>> nsettings = settings.__bind__()
+ >>> interfaces.IBound.providedBy(nsettings)
+ True
+
+ >>> nsettings.__principal__ == principal
+ True
+
+Or we can explicitly set principal, this is usefull when we want to know
+preferences for principal.
+
+ >>> settings = settings.__bind__(principal)
+ >>> interfaces.IBound.providedBy(nsettings)
+ True
+
+Let's now try to access the settings again:
+
+ >>> settings.skin
+ 'Rotterdam'
+
+which is the default value, since we have not set it yet. We can now reassign
+the value:
+
+ >>> settings.skin = 'Basic'
+ >>> settings.skin
+ 'Basic'
+
+However, you cannot just enter any value, since it is validated before the
+assignment:
+
+ >>> settings.skin = 'MySkin'
+ Traceback (most recent call last):
+ ...
+ ConstraintNotSatisfied: MySkin
+
+
+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:
+
+ >>> import sets
+ >>> class IFolderSettings(zope.interface.Interface):
+ ... """Basic User Preferences"""
+ ...
+ ... shownFields = zope.schema.Set(
+ ... title=u"Shown Fields",
+ ... description=u"Fields shown in the table.",
+ ... value_type=zope.schema.Choice(['name', 'size', 'creator']),
+ ... default=sets.Set(['name', 'size']))
+ ...
+ ... sortedBy = zope.schema.Choice(
+ ... title=u"Sorted By",
+ ... description=u"Data field to sort by.",
+ ... values=['name', 'size', 'creator'],
+ ... default='name')
+
+ >>> folderSettingsClass = preferencetype.PreferenceType(
+ ... "ZMISettings.Folder",
+ ... IFolderSettings,
+ ... title=u"Folder Content View Settings")
+
+ >>> IFolderSettings.setTaggedValue('preferenceID', 'ZMISettings.Folder')
+
+ >>> folderSettings = folderSettingsClass()
+
+Note that the id was chosen so that the parent id is the prefix of the child's
+id. Our new preference sub-group should now be available as an attribute or an
+item on the parent group ...
+
+ >>> settings['Folder']
+ Traceback (most recent call last):
+ ...
+ KeyError: 'Folder'
+
+but not before we register the groups as utilities:
+
+ >>> from zope import component
+ >>> siteManager = component.getSiteManager()
+
+ >>> siteManager.registerUtility(
+ ... settings, interfaces.IPreferenceGroup, 'ZMISettings')
+ >>> siteManager.registerUtility(
+ ... folderSettings, interfaces.IPreferenceGroup, 'ZMISettings.Folder')
+
+If we now try to lookup the sub-group again, we should be successful:
+
+ >>> settings['Folder']
+ <z3ext.preferences.preferencetype.Preference<ZMISettings.Folder> ...>
+
+In z3ext.preferences we can't access to subfolder as attribute, this
+is one of difference from zope.app.preference.
+
+ >>> settings['Folder'].sortedBy = 'size'
+ >>> settings['Folder'].sortedBy
+ 'size'
+
+While the registry of the preference groups is flat, the careful naming of the
+ids allows us to have a tree of preferences. Note that this pattern is very
+similar to the way modules are handled in Python; they are stored in a flat
+dictionary in ``sys.modules``, but due to the naming they appear to be in a
+namespace tree.
+
+While we are at it, there are also preference categories that can be compared
+to Python packages. They basically are just a higher level grouping concept
+that is used by the UI to better organize the preferences. A preference group
+can be converted to a category by simply providing an additional interface:
+
+ >>> zope.interface.alsoProvides(settings, interfaces.IPreferenceCategory)
+
+ >>> interfaces.IPreferenceCategory.providedBy(settings)
+ True
+
+Clear:
+
+ >>> t = siteManager.unregisterUtility(
+ ... settings, interfaces.IPreferenceGroup, 'ZMISettings')
+ >>> t = siteManager.unregisterUtility(
+ ... folderSettings, interfaces.IPreferenceGroup, 'ZMISettings.Folder')
+
+
+Creating Preference Groups Using ZCML
+-------------------------------------
+
+If you are using the user preference system in Zope 3, you will not have to
+manually setup the preference groups as we did above (of course). We will use
+ZCML instead. First, we need to register the directives:
+
+ >>> from zope.configuration import xmlconfig
+ >>> import z3ext.preferences
+ >>> context = xmlconfig.file('meta.zcml', z3ext.preferences)
+
+Second we need root preference group:
+
+ >>> from z3ext.preferences.root import PersonalPreferences
+
+ >>> siteManager.registerUtility(
+ ... PersonalPreferences(), interfaces.IPreferenceGroup)
+
+Then the system sets up a root preference group:
+
+ >>> context = xmlconfig.string('''
+ ... <configure
+ ... xmlns:z3ext="http://namespaces.zope.org/z3ext" i18n_domain="test">
+ ...
+ ... <z3ext:preferenceGroup
+ ... id="ZMISettings"
+ ... schema="z3ext.preferences.README.IZMIUserSettings"
+ ... title="ZMI User Settings"
+ ... permission="zope.Public" />
+ ...
+ ... <z3ext:preferenceGroup
+ ... id="ZMISettings.Folder"
+ ... schema="z3ext.preferences.README.IFolderSettings"
+ ... title="Folder Content View Settings"
+ ... permission="zope.Public" />
+ ...
+ ... </configure>''', context)
+
+Now we can use the preference system in its intended way. We access the folder
+settings as follows:
+
+ >>> prefs = component.getUtility(interfaces.IPreferenceGroup)
+ >>> prefs.isAvailable()
+ False
+
+ >>> prefs['ZMISettings']['Folder'].isAvailable()
+ False
+
+
+Don't forget to bind preferences to principal
+
+ >>> prefs = prefs.__bind__(principal)
+ >>> prefs.isAvailable()
+ True
+
+ >>> p = prefs['ZMISettings']['Folder'].__bind__(parent=prefs)
+
+ >>> prefs['ZMISettings']['Folder'].isAvailable()
+ True
+
+ >>> prefs['ZMISettings']['Folder'].sortedBy
+ 'size'
+
+ >>> prefs.items()
+ [(u'ZMISettings', <z3ext.preferences.preferencetype.Preference<ZMISettings> ...>)]
+
+ >>> u'ZMISettings' in prefs
+ True
+
+ >>> prefs.keys()
+ (u'ZMISettings',)
+
+ >>> prefs.values()
+ [<z3ext.preferences.preferencetype.Preference<ZMISettings> ...>]
+
+ >>> list(iter(prefs))
+ [<z3ext.preferences.preferencetype.Preference<ZMISettings> ...>]
+
+ >>> len(prefs)
+ 1
+
+
+Let's register the ZMI settings again under a new name via ZCML:
+
+ >>> class IZMIUserSettings2(IZMIUserSettings):
+ ... pass
+
+ >>> IZMIUserSettings2.setTaggedValue('preferenceID', 'ZMISettings.Folder')
+
+ >>> context = xmlconfig.string('''
+ ... <configure
+ ... xmlns:z3ext="http://namespaces.zope.org/z3ext"
+ ... i18n_domain="test">
+ ...
+ ... <z3ext:preferenceGroup
+ ... id="ZMISettings2"
+ ... title="ZMI Settings NG"
+ ... schema="z3ext.preferences.README.IZMIUserSettings"
+ ... permission="zope.Public"
+ ... provides="z3ext.preferences.interfaces.IPreferenceCategory" />
+ ...
+ ... </configure>''', context)
+
+ >>> prefs['ZMISettings2']
+ <z3ext.preferences.preferencetype.Preference<ZMISettings2> ...>
+
+ >>> prefs['ZMISettings2'].__title__
+ u'ZMI Settings NG'
+
+ >>> IZMIUserSettings.providedBy(prefs['ZMISettings2'])
+ True
+ >>> interfaces.IPreferenceCategory.providedBy(prefs['ZMISettings2'])
+ True
+
+And the tree can built again by carefully constructing the id:
+
+ >>> context = xmlconfig.string('''
+ ... <configure
+ ... xmlns:z3ext="http://namespaces.zope.org/z3ext"
+ ... i18n_domain="test">
+ ...
+ ... <z3ext:preferenceGroup
+ ... id="ZMISettings2.Folder"
+ ... title="Folder Settings"
+ ... schema="z3ext.preferences.README.IFolderSettings" />
+ ...
+ ... </configure>''', context)
+
+ >>> prefs['ZMISettings2']
+ <z3ext.preferences.preferencetype.Preference<ZMISettings2> ...>
+
+ >>> prefs['ZMISettings2'].items()
+ [(u'ZMISettings2.Folder', <z3ext.preferences.preferencetype.Preference<ZMISettings2.Folder> ...)]
+
+ >>> list(iter(prefs['ZMISettings2']))
+ [<z3ext.preferences.preferencetype.Preference<ZMISettings2.Folder> ...>]
+
+ >>> prefs['ZMISettings2']['Folder'].__title__
+ u'Folder Settings'
+
+ >>> IFolderSettings.providedBy(prefs['ZMISettings2']['Folder'])
+ True
+ >>> interfaces.IPreferenceCategory.providedBy(prefs['ZMISettings2']['Folder'])
+ False
+
+We can define preference group for principal type
+
+ >>> class IMyPrincipal(zope.interface.Interface):
+ ... pass
+
+Now let's register preference for for this type of principal
+
+ >>> context = xmlconfig.string('''
+ ... <configure
+ ... xmlns:z3ext="http://namespaces.zope.org/z3ext"
+ ... i18n_domain="test">
+ ...
+ ... <z3ext:preferenceGroup
+ ... id="ZMISettings2.Folder10"
+ ... for="z3ext.preferences.README.IMyPrincipal"
+ ... title="Folder Settings"
+ ... permission="zope.Public"
+ ... schema="z3ext.preferences.README.IFolderSettings" />
+ ...
+ ... </configure>''', context)
+
+ >>> p = component.getUtility(interfaces.IPreferenceGroup, 'ZMISettings2.Folder10')
+ >>> new_prefs = p.__bind__()
+ >>> new_prefs.isAvailable()
+ False
+
+Now let's mark our principal
+
+ >>> zope.interface.alsoProvides(principal, IMyPrincipal)
+ >>> new_prefs = p.__bind__()
+ >>> new_prefs.isAvailable()
+ True
+
+ >>> prefs['ZMISettings2'].remove('Folder10')
+
+
+Simple Python-Level Access
+--------------------------
+
+If a site is set, getting the user preferences is very simple:
+
+ >>> prefs2 = IFolderSettings(principal)
+
+ >>> prefs2.sortedBy
+ 'name'
+
+
+Security
+--------
+
+You might already wonder under which permissions the preferences are
+available. They are actually available with z3ext.ManagePreference
+permission. But sometimes we need preferences which can be changed
+only by manager. In this case we can provide default permission or
+even set security checks on attribute level, like in <class /> directive.
+
+ >>> import zope.security
+ >>> context = xmlconfig.file('meta.zcml', zope.security, context)
+
+ >>> context = xmlconfig.string('''
+ ... <configure
+ ... xmlns="http://namespaces.zope.org/zope"
+ ... xmlns:z3ext="http://namespaces.zope.org/z3ext"
+ ... i18n_domain="z3ext">
+ ...
+ ... <permission id="zope.View" title="zope view" />
+ ... <permission id="zope.Manage" title="zope manage" />
+ ...
+ ... <z3ext:preferenceGroup
+ ... id="ZMISettings3"
+ ... title="ZMI Settings 3"
+ ... schema="z3ext.preferences.README.IZMIUserSettings"
+ ... provides="z3ext.preferences.interfaces.IPreferenceCategory"
+ ... permission="zope.View">
+ ... <allow attributes="email" />
+ ... <require
+ ... attributes="showZopeLogo" permission="zope.Manage" set_attributes="skin" />
+ ... </z3ext:preferenceGroup>
+ ...
+ ... </configure>''', context)
+
Copied: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/category.pt (from rev 86486, z3ext.preferences/trunk/src/z3ext/preferences/browser/category.pt)
===================================================================
--- z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/category.pt (rev 0)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/category.pt 2008-05-07 09:37:09 UTC (rev 86524)
@@ -0,0 +1,8 @@
+<tal:block tal:content="structure view/renderForm" />
+
+<div class="frame" tal:condition="view/groups">
+ <tal:block tal:repeat="group view/groups">
+ <tal:block tal:content="structure group/render" />
+ <br />
+ </tal:block>
+</div>
Copied: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/category.py (from rev 86523, z3ext.preferences/trunk/src/z3ext/preferences/browser/category.py)
===================================================================
--- z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/category.py (rev 0)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/category.py 2008-05-07 09:37:09 UTC (rev 86524)
@@ -0,0 +1,56 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+""" IPreferenceCategory view
+
+$Id$
+"""
+from zope import schema, interface
+from zope.component import getMultiAdapter
+from z3ext.layoutform import PageletEditForm
+
+from group import PreferenceGroup
+
+
+class PreferenceCategory(PreferenceGroup):
+
+ label = u''
+ description = u''
+
+ def update(self):
+ super(PreferenceCategory, self).update()
+
+ context = self.context
+ request = self.request
+
+ subgroups = []
+
+ for name, group in context.items():
+ if not group.isAvailable():
+ continue
+
+ view = getMultiAdapter((group, request), name='view.html')
+ view.update()
+
+ subgroups.append(view)
+
+ self.groups = subgroups
+
+ def renderForm(self):
+ if bool(schema.getFields(self.context.__schema__)):
+ return PageletEditForm.render(self)
+ else:
+ return u''
+
+ def render(self):
+ return self.template()
Deleted: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/configure.zcml
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/browser/configure.zcml 2008-05-06 01:41:40 UTC (rev 86482)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/configure.zcml 2008-05-07 09:37:09 UTC (rev 86524)
@@ -1,68 +0,0 @@
-<configure
- xmlns="http://namespaces.zope.org/zope"
- xmlns:zcml="http://namespaces.zope.org/zcml"
- xmlns:z3ext="http://namespaces.zope.org/z3ext"
- xmlns:browser="http://namespaces.zope.org/browser"
- i18n_domain="z3ext">
-
- <z3ext:layout
- layout="portal"
- name="workspace"
- for="..interfaces.IRootPreferences"
- template="layout.pt"
- hidden="yes" />
-
- <z3ext:layout
- layout="workspace"
- for="..interfaces.IPreferenceCategory"
- template="layoutcontent.pt"
- hidden="yes" />
-
- <!-- browser view -->
- <adapter
- name="preferences"
- provides="zope.publisher.interfaces.browser.IBrowserView"
- factory=".preferences.getPreferences" />
-
- <browser:defaultView
- name="index.html"
- for="..interfaces.IPreferenceGroup" />
-
- <browser:menuItem
- action="index.html"
- for="..interfaces.IPreferenceGroup"
- menu="zmi_views"
- title="View"
- permission="zope.Public" />
-
- <z3ext:pagelet
- for="..interfaces.IRootPreferences"
- name="index.html"
- template="index.pt"
- class=".index.PreferencesView"
- permission="zope.View" />
-
- <browser:page
- name="index.html"
- for="..interfaces.IPreferenceGroup"
- class=".group.PreferenceGroup"
- permission="zope.Public" />
-
- <browser:view
- for="..interfaces.IPreferenceGroup"
- class=".view.PreferenceGroupView"
- provides=".interfaces.IPreferenceGroupView"
- permission="zope.Public" />
-
- <adapter
- zcml:condition="installed z3c.breadcrumb"
- factory=".breadcrumb.PreferenceGroupBreadcrumb" />
-
- <browser:page
- name="navigation"
- for="..interfaces.IPreferenceGroup"
- template="navigation.pt"
- class=".navigation.Navigation"
- permission="zope.Public" />
-
-</configure>
Copied: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/configure.zcml (from rev 86486, z3ext.preferences/trunk/src/z3ext/preferences/browser/configure.zcml)
===================================================================
--- z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/configure.zcml (rev 0)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/configure.zcml 2008-05-07 09:37:09 UTC (rev 86524)
@@ -0,0 +1,82 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:zcml="http://namespaces.zope.org/zcml"
+ xmlns:z3ext="http://namespaces.zope.org/z3ext"
+ xmlns:browser="http://namespaces.zope.org/browser"
+ i18n_domain="z3ext">
+
+ <!-- layouts -->
+ <z3ext:layout
+ layout="portal"
+ name="workspace"
+ for="..interfaces.IRootPreferences"
+ template="layout.pt"
+ hidden="yes" />
+
+ <z3ext:layout
+ layout="workspace"
+ for="..interfaces.IPreferenceCategory"
+ template="layoutcontent.pt"
+ hidden="yes" />
+
+ <!-- browser view -->
+ <adapter
+ name="preferences"
+ provides="zope.publisher.interfaces.browser.IBrowserView"
+ factory=".preferences.getPreferences" />
+
+ <browser:defaultView
+ name="index.html"
+ for="..interfaces.IPreferenceGroup" />
+
+ <browser:menuItem
+ action="index.html"
+ for="..interfaces.IPreferenceGroup"
+ menu="zmi_views"
+ title="View"
+ permission="zope.Public" />
+
+ <!-- root preferences view -->
+ <z3ext:pagelet
+ for="..interfaces.IRootPreferences"
+ name="index.html"
+ template="index.pt"
+ class=".index.PreferencesView"
+ permission="zope.View" />
+
+ <!-- preference category view -->
+ <z3ext:pagelet
+ name="index.html"
+ for="..interfaces.IPreferenceCategory"
+ template="category.pt"
+ class=".category.PreferenceCategory"
+ permission="zope.Public" />
+
+ <!-- preference group view -->
+ <z3ext:pagelet
+ name="index.html"
+ for="..interfaces.IPreferenceGroup"
+ class=".group.PreferenceGroup"
+ permission="zope.Public" />
+
+ <z3ext:pagelet
+ name="view.html"
+ for="..interfaces.IPreferenceGroup"
+ template="group.pt"
+ permission="zope.Public" />
+
+ <!-- navigation -->
+ <browser:viewletManager
+ name="z3ext.preferences-navigation"
+ provides=".interfaces.IPreferencesNavigation"
+ for="..interfaces.IPreferenceGroup"
+ template="navigation.pt"
+ class=".navigation.Navigation"
+ permission="zope.Public" />
+
+ <!-- breadcrumb -->
+ <adapter
+ zcml:condition="installed z3c.breadcrumb"
+ factory=".breadcrumb.PreferenceGroupBreadcrumb" />
+
+</configure>
Deleted: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/edit.pt
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/browser/edit.pt 2008-05-06 01:41:40 UTC (rev 86482)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/edit.pt 2008-05-07 09:37:09 UTC (rev 86524)
@@ -1,13 +0,0 @@
-<div class="frame">
- <h1 tal:content="view/label|nothing">Do something</h1>
- <div class="discreet" tal:content="view/description|nothing"></div>
- <br />
-
- <div class="z-form-fieldset">
- <div>
- <tal:block tal:repeat="widget view/widgets/values">
- <metal:block use-macro="macro:widget-row"/>
- </tal:block>
- </div>
- </div>
-</div>
Deleted: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/group.pt
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/browser/group.pt 2008-05-06 01:41:40 UTC (rev 86482)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/group.pt 2008-05-07 09:37:09 UTC (rev 86524)
@@ -1,34 +0,0 @@
-<form action="." metal:define-macro="master" i18n:domain="z3ext"
- tal:attributes="action request/URL" method="post"
- tal:omit-tag="view/subform"
- class="edit-form" enctype="multipart/form-data">
-
- <tal:block tal:content="structure view/form_result" />
-
- <div class="frame" tal:condition="view/editable" tal:omit-tag="not:view/category">
- <tal:block repeat="group view/subgroups">
- <div tal:condition="nocall:group/view"
- tal:content="structure python:group['view'].render(True)"></div>
- <br />
- </tal:block>
- </div>
-
- <div class="topframe" tal:condition="not:view/editable">
- <tal:block repeat="group view/subgroups">
- <div tal:condition="nocall:group/view"
- tal:content="structure group/view/render"></div>
- <br />
- </tal:block>
- </div>
-
- <div class="formControls"
- tal:condition="python:view.editable and not view.subform">
- <hr />
- <span class="actionButtons">
- <input type="submit"
- id="form-buttons-save" name="form.buttons.save"
- class="z-form-savebutton button-field" value="Save"
- i18n:attributes="value" />
- </span>
- </div>
-</form>
Copied: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/group.pt (from rev 86486, z3ext.preferences/trunk/src/z3ext/preferences/browser/group.pt)
===================================================================
--- z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/group.pt (rev 0)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/group.pt 2008-05-07 09:37:09 UTC (rev 86524)
@@ -0,0 +1,3 @@
+<h2><a tal:attributes="href string:${context/@@absolute_url}/"
+ tal:content="context/__title__"></a></h2>
+<div class="discreet" tal:content="context/__description__"></div>
Deleted: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/group.py
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/browser/group.py 2008-05-06 01:41:40 UTC (rev 86482)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/group.py 2008-05-07 09:37:09 UTC (rev 86524)
@@ -1,108 +0,0 @@
-##############################################################################
-#
-# 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.
-#
-##############################################################################
-""" IPreferenceGroup view
-
-$Id$
-"""
-from zope import event, schema, interface
-from zope.component import getMultiAdapter, queryMultiAdapter
-from zope.cachedescriptors.property import Lazy
-from zope.app.pagetemplate import ViewPageTemplateFile
-from zope.pagetemplate.interfaces import IPageTemplate
-
-from z3ext.layoutform import Fields, PageletEditForm
-from z3ext.preferences.interfaces import IPreferenceCategory
-
-from interfaces import IPreferenceGroupView
-
-
-class PreferenceGroup(PageletEditForm):
-
- edit = None
- editable = False
-
- group = ViewPageTemplateFile('group.pt')
- template = ViewPageTemplateFile('edit.pt')
-
- category = False
-
- @property
- def label(self):
- return self.context.__title__
-
- @property
- def description(self):
- return self.context.__description__
-
- @Lazy
- def fields(self):
- return Fields(self.context.__schema__)
-
- def update(self):
- context = self.context
- request = self.request
-
- self.hasFields = bool(schema.getFields(context.__schema__))
- if self.hasFields:
- super(PreferenceGroup, self).update()
-
- if IPreferenceCategory.providedBy(context):
- subgroups = []
-
- for name, group in context.items():
- if not group.isAvailable():
- continue
-
- view = queryMultiAdapter((group, request), IPreferenceGroupView)
- subgroups.append((group.__title__, group, view))
-
- self.subgroups = [{'group': group, 'view': view}
- for t, group, view in subgroups]
-
- self.category = True
- else:
- subgroups = []
- for name, group in context.items():
- if not group.isAvailable():
- continue
-
- view = queryMultiAdapter((group, request), name='index.html')
- if not view:
- continue
-
- view.update()
- subgroups.append((group.__title__, group, view))
-
- self.subgroups = [{'group': group, 'view': view}
- for t, group, view in subgroups]
-
- if subgroups:
- self.editable = True
-
-
- form_result = u''
-
- def render(self, subform=False):
- self.subform = subform
-
- if self.hasFields:
- self.editable = True
- if self.template is None:
- template = getMultiAdapter(
- (self, self.request), IPageTemplate)
- self.form_result = template(self)
- else:
- self.form_result = self.template()
-
- return self.group()
Copied: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/group.py (from rev 86490, z3ext.preferences/trunk/src/z3ext/preferences/browser/group.py)
===================================================================
--- z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/group.py (rev 0)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/group.py 2008-05-07 09:37:09 UTC (rev 86524)
@@ -0,0 +1,69 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+""" IPreferenceGroup view
+
+$Id$
+"""
+from zope import schema
+from zope.component import getMultiAdapter
+from zope.cachedescriptors.property import Lazy
+from z3ext.layoutform import Fields, PageletEditForm
+
+
+class PreferenceGroup(PageletEditForm):
+
+ @property
+ def prefix(self):
+ return str(self.context.__id__)
+
+ @property
+ def label(self):
+ return self.context.__title__
+
+ @property
+ def description(self):
+ return self.context.__description__
+
+ @Lazy
+ def fields(self):
+ return Fields(self.context.__schema__, omitReadOnly=True)
+
+ def update(self):
+ super(PreferenceGroup, self).update()
+
+ context = self.context
+ request = self.request
+
+ subgroups = []
+
+ for name, group in context.items():
+ if not group.isAvailable():
+ continue
+
+ view = getMultiAdapter((group, request), name='index.html')
+ view.update()
+
+ subgroups.append(view)
+
+ self.groups = subgroups
+
+ def render(self):
+ result = []
+
+ if bool(schema.getFields(self.context.__schema__)):
+ result.append(super(PreferenceGroup, self).render())
+
+ result.extend([group.render() for group in self.groups])
+
+ return u'<br />\n'.join(result)
Deleted: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/interfaces.py
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/browser/interfaces.py 2008-05-06 01:41:40 UTC (rev 86482)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/interfaces.py 2008-05-07 09:37:09 UTC (rev 86524)
@@ -1,40 +0,0 @@
-##############################################################################
-#
-# 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.
-#
-##############################################################################
-""" interfaces relateds to view preference groups
-
-$Id$
-"""
-from zope import interface
-
-
-class IPreferences(interface.Interface):
- """ preferences """
-
-
-class IPreferenceGroupView(interface.Interface):
- """ group view """
-
- def isAvailable():
- """ is this view available """
-
- def render():
- """ render view """
-
-
-class IPreferenceGroupPreview(IPreferenceGroupView):
- """ group preview """
-
-
-class IDefaultPreferenceGroupView(interface.Interface):
- """ default preference view """
Copied: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/interfaces.py (from rev 86486, z3ext.preferences/trunk/src/z3ext/preferences/browser/interfaces.py)
===================================================================
--- z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/interfaces.py (rev 0)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/interfaces.py 2008-05-07 09:37:09 UTC (rev 86524)
@@ -0,0 +1,22 @@
+##############################################################################
+#
+# Copyright (c) 2008 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+from zope.viewlet.interfaces import IViewletManager
+
+
+class IPreferencesNavigation(IViewletManager):
+ """ preferences navigation viewlet manager """
Deleted: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/layout.pt
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/browser/layout.pt 2008-05-06 01:41:40 UTC (rev 86482)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/layout.pt 2008-05-07 09:37:09 UTC (rev 86524)
@@ -1,12 +0,0 @@
-<div id="z-portal-workspace">
- <div class="page"
- tal:define="nav maincontext/@@navigation|nothing; rendered view/render; noNav not:nav">
- <table class="wide" tal:omit-tag="noNav">
- <tr style="vertical-align: top" tal:omit-tag="noNav">
- <td style="padding-right: 1em; width: 200px"
- tal:condition="nav" tal:content="structure nav"></td>
- <td tal:omit-tag="noNav" tal:content="structure rendered"></td>
- </tr>
- </table>
- </div>
-</div>
Copied: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/layout.pt (from rev 86486, z3ext.preferences/trunk/src/z3ext/preferences/browser/layout.pt)
===================================================================
--- z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/layout.pt (rev 0)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/layout.pt 2008-05-07 09:37:09 UTC (rev 86524)
@@ -0,0 +1,15 @@
+<div id="z-portal-workspace"
+ tal:define="context nocall:maincontext;
+ nav provider:z3ext.preferences-navigation;
+ noNav not:nav;
+ rendered view/render">
+ <div class="page">
+ <table class="wide" tal:omit-tag="noNav">
+ <tr style="vertical-align: top" tal:omit-tag="noNav">
+ <td style="padding-right: 1em; width: 200px"
+ tal:condition="nav" tal:content="structure nav"></td>
+ <td tal:omit-tag="noNav" tal:content="structure rendered"></td>
+ </tr>
+ </table>
+ </div>
+</div>
Deleted: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/navigation.pt
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/browser/navigation.pt 2008-05-06 01:41:40 UTC (rev 86482)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/navigation.pt 2008-05-07 09:37:09 UTC (rev 86524)
@@ -1,20 +0,0 @@
-<div class="x-listing box small">
- <tal:block tal:repeat="item view/data">
- <metal:block metal:define-macro="level">
- <div class="x-listing-item"
- tal:attributes="class python:item['selected'] and 'x-listing-item-selected'
- or 'x-listing-item'">
- <div tal:omit-tag="not:item/level|nothing"
- tal:attributes="class string:level${item/level|nothing}">
- <a tal:attributes="href string:${item/prefs/@@absolute_url}/">
- <al:block tal:content="structure item/icon" />
- <tal:block tal:content="item/title" />
- </a>
- </div>
- </div>
- <tal:block tal:repeat="item item/items">
- <metal:block use-macro="view/index/macros/level"/>
- </tal:block>
- </metal:block>
- </tal:block>
-</div>
Copied: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/navigation.pt (from rev 86486, z3ext.preferences/trunk/src/z3ext/preferences/browser/navigation.pt)
===================================================================
--- z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/navigation.pt (rev 0)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/navigation.pt 2008-05-07 09:37:09 UTC (rev 86524)
@@ -0,0 +1,23 @@
+<tal:block tal:repeat="viewlet view/viewlets"
+ tal:content="structure viewlet/render" />
+
+<div class="x-listing box small">
+ <tal:block tal:repeat="item view/data">
+ <metal:block metal:define-macro="level">
+ <div class="x-listing-item"
+ tal:attributes="class python:item['selected'] and 'x-listing-item-selected'
+ or 'x-listing-item'">
+ <div tal:omit-tag="not:item/level|nothing"
+ tal:attributes="class string:level${item/level|nothing}">
+ <a tal:attributes="href string:${item/prefs/@@absolute_url}/">
+ <al:block tal:content="structure item/icon" />
+ <tal:block tal:content="item/title" />
+ </a>
+ </div>
+ </div>
+ <tal:block tal:repeat="item item/items">
+ <metal:block use-macro="view/template/macros/level"/>
+ </tal:block>
+ </metal:block>
+ </tal:block>
+</div>
Deleted: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/navigation.py
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/browser/navigation.py 2008-05-06 01:41:40 UTC (rev 86482)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/navigation.py 2008-05-07 09:37:09 UTC (rev 86524)
@@ -1,85 +0,0 @@
-##############################################################################
-#
-# 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.
-#
-##############################################################################
-"""
-
-$Id$
-"""
-from zope.component import queryMultiAdapter
-from z3ext.preferences.interfaces import IRootPreferences
-from z3ext.preferences.interfaces import IPreferenceGroup
-from z3ext.preferences.interfaces import IPreferenceCategory
-
-
-class Navigation(object):
-
- def __init__(self, context, request):
- self.context = context
- self.request = request
-
- self.isRoot = IRootPreferences.providedBy(context)
- if self.isRoot:
- return
-
- path = []
- parent = context
- while IPreferenceGroup.providedBy(parent):
- path.insert(0, parent)
- parent = parent.__parent__
-
- self.root, path = path[0], path[1:]
-
- self.data = self._process(self.root, path)
-
- def _process(self, context, path, level=1):
- request = self.request
-
- if path:
- data = []
- items = getattr(context, 'items', ())
- if callable(items):
- items = items()
-
- for name, prefs in items:
- if not prefs.isAvailable():
- continue
-
- info = {'name': name,
- 'title': prefs.__title__,
- 'icon': queryMultiAdapter(
- (prefs, request), name='zmi_icon'),
- 'items': (),
- 'selected': False,
- 'prefs': prefs,
- 'level': level}
-
- if prefs.__id__ == path[0].__id__:
- info['items'] = self._process(prefs, path[1:], level+1)
-
- if prefs.__id__ == self.context.__id__:
- info['selected'] = True
- info['items'] = self._process(prefs, [prefs], level+1)
-
- if IPreferenceCategory.providedBy(prefs) and not info['items']:
- if not self._process(prefs, [prefs], level+1):
- continue
-
- data.append(info)
-
- return data
-
- def __call__(self):
- if self.isRoot:
- return ''
- else:
- return self.index()
Copied: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/navigation.py (from rev 86486, z3ext.preferences/trunk/src/z3ext/preferences/browser/navigation.py)
===================================================================
--- z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/navigation.py (rev 0)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/navigation.py 2008-05-07 09:37:09 UTC (rev 86524)
@@ -0,0 +1,88 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+from zope.component import queryMultiAdapter
+from zope.viewlet.manager import ViewletManagerBase
+from z3ext.preferences.interfaces import IRootPreferences
+from z3ext.preferences.interfaces import IPreferenceGroup
+from z3ext.preferences.interfaces import IPreferenceCategory
+
+
+class Navigation(ViewletManagerBase):
+
+ def update(self):
+ super(Navigation, self).update()
+
+ context = self.context
+
+ self.isRoot = IRootPreferences.providedBy(context)
+ if self.isRoot:
+ return
+
+ path = []
+ parent = context
+ while IPreferenceGroup.providedBy(parent):
+ path.insert(0, parent)
+ parent = parent.__parent__
+
+ self.root, path = path[0], path[1:]
+
+ self.data = self._process(self.root, path)
+
+ def _process(self, context, path, level=1):
+ request = self.request
+
+ if path:
+ data = []
+ items = getattr(context, 'items', ())
+ if callable(items):
+ items = items()
+
+ for name, prefs in items:
+ if not prefs.isAvailable():
+ continue
+
+ info = {'name': name,
+ 'title': prefs.__title__,
+ 'icon': queryMultiAdapter(
+ (prefs, request), name='zmi_icon'),
+ 'items': (),
+ 'selected': False,
+ 'prefs': prefs,
+ 'level': level}
+
+ if prefs.__id__ == path[0].__id__:
+ info['items'] = self._process(prefs, path[1:], level+1)
+
+ if prefs.__id__ == self.context.__id__:
+ info['selected'] = True
+ info['items'] = self._process(prefs, [prefs], level+1)
+
+ if IPreferenceCategory.providedBy(prefs) and not info['items']:
+ if not self._process(prefs, [prefs], level+1):
+ continue
+
+ data.append(info)
+
+ return data
+
+ def render(self):
+ if self.isRoot:
+ return u''
+ else:
+ return super(Navigation, self).render()
+
Deleted: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/view.pt
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/browser/view.pt 2008-05-06 01:41:40 UTC (rev 86482)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/view.pt 2008-05-07 09:37:09 UTC (rev 86524)
@@ -1,3 +0,0 @@
-<h2><a tal:attributes="href string:${context/@@absolute_url}/"
- tal:content="context/__title__"></a></h2>
-<div class="discreet" tal:content="context/__description__"></div>
Deleted: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/view.py
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/browser/view.py 2008-05-06 01:41:40 UTC (rev 86482)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/browser/view.py 2008-05-07 09:37:09 UTC (rev 86524)
@@ -1,27 +0,0 @@
-##############################################################################
-#
-# 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.
-#
-##############################################################################
-"""
-
-$Id$
-"""
-from zope import interface
-from zope.app.pagetemplate import ViewPageTemplateFile
-
-from interfaces import IDefaultPreferenceGroupView
-
-
-class PreferenceGroupView(object):
- interface.implements(IDefaultPreferenceGroupView)
-
- render = ViewPageTemplateFile('view.pt')
Deleted: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/zcml.py
===================================================================
--- z3ext.preferences/trunk/src/z3ext/preferences/zcml.py 2008-05-06 01:41:40 UTC (rev 86482)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/zcml.py 2008-05-07 09:37:09 UTC (rev 86524)
@@ -1,258 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2008 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.
-#
-##############################################################################
-""" z3ext:preferenceGroup directive implementation
-
-$Id$
-"""
-from zope import interface
-from zope.schema import Int
-from zope.component import getUtility, queryUtility, getGlobalSiteManager
-from zope.schema.interfaces import IField
-from zope.location.interfaces import ILocation
-
-from zope.security.zcml import Permission
-from zope.security.checker import Checker, CheckerPublic
-from zope.security.interfaces import IPrincipal
-
-from zope.interface.common.mapping import IEnumerableMapping
-
-from zope.component.zcml import utility, adapter
-from zope.component.interface import provideInterface
-
-from zope.configuration import fields
-from zope.configuration.exceptions import ConfigurationError
-
-from zope.app.security.protectclass import \
- protectName, protectSetAttribute, protectLikeUnto
-
-from interfaces import IPreferenceGroup
-from preference import PreferenceGroup
-from preferencetype import PreferenceType
-from utils import PrincipalChecker, PermissionChecker
-
-
-class IPreferenceGroupDirective(interface.Interface):
- """Register a preference group."""
-
- id = fields.PythonIdentifier(
- title=u"Id",
- description=u"""
- Id of the preference group used to access the group. The id should
- be a valid path in the preferences tree.""",
- required=True)
-
- for_ = fields.GlobalInterface(
- title=u"For",
- description=u"Principal interface to use this preference for.",
- required=False)
-
- schema = fields.GlobalInterface(
- title=u"Schema",
- description=u"Schema of the preference group used defining the "
- u"preferences of the group.",
- required=True)
-
- title = fields.MessageID(
- title=u"Title",
- description=u"Title of the preference group used in UIs.",
- required=True)
-
- description = fields.MessageID(
- title=u"Description",
- description=u"Description of the preference group used in UIs.",
- required=False)
-
- class_ = fields.GlobalObject(
- title=u"Class",
- description=u"Custom IPreferenceGroup implementation.",
- required=False)
-
- provides = fields.Tokens(
- title = u'Provides',
- required = False,
- value_type = fields.GlobalInterface())
-
- permission = Permission(
- title = u'Permission',
- description = u'Default access permission.',
- required = False)
-
- tests = fields.Tokens(
- title = u"Tests",
- description = u'Tests for check availability.',
- value_type = fields.GlobalObject(),
- required = False)
-
- order = Int(
- title = u'Order',
- default = 999999,
- required = False)
-
-
-class PreferenceGroupAdapter(object):
-
- def __init__(self, name):
- self.name = name
-
- def __call__(self, principal, context=None):
- prefs = getUtility(IPreferenceGroup, self.name)
- return prefs.__bind__(principal, context)
-
-
-class PreferenceGroupDirective(object):
-
- def __init__(self, _context, id, schema, title,
- for_=None, description=u'', class_=None, provides=[],
- permission='z3ext.ModifyPreference', tests=(), order = 9999):
-
- Class = PreferenceType(str(id), schema, class_, title, description)
- Class.order = order
-
- if interface.interfaces.IInterface.providedBy(for_):
- tests = tests + (PrincipalChecker(for_),)
-
- tests = tuple(tests) + (PermissionChecker(permission),)
-
- group = Class(tests)
-
- utility(_context, IPreferenceGroup, group, name=id)
- adapter(_context, (PreferenceGroupAdapter(id),), schema,
- (for_ or IPrincipal,))
- adapter(_context, (PreferenceGroupAdapter(id),), schema,
- (for_ or IPrincipal, interface.Interface))
-
- interface.classImplements(Class, *provides)
-
- self._class = Class
- self._context = _context
- self._permission = permission
-
- self.require(_context, permission,
- interface=(IPreferenceGroup, schema), set_schema=(schema,))
- self.require(_context, CheckerPublic,
- interface=(IEnumerableMapping, ILocation),
- attributes=('isAvailable',
- '__id__', '__schema__',
- '__title__', '__description__'))
-
- schema.setTaggedValue('preferenceID', id)
-
- _context.action(
- discriminator=('z3ext:preferences', schema),
- callable=addSubgroup, args=(group,))
-
- def require(self, _context,
- permission=None, attributes=None, interface=None,
- like_class=None, set_attributes=None, set_schema=None):
- """Require a permission to access a specific aspect"""
- if like_class:
- self.__mimic(_context, like_class)
-
- if not (interface or attributes or set_attributes or set_schema):
- if like_class:
- return
- raise ConfigurationError("Nothing required")
-
- if not permission:
- raise ConfigurationError("No permission specified")
-
- if interface:
- for i in interface:
- if i:
- self.__protectByInterface(i, permission)
-
- if attributes:
- self.__protectNames(attributes, permission)
-
- if set_attributes:
- self.__protectSetAttributes(set_attributes, permission)
-
- if set_schema:
- for s in set_schema:
- self.__protectSetSchema(s, permission)
-
- def __mimic(self, _context, class_):
- """Base security requirements on those of the given class"""
- _context.action(
- discriminator=('z3ext:preferences:mimic', self._class),
- callable=protectLikeUnto,
- args=(self._class, class_),
- )
-
- def allow(self, _context, attributes=None, interface=None):
- """Like require, but with permission_id zope.Public"""
- return self.require(_context, self._permission, attributes, interface)
-
- def __protectByInterface(self, interface, permission_id):
- "Set a permission on names in an interface."
- for n, d in interface.namesAndDescriptions(1):
- self.__protectName(n, permission_id)
-
- self._context.action(
- discriminator = None,
- callable = provideInterface,
- args = (interface.__module__+'.'+interface.getName(), interface))
-
- def __protectName(self, name, permission_id):
- "Set a permission on a particular name."
- self._context.action(
- discriminator = ('z3ext:preferences:protectName', object()),
- callable = protectName,
- args = (self._class, name, permission_id))
-
- def __protectNames(self, names, permission_id):
- "Set a permission on a bunch of names."
- for name in names:
- self.__protectName(name, permission_id)
-
- def __protectSetAttributes(self, names, permission_id):
- "Set a permission on a bunch of names."
- for name in names:
- self._context.action(
- discriminator = (
- 'z3ext:preferences:protectSetAttribute', object()),
- callable = protectSetAttribute,
- args = (self._class, name, permission_id))
-
- def __protectSetSchema(self, schema, permission_id):
- "Set a permission on a bunch of names."
- _context = self._context
-
- for name in schema:
- field = schema[name]
- if IField.providedBy(field) and not field.readonly:
- _context.action(
- discriminator = (
- 'z3ext:preferences:protectSetAttribute', object()),
- callable = protectSetAttribute,
- args = (self._class, name, permission_id))
-
- _context.action(
- discriminator = None,
- callable = provideInterface,
- args = (schema.__module__+'.'+schema.getName(), schema))
-
-
-def addSubgroup(group):
- if '.' in group.__id__:
- parentId = group.__id__.split('.')[0]
- else:
- parentId = ''
-
- parent = queryUtility(IPreferenceGroup, parentId)
- if parent is None:
- parent = getGlobalSiteManager().getUtility(IPreferenceGroup, parentId)
-
- parent.add(group.__name__)
- group.__parent__ = parent
Copied: z3ext.preferences/tags/1.3.1/src/z3ext/preferences/zcml.py (from rev 86483, z3ext.preferences/trunk/src/z3ext/preferences/zcml.py)
===================================================================
--- z3ext.preferences/tags/1.3.1/src/z3ext/preferences/zcml.py (rev 0)
+++ z3ext.preferences/tags/1.3.1/src/z3ext/preferences/zcml.py 2008-05-07 09:37:09 UTC (rev 86524)
@@ -0,0 +1,259 @@
+##############################################################################
+#
+# Copyright (c) 2008 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.
+#
+##############################################################################
+""" z3ext:preferenceGroup directive implementation
+
+$Id$
+"""
+from zope import interface
+from zope.schema import Int
+from zope.component import getUtility, queryUtility, getGlobalSiteManager
+from zope.schema.interfaces import IField
+from zope.location.interfaces import ILocation
+
+from zope.security.zcml import Permission
+from zope.security.checker import Checker, CheckerPublic
+from zope.security.interfaces import IPrincipal
+
+from zope.interface.common.mapping import IEnumerableMapping
+
+from zope.component.zcml import utility, adapter
+from zope.component.interface import provideInterface
+
+from zope.configuration import fields
+from zope.configuration.exceptions import ConfigurationError
+
+from zope.app.security.protectclass import \
+ protectName, protectSetAttribute, protectLikeUnto
+
+from interfaces import IPreferenceGroup
+from preference import PreferenceGroup
+from preferencetype import PreferenceType
+from utils import PrincipalChecker, PermissionChecker
+
+
+class IPreferenceGroupDirective(interface.Interface):
+ """Register a preference group."""
+
+ id = fields.PythonIdentifier(
+ title=u"Id",
+ description=u"""
+ Id of the preference group used to access the group. The id should
+ be a valid path in the preferences tree.""",
+ required=True)
+
+ for_ = fields.GlobalInterface(
+ title=u"For",
+ description=u"Principal interface to use this preference for.",
+ required=False)
+
+ schema = fields.GlobalInterface(
+ title=u"Schema",
+ description=u"Schema of the preference group used defining the "
+ u"preferences of the group.",
+ required=True)
+
+ title = fields.MessageID(
+ title=u"Title",
+ description=u"Title of the preference group used in UIs.",
+ required=True)
+
+ description = fields.MessageID(
+ title=u"Description",
+ description=u"Description of the preference group used in UIs.",
+ required=False)
+
+ class_ = fields.GlobalObject(
+ title=u"Class",
+ description=u"Custom IPreferenceGroup implementation.",
+ required=False)
+
+ provides = fields.Tokens(
+ title = u'Provides',
+ required = False,
+ value_type = fields.GlobalInterface())
+
+ permission = Permission(
+ title = u'Permission',
+ description = u'Default access permission.',
+ required = False)
+
+ tests = fields.Tokens(
+ title = u"Tests",
+ description = u'Tests for check availability.',
+ value_type = fields.GlobalObject(),
+ required = False)
+
+ order = Int(
+ title = u'Order',
+ default = 999999,
+ required = False)
+
+
+class PreferenceGroupAdapter(object):
+
+ def __init__(self, name):
+ self.name = name
+
+ def __call__(self, principal, context=None):
+ prefs = getUtility(IPreferenceGroup, self.name)
+ return prefs.__bind__(principal, context)
+
+
+class PreferenceGroupDirective(object):
+
+ def __init__(self, _context, id, schema, title,
+ for_=None, description=u'', class_=None, provides=[],
+ permission='z3ext.ModifyPreference', tests=(), order = 9999):
+
+ Class = PreferenceType(str(id), schema, class_, title, description)
+ Class.order = order
+
+ if interface.interfaces.IInterface.providedBy(for_):
+ tests = tests + (PrincipalChecker(for_),)
+
+ if permission != 'zope.Public':
+ tests = tuple(tests) + (PermissionChecker(permission),)
+
+ group = Class(tests)
+
+ utility(_context, IPreferenceGroup, group, name=id)
+ adapter(_context, (PreferenceGroupAdapter(id),), schema,
+ (for_ or IPrincipal,))
+ adapter(_context, (PreferenceGroupAdapter(id),), schema,
+ (for_ or IPrincipal, interface.Interface))
+
+ interface.classImplements(Class, *provides)
+
+ self._class = Class
+ self._context = _context
+ self._permission = permission
+
+ self.require(_context, permission,
+ interface=(IPreferenceGroup, schema), set_schema=(schema,))
+ self.require(_context, CheckerPublic,
+ interface=(IEnumerableMapping, ILocation),
+ attributes=('isAvailable',
+ '__id__', '__schema__',
+ '__title__', '__description__'))
+
+ schema.setTaggedValue('preferenceID', id)
+
+ _context.action(
+ discriminator=('z3ext:preferences', schema),
+ callable=addSubgroup, args=(group,))
+
+ def require(self, _context,
+ permission=None, attributes=None, interface=None,
+ like_class=None, set_attributes=None, set_schema=None):
+ """Require a permission to access a specific aspect"""
+ if like_class:
+ self.__mimic(_context, like_class)
+
+ if not (interface or attributes or set_attributes or set_schema):
+ if like_class:
+ return
+ raise ConfigurationError("Nothing required")
+
+ if not permission:
+ raise ConfigurationError("No permission specified")
+
+ if interface:
+ for i in interface:
+ if i:
+ self.__protectByInterface(i, permission)
+
+ if attributes:
+ self.__protectNames(attributes, permission)
+
+ if set_attributes:
+ self.__protectSetAttributes(set_attributes, permission)
+
+ if set_schema:
+ for s in set_schema:
+ self.__protectSetSchema(s, permission)
+
+ def __mimic(self, _context, class_):
+ """Base security requirements on those of the given class"""
+ _context.action(
+ discriminator=('z3ext:preferences:mimic', self._class),
+ callable=protectLikeUnto,
+ args=(self._class, class_),
+ )
+
+ def allow(self, _context, attributes=None, interface=None):
+ """Like require, but with permission_id zope.Public"""
+ return self.require(_context, self._permission, attributes, interface)
+
+ def __protectByInterface(self, interface, permission_id):
+ "Set a permission on names in an interface."
+ for n, d in interface.namesAndDescriptions(1):
+ self.__protectName(n, permission_id)
+
+ self._context.action(
+ discriminator = None,
+ callable = provideInterface,
+ args = (interface.__module__+'.'+interface.getName(), interface))
+
+ def __protectName(self, name, permission_id):
+ "Set a permission on a particular name."
+ self._context.action(
+ discriminator = ('z3ext:preferences:protectName', object()),
+ callable = protectName,
+ args = (self._class, name, permission_id))
+
+ def __protectNames(self, names, permission_id):
+ "Set a permission on a bunch of names."
+ for name in names:
+ self.__protectName(name, permission_id)
+
+ def __protectSetAttributes(self, names, permission_id):
+ "Set a permission on a bunch of names."
+ for name in names:
+ self._context.action(
+ discriminator = (
+ 'z3ext:preferences:protectSetAttribute', object()),
+ callable = protectSetAttribute,
+ args = (self._class, name, permission_id))
+
+ def __protectSetSchema(self, schema, permission_id):
+ "Set a permission on a bunch of names."
+ _context = self._context
+
+ for name in schema:
+ field = schema[name]
+ if IField.providedBy(field) and not field.readonly:
+ _context.action(
+ discriminator = (
+ 'z3ext:preferences:protectSetAttribute', object()),
+ callable = protectSetAttribute,
+ args = (self._class, name, permission_id))
+
+ _context.action(
+ discriminator = None,
+ callable = provideInterface,
+ args = (schema.__module__+'.'+schema.getName(), schema))
+
+
+def addSubgroup(group):
+ if '.' in group.__id__:
+ parentId = group.__id__.split('.')[0]
+ else:
+ parentId = ''
+
+ parent = queryUtility(IPreferenceGroup, parentId)
+ if parent is None:
+ parent = getGlobalSiteManager().getUtility(IPreferenceGroup, parentId)
+
+ parent.add(group.__name__)
+ group.__parent__ = parent
More information about the Checkins
mailing list