[Zope3-dev] View components being instantiated twice?

Steve Alexander steve@cat-box.net
Sat, 16 Feb 2002 20:19:29 +0000


Steve Alexander wrote:
> I've put some debugging printing in the __init__ method of 
> ContactEditView from the Contact product.
> 
> For some reason, when I view acontact/edit;view, the view is 
> instantiated twice in a row.
> 
> Any idea why?

I've tracked this down:

See Zope/App/ZMI/ZMIViewUtility.py, line 42:

  def getZMIViews(self):

         context = self.getContext()
         zmi_view_service = getService(context, 'ZMIViewService')
         zmi_views=[]
         traverser = PublicationTraverser()
         for view in zmi_view_service.getViews(context):
             label=view[0]
             action=view[1]
             try:
                 # THIS NEXT LINE !!!
                 traverser.traversePath(self.__request, context, action)
             except Unauthorized:
                 pass # Skip unauthorized
             else:
                 zmi_views.append({'label': label, 'action': "../%s" % 
action})

         return zmi_views


The call to traverser.traversePath is being used to check whether the 
view is authorized. Surely there must be a better way of doing this!

--
Steve Alexander