[Zope] Site Navigation problem
   
    Nico de Boer
     
    nico@nfg.nl
       
    04 Sep 2002 09:51:20 +0200
    
    
  
Hi all,
I'm working on a site navigation product. For the rendering I've got
some rendering methods that the site owner can customize. This way the
rendering methods aren't hard coded in python.
Now I've got a problem as someone removes one of these methods. Here's
 a snippet of code for a tree site menu:
        # test if a tree menu has to be generated
		if self.mode=='tree': 
            # test if the current item is active
			if self.isactive(objectid,newcontextid):
                # seperate method to test for dtml rendering-method
				if self.methodTestOk('tree_item_active'):
                    # call the dtml-method from python
					return self.NavItem(self.tree_item_active)
			else:
                # the current item is inactive
                # test if dtml rendering-method isn't deleted
				if self.methodTestOk('tree_item_link'):
                    # call the dtml-method from python
					return self.NavItem(self.tree_item_link)
	def NavItem(self, dtmlmethod):
		return self.call(
			dtmlmethod,
			client=self,
			REQUEST=self.REQUEST)
	def call(self, f, *args, **kw):
		try: return apply(f,args, kw)
		except:
			import sys
			raise sys.exc_info()[0],sys.exc_info()[1],sys.exc_info()[2]
	def methodTestOk(self, methodname):
		if hasattr(self, methodname):
			return 1
		else:
            return 0
This is an example of a dtml-rendering method (the current object is given as
an argument to the method):
<tr>
  <td>
    <a href="<dtml-var absolute_url>"><dtml-var title_or_id></a>
  </td>
</tr>
Maybe someone knows an other way to call dtml-methods from python. The
problem with my code is that I don't get any error message if one of
the methods is deleted. I get a None object back. Is it possible that
methodTestOk returns the errormessage?
Can someone help me with my problem?
Greetz Nico