[Zope3-checkins] SVN: Zope3/trunk/src/zope/viewlet/ add name to
viewlets if they provide ILocation, so they know about their name
Bernd Dorn
bernd.dorn at lovelysystems.com
Sun Jan 28 06:57:10 EST 2007
Log message for revision 72245:
add name to viewlets if they provide ILocation, so they know about their name
Changed:
U Zope3/trunk/src/zope/viewlet/README.txt
U Zope3/trunk/src/zope/viewlet/manager.py
-=-
Modified: Zope3/trunk/src/zope/viewlet/README.txt
===================================================================
--- Zope3/trunk/src/zope/viewlet/README.txt 2007-01-27 23:37:28 UTC (rev 72244)
+++ Zope3/trunk/src/zope/viewlet/README.txt 2007-01-28 11:57:09 UTC (rev 72245)
@@ -99,8 +99,10 @@
... IBrowserView, ILeftColumn),
... interfaces.IViewlet, name='weather')
+ >>> from zope.location.interfaces import ILocation
>>> class SportBox(object):
- ... zope.interface.implements(interfaces.IViewlet)
+ ... zope.interface.implements(interfaces.IViewlet,
+ ... ILocation)
...
... def __init__(self, context, request, view, manager):
... self.__parent__ = view
@@ -158,6 +160,13 @@
<div class="box">It is sunny today!</div>
</div>
+If a viewlet provides ILocation the ``__name__`` attribute of the
+viewlet is set to the name under which the viewlet is registered.
+
+ >>> [getattr(viewlet, '__name__', None) for viewlet in leftColumn.viewlets]
+ [u'sport', None]
+
+
You can also lookup the viewlets directly for management purposes:
>>> leftColumn['weather']
Modified: Zope3/trunk/src/zope/viewlet/manager.py
===================================================================
--- Zope3/trunk/src/zope/viewlet/manager.py 2007-01-27 23:37:28 UTC (rev 72244)
+++ Zope3/trunk/src/zope/viewlet/manager.py 2007-01-28 11:57:09 UTC (rev 72245)
@@ -23,6 +23,7 @@
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
from zope.viewlet import interfaces
+from zope.location.interfaces import ILocation
class ViewletManagerBase(object):
"""The Viewlet Manager Base
@@ -97,10 +98,15 @@
viewlets = self.filter(viewlets)
viewlets = self.sort(viewlets)
-
# Just use the viewlets from now on
- self.viewlets = [viewlet for name, viewlet in viewlets]
+ self.viewlets=[]
+ for name, viewlet in viewlets:
+ if ILocation.providedBy(viewlet):
+ viewlet.__name__ = name
+ self.viewlets.append(viewlet)
+ self._updateViewlets()
+ def _updateViewlets(self):
# Update all viewlets
[viewlet.update() for viewlet in self.viewlets]
More information about the Zope3-Checkins
mailing list