Re: passing element lists to cheetah template

Jeremy James <[email protected]> Tue, 09 Nov 2010 12:29:45 +0000
Newsgroups gmane.comp.python.cheetah
Message-ID <[email protected]>
Hi Robin,

I suspect it's search the properties of the items in the search list, so =

it is trying to find something that doesn't exist, like core.core or =

core["core"]. You probably want to explicitly list things that are being =

passed through, like:

t =3D Template(file=3D"stat.tmpl", searchList=3D[{"core":core}])

Or to be particularly lazy (I'll certainly be told off for this):

t =3D Template(file=3D"stat.tmpl", searchList=3D[locals()])

Best wishes,
Jeremy


Robin D. Bussell wrote:
> Hi Folks,
> I'm new to Python and Cheetah so please bear with me, I hope this will =

> be a simple answer:
> =

> I'm aiming to use a python script to parse some xml into an elementTree =

> and fill a list with elements from some braches of the xml.
> So far so good, The parsing works fine, I end up with a list with =

> elements in it and can print the contents out to verify the right =

> attributes got in there .... that was lovely and easy and made my first =

> experience of python a happy one :)
> =

> My problem comes when I try to use the resulting list in a cheetah =

> template, namemapper can't find my object :(I'd be greatful if anyone =

> could cast an eye over this and tell me where I might be going wrong (or =

> even point me at a better place to ask this question! )
> =

> here's the python side of things:
> =

>  =

> =

>  =

> =

>  =

> =

> |import elementtree.ElementTree as ET|
> |from Cheetah.Template import Template |
> |core=3D[]|
> =

> |#load config xml file as tree of elements|
> |configtree=3DET.parse("/etc/ddmi/ddmi.conf")|
> =

> |#walk it and fill category lists|
> |daemons=3Dconfigtree.find("daemons")|
> |for daemon in  daemons:|
> |   print daemon.tag|
> |   for member in daemon:|
> |      print member.text, member.get("category"), member.get("longname")|
> |      if member.get("category") =3D=3D "corecomm" :|
> |         core.append(member)|
> |      else:|
> |         print ("unknown category" , member)    |
> |      |
> |#do template stuff:|
> |t =3D Template(file=3D"stat.tmpl", searchList=3D[core])|
> |print t|
> =

> | |
> =

> | |
> =

> And here's a section of the template:
> =

>  =

> =

> |#for $corething in $core|
> |<td id=3D"${corething.text}_Test">|
> |        <div class=3D"statusBoxBlue">|
> |        ${corething.get("longname")} untested|
> |        </div>   |
> |</td>|
> |#end for|
> =

> | |
> =

> | |
> =

> | |
> =

> When I run the python (on gentoo, python 2.6.5 , cheetah 2.4.3 ) I get =

> (after some printing of the elements ) :
> =

>  =

> =

>  =

> =

> |Traceback (most recent call last):|
> |  File "pytest.py", line 21, in <module>|
> |    print t|
> |  File "/usr/lib/python2.6/site-packages/Cheetah/Template.py", line =

> 1005, in __str__|
> |    rc =3D getattr(self, mainMethName)()|
> |  File "_home_ddmi_stat_tmpl.py", line 85, in respond|
> |NameMapper.NotFound: cannot find 'core'|
> =

> | |
> =

> | |
> =

> | |
> =

> |Any ideas where I=92m going wrong?|
> =

> | |
> =

> |Many Thanks,|
> =

> |          Robin.|
> =

> | |
> =

> | |
> =

>  =

> =

> =

> ------------------------------------------------------------------------
> =

> -------------------------------------------------------------------------=
-----
> The Next 800 Companies to Lead America's Growth: New Video Whitepaper
> David G. Thomson, author of the best-selling book "Blueprint to a =

> Billion" shares his insights and actions to help propel your =

> business during the next growth cycle. Listen Now!
> http://p.sf.net/sfu/SAP-dev2dev
> =

> =

> ------------------------------------------------------------------------
> =

> _______________________________________________
> Cheetahtemplate-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss


---------------------------------------------------------------------------=
---
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a =

Billion" shares his insights and actions to help propel your =

business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev