[Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Chris Withers

Jim Fulton wrote:
snip __call__ stuff

Okay, this is almost the same, but apparently not the same.

I have a Python Product Class, with a method, a_method, that gets called
from some of the Python Product's management screens (encapsulation is
good ;-)

This method needs several parameters from the namespace, so when it's
called I was hoping I wouldn't have to do something nasty and clunky
like:

dtml-var "a_method(param1,param2,param3)"

Given my recently acquired __call__ Zen, I thought 'No problem...' and
tried to define the method as follows:

isDocTemplate = 1

def a_method(self, ignored=None, md=None):

...with the hope I'd just be able to do dtml-var a_method and pluck
the stuff from md.

No dice.

md and ignored turn up as None from all the dtml-var a_method calls.
:-(

What am I doing wrong? How can I get access to the namespace in a method
of a class like this?

cheers,

Chris

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Toby Dickenson

On Fri, 13 Oct 2000 11:48:39 +0100, Chris Withers [EMAIL PROTECTED]
wrote:

I have a Python Product Class, with a method, a_method, that gets called
from some of the Python Product's management screens (encapsulation is
good ;-)

This method needs several parameters from the namespace, so when it's
called I was hoping I wouldn't have to do something nasty and clunky
like:

dtml-var "a_method(param1,param2,param3)"

Given my recently acquired __call__ Zen, I thought 'No problem...' and
tried to define the method as follows:

isDocTemplate = 1

def a_method(self, ignored=None, md=None):

...with the hope I'd just be able to do dtml-var a_method and pluck
the stuff from md.

No dice.

md and ignored turn up as None from all the dtml-var a_method calls.
:-(

What am I doing wrong? How can I get access to the namespace in a method
of a class like this?

You need to have the isDocTemplate=1 as an attribute of the method
object itself, not the class that contains the method.

You also need some extra voodoo if you want to call the method
directly from ZPublisher (by including the method name in a url). Here
a link to a wrapper that does it all

http://www.zope.org/Members/htrd/howto/FunctionTemplate

you would use

def a_method(self,md):
do_stuff_with(md['param1'],md['param2'])
a_method = FunctionTemplate(a_method)




Toby Dickenson
[EMAIL PROTECTED]

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Chris Withers

Toby Dickenson wrote:
 http://www.zope.org/Members/htrd/howto/FunctionTemplate
 
 you would use
 
 def a_method(self,md):
 do_stuff_with(md['param1'],md['param2'])
 a_method = FunctionTemplate(a_method)

That looks like it'll do the trick... I wonder if there's any way you
can role it up into a Product so that I don't need to have
FunctionTemplate.py in each folder of a product that needs to use it?

cheers,

Chris

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




RE: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Toby Dickenson

 That looks like it'll do the trick... I wonder if there's any way you
 can role it up into a Product so that I don't need to have
 FunctionTemplate.py in each folder of a product that needs to use it?

Im working on a set of tools to aid my transition to a dtml-free Zope.
Eventually I will package them all as a whole.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Chris Withers

Toby Dickenson wrote:
 
  That looks like it'll do the trick... I wonder if there's any way you
  can role it up into a Product so that I don't need to have
  FunctionTemplate.py in each folder of a product that needs to use it?
 
 Im working on a set of tools to aid my transition to a dtml-free Zope.
 Eventually I will package them all as a whole.

cartman voice

swt

Chris ;-)

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Chris Withers

Toby Dickenson wrote:
 http://www.zope.org/Members/htrd/howto/FunctionTemplate
 
 you would use
 
 def a_method(self,md):
 do_stuff_with(md['param1'],md['param2'])
 a_method = FunctionTemplate(a_method)

Okay, spoke too soon... when I do the above and then call the method
with:

dtml-var a_method

I get:

Error type: exceptions.AttributeError
Error value: __len__ 

Traceback (innermost last):
  File E:\Zope\2271B4~1.2\lib\python\ZPublisher\Publish.py, line 222, in
publish_module
  File E:\Zope\2271B4~1.2\lib\python\ZPublisher\Publish.py, line 187, in
publish
  File E:\Zope\2271B4~1.2\lib\python\Zope\__init__.py, line 221, in
zpublisher_exception_hook
(Object: testdefiner)
  File E:\Zope\2271B4~1.2\lib\python\ZPublisher\Publish.py, line 171, in
publish
  File E:\Zope\2271B4~1.2\lib\python\ZPublisher\mapply.py, line 160, in
mapply
(Object: index_html)
  File E:\Zope\2271B4~1.2\lib\python\ZPublisher\Publish.py, line 112, in
call_object
(Object: index_html)
  File E:\Zope\2271B4~1.2\lib\python\App\special_dtml.py, line 120, in
__call__
(Object: index_html)
(Info: E:\Zope\2.2.2\lib\python\Products\A_product\Form.dtml)
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLLocator.py, line
103, in __call__
(Object: index_html)
  File E:\Zope\2271B4~1.2\lib\python\DocumentTemplate\DT_String.py, line
528, in __call__
(Object: index_html)
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLDebug.py, line 288,
in debug_render_blocks
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLDebug.py, line 286,
in debug_render_blocks
  File E:\Zope\2271B4~1.2\lib\python\DocumentTemplate\DT_In.py, line
691, in renderwob
(Object: _.range(1,11))
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLDebug.py, line 288,
in debug_render_blocks
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLDebug.py, line 286,
in debug_render_blocks
  File E:\Zope\2271B4~1.2\lib\python\DocumentTemplate\DT_Let.py, line
