passing element lists to cheetah template

"Robin D. Bussell" <[email protected]> Tue, 9 Nov 2010 10:47:37 -0000
Newsgroups gmane.comp.python.cheetah
Message-ID <6DC1FD29A26F0E43BC8ED19E8A00D6F4AD6257@lister.holly.ho.excelerate.com>
This is a multi-part message in MIME format.

--===============3687891037511478792==
Content-class: urn:content-classes:message
Content-Type: multipart/related; type="multipart/alternative";
	boundary="----_=_NextPart_001_01CB7FFB.7EC6E04F"

This is a multi-part message in MIME format.

------_=_NextPart_001_01CB7FFB.7EC6E04F
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_002_01CB7FFB.7EC6E04F"


------_=_NextPart_002_01CB7FFB.7EC6E04F
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

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 =20

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:

=20

=20

=20

import elementtree.ElementTree as ET
from Cheetah.Template import Template=20
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)   =20
     =20
#do template stuff:
t =3D Template(file=3D"stat.tmpl", searchList=3D[core])
print t

=20

=20

And here's a section of the template:

=20

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

=20

=20

=20

When I run the python (on gentoo, python 2.6.5 , cheetah 2.4.3 ) I get
(after some printing of the elements ) :

=20

=20

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'

=20

=20

=20

Any ideas where I'm going wrong?

=20

Many Thanks,

          Robin.

=20

=20

=20


------_=_NextPart_002_01CB7FFB.7EC6E04F
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<meta name=3DGenerator content=3D"Microsoft Word 12 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
code
	{mso-style-priority:99;
	font-family:"Courier New";}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
	{mso-style-priority:99;
	mso-style-link:"Balloon Text Char";
	margin:0cm;
	margin-bottom:.0001pt;
	font-size:8.0pt;
	font-family:"Tahoma","sans-serif";}
span.EmailStyle17
	{mso-style-type:personal-compose;
	font-family:"Calibri","sans-serif";
	color:windowtext;}
span.BalloonTextChar
	{mso-style-name:"Balloon Text Char";
	mso-style-priority:99;
	mso-style-link:"Balloon Text";
	font-family:"Tahoma","sans-serif";}
