[Zope-CMF] Re: Implementing utitlity functions in a product to be used by ZPT

Rainer Thaden Rainer Thaden <thadi@gmx.de>
Mon, 1 Jul 2002 12:57:49 +0200


Hi,

RT> I built a product for CMF with some classes in it and have lots of
RT> small python scripts which are used for conversions etc.
RT> I'd like to put all these small helper functions in one file which
RT> is available in page templates.

after some googling and experimenting i finally solved the problem.
For anyone who's interested:

the my_utils file just defines some functions

def myfunc(context, bla)

in the __init.py it goes like so:

from AccessControl import ModuleSecurityInfo

import my_utils

ModuleSecurityInfo('Products').declarePublic('MyProduct')
ModuleSecurityInfo('Products.MyProduct').declarePublic('my_utils')
ModuleSecurityInfo('Products.MyProduct.my_utils').declarePublic('myfunc')



and in a ZPT i use it like so:

...tal:define="item
        python:modules['Products.MyProduct.my_utils'].myfunc(here,item)"


-- 
Regards,
 Rainer                            mailto:thadi@gmx.de