Zope: Adding a layer causes valid output to become an object reference?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Junkmail

    #1

    Zope: Adding a layer causes valid output to become an object reference?

    I've been playing with Zope for about a year and took the plunge last
    week into making a product.

    To keep it [arguably] simple I used a ZClass to wrap an external
    method. My ZClass works and returns the output I expect.

    What doesn't work is when I refer to an object I've created from a
    dtml-var or a tal:content or tal:replace statement. Instead of the
    proper output I receive: <TextileClass at home> where TextileClass is
    my class name and home is the Object ID I'm referencing. The fact that
    the < and > surround the output make it invisible in the browser and
    had me chasing ghosts for a while. I'd bet I'm not groking something
    here.

    So if I call /home I get the proper HTML output: "<b>What I am looking
    for</b>" but when in another object I reference <dtml-var home> I get:
    "<TextileCl ass at home>".

    Any thoughts are appreciated.

    Mike

    PS: Yes it is a wrapper for Textile ver 2 and I plan on publishing it.
    It is however limited to Zope 2.7+ due to the implementation of Textile
    requiring Python 2.3

  • Dieter Maurer

    #2
    Re: Zope: Adding a layer causes valid output to become an object reference?

    "Junkmail" <junkmail@chipw orks.net> writes on 10 Feb 2005 18:26:52 -0800:[color=blue]
    > I've been playing with Zope for about a year and took the plunge last
    > week into making a product.[/color]

    You should send Zope related questions to the Zope mailing list.
    You will need to subcribe. You can do this at "http://www.zope.org".
    [color=blue]
    > ...
    > What doesn't work is when I refer to an object I've created from a
    > dtml-var or a tal:content or tal:replace statement. Instead of the
    > proper output I receive: <TextileClass at home> where TextileClass is
    > my class name and home is the Object ID I'm referencing.[/color]

    There is a fundamental difference when you "call" an object
    with ZPublisher (i.e. via the Web) and when you use it
    in a template.

    ZPublisher effectively "calls" "index_html " and if
    this is "None", it calls the object.

    A template (usually) calls the object (if it is callable) and
    then converts the result into a string.


    Apparently, your ZInstance is not callable.
    Therefore, it is converted into a string.
    Apparently, it does not have a custom "__str__",
    therefore, you get the standard string conversion for instances
    (that's what you see).
    [color=blue]
    > The fact that
    > the < and > surround the output make it invisible in the browser and
    > had me chasing ghosts for a while. I'd bet I'm not groking something
    > here.[/color]

    This should not happen in ZPT (unless you use "structure" ).
    [color=blue]
    > So if I call /home I get the proper HTML output: "<b>What I am looking
    > for</b>" but when in another object I reference <dtml-var home> I get:
    > "<TextileCl ass at home>".
    >
    > Any thoughts are appreciated.[/color]

    Call a method on your ZInstance.

    To get the same result as via ZPublisher (the Web),
    call its "index_html ". This may need arguments (I do not know).


    Dieter

    Comment

    • Junkmail

      #3
      Re: Zope: Adding a layer causes valid output to become an object reference?

      Dieter,

      Thanks for the reply. I ran across an article in the Zope FAQ that
      nailed the problem on the head. Basically it said the same thing you
      are saying. For those that follow in my footsteps one day...

      ZPublisher Implicitly calls the method of a url which in the case of a
      zclass is a call to index_html. From ZPT and DTML however you must
      Explicitly call the method of your zclass, for example:

      <dtml-var "get_users.inde x_html()">

      The paren () on the end are important!!

      To make matters worse my external script references parameters in the
      actual object I'm calling, but since I'm not calling a DTML method and
      I have to explicitly reference the method I want to call, the DTML
      namespace gets shipped to my external method instead of the namespace
      of my called object. I read "groking acquisition" 4 times before I
      groked it. To fix that I changed the index_html of my zclass to a
      python script and call my external script from there so I can pass the
      proper namespaces to the external script. I suppose I can do that from
      a DTML method, but the python script makes it absolutely clear what the
      intention is.

      I think the proper thing for the long term is re-write this as a
      Product and emulate the way a DTML method accepts a call so I can avoid
      all the "blah.index_htm l()" references and provide something a bit less
      error prone (more standard).

      I'm highly tempted to hack the existing DTML method into a new product
      and leave DTML in it so I can combine Textile with DTML in a single
      object.

      Thanks,

      Mike

      Comment

      Working...