.MsoChpDefault
	{mso-style-type:export-only;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
	{page:WordSection1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext=3D"edit" spidmax=3D"2050" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext=3D"edit">
  <o:idmap v:ext=3D"edit" data=3D"1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=3DEN-GB link=3Dblue vlink=3Dpurple>

<div class=3DWordSection1>

<p class=3DMsoNormal>Hi Folks,<br>
I'm new to Python and Cheetah so please bear with me, I hope this will =
be a
simple answer:<br>
<br>
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.<br>
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 <img width=3D15 height=3D15 id=3D"Picture_x0020_1"
src=3D"cid:[email protected]" alt=3D":)"><br>
<br>
My problem comes when I try to use the resulting list in a cheetah =
template,
namemapper can't find my object <img width=3D15 height=3D15 =
id=3D"Picture_x0020_2"
src=3D"cid:[email protected]" alt=3D":(">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! )<br>
<br>
here's the python side of things:<o:p></o:p></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

<p class=3DMsoNormal><code><span style=3D'font-size:10.0pt'>import
elementtree.ElementTree as ET</span></code><span =
style=3D'font-size:10.0pt;
font-family:"Courier New"'><br>
<code>from Cheetah.Template import Template </code><br>
<code>core=3D[]</code><br>
<br>
<code>#load config xml file as tree of elements</code><br>
<code>configtree=3DET.parse(&quot;/etc/ddmi/ddmi.conf&quot;)</code><br>
<br>
<code>#walk it and fill category lists</code><br>
<code>daemons=3Dconfigtree.find(&quot;daemons&quot;)</code><br>
<code>for daemon in&nbsp; daemons:</code><br>
<code>&nbsp; &nbsp;print daemon.tag</code><br>
<code>&nbsp; &nbsp;for member in daemon:</code><br>
<code>&nbsp; &nbsp;&nbsp; &nbsp;print member.text,
member.get(&quot;category&quot;), =
member.get(&quot;longname&quot;)</code><br>
<code>&nbsp; &nbsp;&nbsp; &nbsp;if member.get(&quot;category&quot;) =
=3D=3D
&quot;corecomm&quot; :</code><br>
<code>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; =
&nbsp;core.append(member)</code><br>
<code>&nbsp; &nbsp;&nbsp; &nbsp;else:</code><br>
<code>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;print (&quot;unknown
category&quot; , member) &nbsp; &nbsp;</code><br>
<code>&nbsp; &nbsp;&nbsp; &nbsp;</code><br>
<code>#do template stuff:</code><br>
<code>t =3D Template(file=3D&quot;stat.tmpl&quot;, =
searchList=3D[core])</code><br>
<code>print t<o:p></o:p></code></span></p>

<p class=3DMsoNormal><code><span =
style=3D'font-size:10.0pt'><o:p>&nbsp;</o:p></span></code></p>

<p class=3DMsoNormal><code><span =
style=3D'font-size:10.0pt'><o:p>&nbsp;</o:p></span></code></p>

<p class=3DMsoNormal>And here's a section of the =
template:<o:p></o:p></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

<p class=3DMsoNormal><code><span style=3D'font-size:10.0pt'>#for =
$corething in
$core</span></code><span style=3D'font-size:10.0pt;font-family:"Courier =
New"'><br>
<code>&lt;td id=3D&quot;${corething.text}_Test&quot;&gt;</code><br>
<code>&nbsp; &nbsp; &nbsp; &nbsp; &lt;div =
class=3D&quot;statusBoxBlue&quot;&gt;</code><br>
<code>&nbsp; &nbsp; &nbsp; &nbsp; ${corething.get(&quot;longname&quot;)}
untested</code><br>
<code>&nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;&nbsp; &nbsp;</code><br>
<code>&lt;/td&gt;</code><br>
<code>#end for<o:p></o:p></code></span></p>

<p class=3DMsoNormal><code><span =
style=3D'font-size:10.0pt'><o:p>&nbsp;</o:p></span></code></p>

<p class=3DMsoNormal><code><span =
style=3D'font-size:10.0pt'><o:p>&nbsp;</o:p></span></code></p>

<p class=3DMsoNormal><code><span =
style=3D'font-size:10.0pt'><o:p>&nbsp;</o:p></span></code></p>

<p class=3DMsoNormal>When I run the python (on gentoo, python 2.6.5 , =
cheetah
2.4.3 ) I get (after some printing of the elements ) :<o:p></o:p></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

<p class=3DMsoNormal><code><span style=3D'font-size:10.0pt'>Traceback =
(most recent
call last):</span></code><span =
style=3D'font-size:10.0pt;font-family:"Courier New"'><br>
<code>&nbsp; File &quot;pytest.py&quot;, line 21, in =
&lt;module&gt;</code><br>
<code>&nbsp; &nbsp; print t</code><br>
<code>&nbsp; File
&quot;/usr/lib/python2.6/site-packages/Cheetah/Template.py&quot;, line =
1005, in
__str__</code><br>
<code>&nbsp; &nbsp; rc =3D getattr(self, mainMethName)()</code><br>
<code>&nbsp; File &quot;_home_ddmi_stat_tmpl.py&quot;, line 85, in =
respond</code><br>
<code>NameMapper.NotFound: cannot find =
'core'<o:p></o:p></code></span></p>

<p class=3DMsoNormal><code><span =
style=3D'font-size:10.0pt'><o:p>&nbsp;</o:p></span></code></p>

<p class=3DMsoNormal><code><span =
style=3D'font-size:10.0pt'><o:p>&nbsp;</o:p></span></code></p>

<p class=3DMsoNormal><code><span =
style=3D'font-size:10.0pt'><o:p>&nbsp;</o:p></span></code></p>

<p class=3DMsoNormal><code><span style=3D'font-size:10.0pt'>Any ideas =
where I&#8217;m
going wrong?<o:p></o:p></span></code></p>

<p class=3DMsoNormal><code><span =
style=3D'font-size:10.0pt'><o:p>&nbsp;</o:p></span></code></p>

<p class=3DMsoNormal><code><span style=3D'font-size:10.0pt'>Many =
Thanks,<o:p></o:p></span></code></p>

<p class=3DMsoNormal><code><span =
style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;
Robin.<o:p></o:p></span></code></p>

<p class=3DMsoNormal><code><span =
style=3D'font-size:10.0pt'><o:p>&nbsp;</o:p></span></code></p>

<p class=3DMsoNormal><code><span =
style=3D'font-size:10.0pt'><o:p>&nbsp;</o:p></span></code></p>

<p class=3DMsoNormal><o:p>&nbsp;</o:p></p>

</div>

</body>

</html>

------_=_NextPart_002_01CB7FFB.7EC6E04F--

------_=_NextPart_001_01CB7FFB.7EC6E04F
Content-Type: image/gif;
	name="image001.gif"
Content-Transfer-Encoding: base64
Content-ID: <[email protected]>
Content-Description: image001.gif
Content-Location: image001.gif

R0lGODlhDwAPALMOAP/qAEVFRQAAAP/OAP/JAP+0AP6dAP/+k//9E///////xzMzM///6//lAAAA
AAAAACH5BAEAAA4ALAAAAAAPAA8AAARb0EkZap3YVabOGRcWcAgCnIMRTEEnCCfwpqt2mHEOagoO
nz+CKnADxoKFyiHHBBCSAdOiCVg8KwPZa7sVrgJZQWI8FhB2msGgwTXTWGqCXP4WBQr4wjDDstQm
EQA7

------_=_NextPart_001_01CB7FFB.7EC6E04F
Content-Type: image/gif;
	name="image002.gif"
Content-Transfer-Encoding: base64
Content-ID: <[email protected]>
Content-Description: image002.gif
Content-Location: image002.gif

R0lGODlhDwAPALMMAP/qAEVFRQAAAP/OAP/JAP6dAP+0AP/+k//9E///x//lAP//6wAAAAAAAAAA
AAAAACH5BAEAAAwALAAAAAAPAA8AAARYkEkZap2Y1ZXOGRcWcAgCnEMRTEEnnLCQrtrxwjGoJSZw
+yeCKnDo/W4EQ+WAawKSlZ4zqAwMpieFcGU9Cb7fp04zGPwACpmKVSa43bNMxUA3DDMsC20SAQA7

------_=_NextPart_001_01CB7FFB.7EC6E04F--


--===============3687891037511478792==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
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
--===============3687891037511478792==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

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

--===============3687891037511478792==--