Re: [Zope] Re: Getting at third-party modules in dtml?

2005-09-21 Thread Dieter Maurer
Paul Winkler wrote at 2005-9-20 14:02 -0500:
 ...
I have to say that's pretty darn obscure behavior.
It's the antithesis of self-documenting, and I've never seen it used
before.  Is this documented somewhere?

It is the ancient product initialization -- used by the first
products: e.g. DTML Document and Method and ZSQL Method.

It was superceeded by product local constructors -- for the obvious
reason to avoid name clashes.

 ...
Also, AFAICT there's no way to declare security on that function.
(which is OK in this case since I wanted something 'public' anyway).

It is -- if you know and use the implementation details
of Zope's security subsystem:

   To protect a method m with permission p,
   you assign PermissionRole(p) to m__roles__.

Not that a maintainer (without the same detailed knowledge
about the security subsystem) would understand such
a method -- unless you had put in an explaining comment...

-- 
Dieter
___
Zope maillist  -  Zope@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 )


Re: [Zope] Re: Getting at third-party modules in dtml?

2005-09-20 Thread Dieter Maurer
Axel Straschil wrote at 2005-9-20 04:07 +:
Hi!

 Say I have a function that I want to make callable in
 my UI. It needs to be globally available, i.e. it needs to
 be callable *without* having an instance of my product yet.
 (This has to do with listing information about all acquirable
 instances of the product, so the user can choose from those
 available.)

In a Product's __init__.py:

def theSecret(self):
   return A hobbit!
   
methods = {
   'whatIsFrodo':  theSecret
}


Save that i.E. in MyInstance/Products/MyFancy/__init__.py, restart Zope
And than dtml-var whatIsFrodo. 

And if you do not want to pollute the Folder (class) namespace,
you can define it as a constructors (to registerClass)
and use it via
objectManager.manage_addProduct[your product].constructor(...)

-- 
Dieter
___
Zope maillist  -  Zope@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 )


Re: [Zope] Re: Getting at third-party modules in dtml?

2005-09-20 Thread Paul Winkler
 Axel Straschil wrote at 2005-9-20 04:07 +:
Hi!

 Say I have a function that I want to make callable in
 my UI. It needs to be globally available, i.e. it needs to
 be callable *without* having an instance of my product yet.
 (This has to do with listing information about all acquirable
 instances of the product, so the user can choose from those
 available.)

In a Product's __init__.py:

def theSecret(self):
  return A hobbit!

methods = {
  'whatIsFrodo':  theSecret
}


Save that i.E. in MyInstance/Products/MyFancy/__init__.py, restart Zope
 And than dtml-var whatIsFrodo.

 And if you do not want to pollute the Folder (class) namespace,
 you can define it as a constructors (to registerClass)
 and use it via
 objectManager.manage_addProduct[your product].constructor(...)

Very educational, thanks for the replies!
I didn't understand Dieter's comment until I tried Axel's suggestion.
It apparently works by adding a theSecret method to the Folder
class and derived objects including the root App object.
i.e. you can visit http://localhost:8080/theSecret and (if the method
has a docstring) you'll see 'A hobbit!'.

I have to say that's pretty darn obscure behavior.
It's the antithesis of self-documenting, and I've never seen it used
before.  Is this documented somewhere?
I see one example of it in OFS/tests/testProductInit.py...

Also, AFAICT there's no way to declare security on that function.
(which is OK in this case since I wanted something 'public' anyway).

Anyway, in the end, I followed neither suggestion, since I don't want
either to pollute the Folder (class) namespace, nor do I want
to register a constructor that isn't really a constructor ...
the former would be obnoxious to users who install my product, the
latter seems likely to confuse whoever has to maintain this code
after me!

Instead, I bit the bullet and rewrote the offending part of the
UI as a PageTemplateFile; it wasn't much work after all and I can
leave the rest as DTML for now.  I like this solution because
client code (the template) has to explicitly look up the function
via the 'modules' mapping.

-PW



___
Zope maillist  -  Zope@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 )