[Zope] help with restrictedTraverse

Small Business Services toolkit at magma.ca
Wed Dec 10 17:53:40 EST 2003


I would not use the name 'getObject' as this is the name of a zope routine.

I like to use dtml-with statements to access subfolders (easy, maintainable, and I usually do more than one thing in a given subfolder at a given time)

eg

<dtml-with Plone>
  <dtml-with reports>
    <dtml-with Site2>
       <dtml-var myObject>


If you do want to use restrictedTraverse you can do it with dtml:

<dtml-var "restrictedTraverse('Plone/reports/Site2/myObject')">

however you must ensure the myObject is something that the dtml-var tag can work with (eg. if myObject is a zclass with property fields, dtml-var won't be able to display anything for you - you won't get an error, just nothing will show - unless you view the html source code that is rendered and you will see something like '<zclassname at myObject>')


HTH

Jonathan



  ----- Original Message ----- 
  From: Ruben Montejano 
  To: zope at zope.org 
  Sent: December 10, 2003 5:24 PM
  Subject: [Zope] help with restrictedTraverse


  Hi everybody,

     The task I am trying to accomplish is to be able to call an object(it could
  be a dtml method, python script, php document, etc), given its path as a string
  parameter.
     Let's say my directory structure looks like this:
  /-+-Plone-+-homepage 
            +-reports-+-Site1 
                      +-Site2-+-myObject 
                      +-... 
            +-... 

      I need to call myObject, which path is '/Plone/reports/Site2/', from any
  other directory within the directory structure, but at this time I'm using
  homepage.

      Browsing the mailing list I found that I could use restrictedTraverse, so
  I created an External Method getObject under the homepage directory with the
  following code:

  def getObject( self ):
      return self.restrictedTraverse('/Plone/reports/Site2/myObject')

  myObject in this case is a php document that contains: 
  <?php
  include "http://2ksvr/ploneSupp/lines.php?wk=2002-06-01";
  ?>

  Now using the External Method from the homepage's index_html:
  <dtml-var getObject>

  This is what I get, instead of the chart that this object displays:
  <?php include "http://2ksvr/ploneSupp/lines.php?wk=2002-06-01"; ?>

  I also tried creating a python script with the following code:
  return container.restrictedTraverse('/Plone/pig_reports/test_farrowing/crChart')

  but the script returns this:
  &lt;?php
  include &quot;http://2ksvr/ploneSupp/lines.php?wk=2002-06-01&quot;;
  ?&gt;

  What am I doing wrong? Any ideas or help is more than welcome.
  Thanks,

         Ruben Montejano.
         email: rubemontejano at yahoo.com



  ----------------------------------------------------
  Ruben Montejano.
  phone: (309) 837-2318
  email: rubemontejano at yahoo.com


------------------------------------------------------------------------------
  Do you Yahoo!?
  New Yahoo! Photos - easier uploading and sharing


------------------------------------------------------------------------------


  _______________________________________________
  Zope maillist  -  Zope at zope.org
  http://mail.zope.org/mailman/listinfo/zope
  **   No cross posts or HTML encoding!  **
  (Related lists - 
   http://mail.zope.org/mailman/listinfo/zope-announce
   http://mail.zope.org/mailman/listinfo/zope-dev )

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope/attachments/20031210/94f2a775/attachment.html


More information about the Zope mailing list