[Zope3-Users] practical example of migrating from services to
utilities
Duncan McGreggor
duncan.mcgreggor at gmail.com
Mon Aug 8 15:57:21 EDT 2005
Hey all,
I just wanted to check to make sure I was doing this right, and if so,
provide a resource that would turn up on subsequent googling. This
example involves the getting menus items with the getService/getUtility
functions and is taken from Philip's worldcookery example code.
Here's the pertinent zcml (worldcookery/browser/configure.zcml):
<browser:menu
id="alternate_views"
title="Menu containing a list of alternative views for an object"
/>
<browser:addMenuItem
title="[label-recipe] Recipe"
class="worldcookery.recipe.Recipe"
permission="worldcookery.EditRecipes"
view="AddRecipe.html"
/>
Here's the original code (worldcookery/browser/recipe.py):
def alternateViews(self):
menu_service = zapi.getService(servicenames.BrowserMenu)
menu_id = 'alternate_views'
return menu_service.getMenu(menu_id, self.context, self.request)
Here's the modified example that I'd want to check if I am doing
correctly:
def alternateViews(self):
browser_menu = zapi.getUtility(IBrowserMenu, 'alternate_views')
return browser_menu.getMenuItems(self.context, self.request)
Am I doing this properly?
Thanks!
d
More information about the Zope3-users
mailing list