[Zope3-checkins]
SVN: Zope3/branches/roger-contentprovider/src/zope/portlet/
statehandler work in progress
Helmut Merz
helmutm at cy55.de
Sat Oct 8 18:30:21 EDT 2005
Log message for revision 38982:
statehandler work in progress
Changed:
U Zope3/branches/roger-contentprovider/src/zope/portlet/preferences.py
U Zope3/branches/roger-contentprovider/src/zope/portlet/statehandler.py
U Zope3/branches/roger-contentprovider/src/zope/portlet/statehandler.txt
-=-
Modified: Zope3/branches/roger-contentprovider/src/zope/portlet/preferences.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/portlet/preferences.py 2005-10-08 22:28:31 UTC (rev 38981)
+++ Zope3/branches/roger-contentprovider/src/zope/portlet/preferences.py 2005-10-08 22:30:21 UTC (rev 38982)
@@ -18,21 +18,21 @@
__docformat__ = 'restructuredtext'
from zope.interface import Interface
-from zope.schema import Bool
-
+from zope import schema
from zope.app.i18n import ZopeMessageIDFactory as _
-
-class IPortletPreference(Interface):
+class IPortletPreferences(Interface):
"""User Preference for a single portlet."""
- expanded = Bool(
+ expanded = schema.Bool(
title=_(u"Show portlet expanded"),
description=_(u"Shows portlet in its inital state expanded.")
)
- state = Choice(
+ state = schema.Choice(
title=_(u"Portlet state"),
- description=_(u"Render portlt in the given mode.")
- )
\ No newline at end of file
+ description=_(u"Render portlet in the given mode."),
+ values=(_(u"visible"), _(u"hidden"),),
+ )
+
\ No newline at end of file
Modified: Zope3/branches/roger-contentprovider/src/zope/portlet/statehandler.py
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/portlet/statehandler.py 2005-10-08 22:28:31 UTC (rev 38981)
+++ Zope3/branches/roger-contentprovider/src/zope/portlet/statehandler.py 2005-10-08 22:30:21 UTC (rev 38982)
@@ -17,12 +17,15 @@
"""
__docformat__ = 'restructuredtext'
+from zope.app import zapi
import zope.interface
+from zope.app.preference import preference
+from zope.contentprovider.interfaces import IContentProviderType
from zope.portlet import interfaces
+from zope.portlet.preferences import IPortletPreferences
-
class PreferencesStateHandler(object):
"""State handler based on preferences."""
@@ -34,5 +37,12 @@
def setState(self, value, name):
"""xxx"""
- # self.preferences.portletmanager.%s.state = %s % (portletname, name)
+ cpType = zapi.queryType(self.context, IContentProviderType)
+ cpTypeName = cpType.__module__ + '.' + cpType.__name__
+ settings = preference.PreferenceGroup(
+ cpTypeName,
+ schema=IPortletPreferences,
+ title=u"Portlet User Settings",
+ description=u""
+ )
Modified: Zope3/branches/roger-contentprovider/src/zope/portlet/statehandler.txt
===================================================================
--- Zope3/branches/roger-contentprovider/src/zope/portlet/statehandler.txt 2005-10-08 22:28:31 UTC (rev 38981)
+++ Zope3/branches/roger-contentprovider/src/zope/portlet/statehandler.txt 2005-10-08 22:30:21 UTC (rev 38982)
@@ -51,8 +51,8 @@
>>> class ISpecialPortlet(IPortlet):
... pass
-Our content provider must be of IContentProviderType so it can recognized
-during adapter lookup:
+Content provider types must be of IContentProviderType so that they can be
+recognized during adapter lookup:
>>> directlyProvides(ISpecialPortlet, IContentProviderType)
@@ -73,10 +73,36 @@
'visible'
-Use preferences for portlat state storage
+Use preferences for portlet state storage
-----------------------------------------
>>> from zope.portlet.statehandler import PreferencesStateHandler
+ >>> from zope.publisher.browser import TestRequest
+ >>> from zope.publisher.browser import IBrowserRequest
+
>>> ztapi.provideAdapter(IPortlet, IStateHandler, PreferencesStateHandler)
+We need a principal to store preferences with and a corresponding interaction
+to find it.
+ >>> 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.endInteraction()
+ >>> zope.security.management.newInteraction(participation)
+
+ >>> handler = zapi.getAdapter(portlet, IStateHandler)
+ >>> isinstance(handler, PreferencesStateHandler)
+ True
+ >>> handler.setState('visible', name='dummy.portlet')
+
More information about the Zope3-Checkins
mailing list