147, in render
(Object: row=sequence-item)
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLDebug.py, line 242,
in debug_render_blocks
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLDebug.py, line 221,
in debugException
  File E:\Zope\2.2.1\lib\python\Products\ZDebug\DTMLDebug.py, line 239,
in debug_render_blocks
  File E:\Zope\2.2.2\lib\python\Products\A_product\FunctionTemplate.py,
line 38, in __call__
AttributeError: (see above)

What's going on?

cheers,

Chris

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Chris Withers

Jim Fulton wrote:

 In any case, if you *just* want to get your function to be
 called from DTML (and your class is an extension class), you can give
 it the isDocTemp attribute like so:
 
   class MyClass( include some extension class ...):
 
 some_methodisDocTemp=1
 def some_method(self, ignored, md):

great :-) that did the trick, thanks...

I can't help but feel this woudl all be so much simpler if it was
documented somewhere for idiots like me :-S

cheers,

Chris

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Shane Hathaway

Jim Fulton wrote:
 
 Chris Withers wrote:
 
  Toby Dickenson wrote:
   http://www.zope.org/Members/htrd/howto/FunctionTemplate
  
   you would use
  
   def a_method(self,md):
   do_stuff_with(md['param1'],md['param2'])
   a_method = FunctionTemplate(a_method)
 
  That looks like it'll do the trick... I wonder if there's any way you
  can role it up into a Product so that I don't need to have
  FunctionTemplate.py in each folder of a product that needs to use it?
 
 Is it *really* the case that you often want to method to be called directly
 via the Web *and* and from DTML?  This doesn't seem right to me.

As I understand it, that's not the issue.  Chris wants to receive the
DTML namespace implicitly.

 In any case, if you *just* want to get your function to be
 called from DTML (and your class is an extension class), you can give
 it the isDocTemp attribute like so:
 
   class MyClass( include some extension class ...):
 
 some_methodisDocTemp=1
 def some_method(trueself, self, REQUEST, RESPONSE=None):
 

That's a good idea, I wish I'd thought of it. :-)

However, the new calling convention (__render_with_namespace__, or
something like that) might break "isDocTemp" code.

 Note that if you get called from the web, RESPONSE will
 not be none. This is a handy way to decide if you
 are called from the web or as a sub-template. Of course,
 someone could pass a non-None RESPONSE argument directly.

This convention is helpful but not at all documented, so products (ZWiki
is a good example) often break this convention.

Shane

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Jim Fulton

Shane Hathaway wrote:
 
 Jim Fulton wrote:
 
  Chris Withers wrote:
  
   Toby Dickenson wrote:
http://www.zope.org/Members/htrd/howto/FunctionTemplate
   
you would use
   
def a_method(self,md):
do_stuff_with(md['param1'],md['param2'])
a_method = FunctionTemplate(a_method)
  
   That looks like it'll do the trick... I wonder if there's any way you
   can role it up into a Product so that I don't need to have
   FunctionTemplate.py in each folder of a product that needs to use it?
 
  Is it *really* the case that you often want to method to be called directly
  via the Web *and* and from DTML?  This doesn't seem right to me.
 
 As I understand it, that's not the issue.  Chris wants to receive the
 DTML namespace implicitly.
 
  In any case, if you *just* want to get your function to be
  called from DTML (and your class is an extension class), you can give
  it the isDocTemp attribute like so:
 
class MyClass( include some extension class ...):
 
  some_methodisDocTemp=1
  def some_method(trueself, self, REQUEST, RESPONSE=None):
  
 
 That's a good idea, I wish I'd thought of it. :-)
 
 However, the new calling convention (__render_with_namespace__, or
 something like that) might break "isDocTemp" code.

I thought of that, but I don't think so. There are obviously 
enough people using the isDocTemp thing that we'll probably need to
keep supporting it.  The use of a separate render method won't be
convenient for iplementing simple methods. Not that that is necessarily
that critical.

  Note that if you get called from the web, RESPONSE will
  not be none. This is a handy way to decide if you
  are called from the web or as a sub-template. Of course,
  someone could pass a non-None RESPONSE argument directly.
 
 This convention is helpful but not at all documented, so products (ZWiki
 is a good example) often break this convention.

Which convention? The passing of arguments with names meaningful to
the publisher is certainly well documented.

Jim

--
Jim Fulton   mailto:[EMAIL PROTECTED]   Python Powered!
Technical Director   (888) 344-4332http://www.python.org  
Digital Creationshttp://www.digicool.com   http://www.zope.org

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] More almost __call__ ;-)

2000-10-13 Thread Shane Hathaway

Jim Fulton wrote:
 The fact that ZPublisher will pass it is documented.  Whether
 or not something else calls it is up to the something else.
 The method designer specified an interface that includes RESPONSE.
 If it requires RESPONSE, by not specifying a default, then it
 requires the clients to oass it. If the clients don't, then they
 are not satisfying the interface.  Are you saying that objects
 that require that RESPONSE is passed are broken because they don't
 sufficiently advertise the fact?

I'm saying that there are some methods which expect the RESPONSE to be
passed only when called by ZPublisher.  They expect RESPONSE to be
"None" when called as a subtemplate or otherwise.  The only problem is
that this convention is not enforced.

But we've strayed... :-)

Shane

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )