[ZPT] Calling complex product tags from ZPT
   
    J C Lawrence
     
    claw@kanga.nu
       
    Sat, 13 Jul 2002 23:10:49 -0700
    
    
  
On Sun, 07 Jul 2002 18:56:30 +0200 
j-david  <ISO-8859-1> wrote:
> J C Lawrence wrote:
>> On Sun, 07 Jul 2002 17:12:23 +0200 j-david <ISO-8859-1> wrote:
> I use a really primitive way to debug, which is enough most of the
> time. Just modify NuxWidgets to output a message in the right
> places. For example, in NuxWidgets.__init__.py, add the following line
> at the beginning of pt_getContext:
>   open('/tmp/kk', 'w').write('pt_getContext from NuxWidgets\n')
I went a little further than that:
--<cut>--
def pt_getContext(self):
    """
    New "pt_getContext" method, adds the "widgets" name.
    """
    c = self.pt_getContext_old()
    c['widgets'] = widgets
    open('/tmp/t.t', 'a').write('pt_getContext from NuxWidgets\n')
    return c
PageTemplate.pt_getContext = pt_getContext
PageTemplateFile.pt_getContext = pt_getContext
ZopePageTemplate.pt_getContext = pt_getContext
######################################################################
# Security, declare this module public
######################################################################
from AccessControl import ModuleSecurityInfo
ModuleSecurityInfo('Products').declarePublic('NuxWidgets')
######################################################################
# Register the widgets
######################################################################
# Calendar
from Calendar import calendar
open('/tmp/t.t', 'a').write('Declare calendar\n')
widgets['calendar'] = calendar.macros['calendar']
# Timetable
from Timetable import timetable
open('/tmp/t.t', 'a').write('Declare timetable\n')
widgets['timetable'] = timetable.macros['timetable']
open('/tmp/t.t', 'a').write('Done\n')
--<cut>
Results:
  $ cat /tmp/t.t
  Declare calendar
  Declare timetable
  Done
ie pt_getContext is never getting called.
Curious.  This is under Python 2.1.
-- 
J C Lawrence                
---------(*)                Satan, oscillate my metallic sonatas. 
claw@kanga.nu               He lived as a devil, eh?		  
http://www.kanga.nu/~claw/  Evil is a name of a foeman, as I live.