[Checkins] SVN: grokcore.viewlet/trunk/src/grokcore/viewlet/components.py Simplify code with the option to sort_components.
Sylvain Viollow
cvs-admin at zope.org
Sun Apr 29 13:35:03 UTC 2012
Log message for revision 125380:
Simplify code with the option to sort_components.
Changed:
U grokcore.viewlet/trunk/src/grokcore/viewlet/components.py
-=-
Modified: grokcore.viewlet/trunk/src/grokcore/viewlet/components.py
===================================================================
--- grokcore.viewlet/trunk/src/grokcore/viewlet/components.py 2012-04-29 13:13:24 UTC (rev 125379)
+++ grokcore.viewlet/trunk/src/grokcore/viewlet/components.py 2012-04-29 13:34:59 UTC (rev 125380)
@@ -13,6 +13,8 @@
##############################################################################
"""Grok components"""
+from operator import itemgetter
+
from zope import component, interface
from zope.viewlet.manager import ViewletManagerBase
from zope.viewlet.viewlet import ViewletBase
@@ -45,24 +47,8 @@
``viewlets`` is a list of tuples of the form (name, viewlet).
"""
- # In Grok, the default order of the viewlets is determined by
- # util.sort_components. util.sort_components() however expects
- # a list of just components, but sort() is supposed to deal
- # with a list of (name, viewlet) tuples.
- # To handle this situation we first store the name part on the
- # viewlet, then use util.sort_components() and then "unpack"
- # the name from the viewlet and recreate the list of (name,
- # viewlet) tuples, now in the correct order.
- s_viewlets = []
- for name, viewlet in viewlets:
- # Stuff away viewlet name so we can later retrieve it.
- # XXX We loose name information in case the same viewlet
- # is in the viewlets list twice, but with a different
- # name. Most probably this situation doesn't occur.
- viewlet.__viewlet_name__ = name
- s_viewlets.append(viewlet)
- s_viewlets = util.sort_components(s_viewlets)
- return [(viewlet.__viewlet_name__, viewlet) for viewlet in s_viewlets]
+ # Sort viewlets following grok.order rule.
+ return util.sort_components(viewlets, key=itemgetter(1))
def default_namespace(self):
namespace = {}
More information about the checkins
mailing list