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

J

Junkmail

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:
"<TextileClass 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
 
D

Dieter Maurer

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

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".
...
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.

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).
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.

This should not happen in ZPT (unless you use "structure").
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:
"<TextileClass at home>".

Any thoughts are appreciated.

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
 
J

Junkmail

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.index_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_html()" 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top