Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Cheetah template driven object output? Pythonically?

Reply
Thread Tools

Cheetah template driven object output? Pythonically?

 
 
Fried Egg
Guest
Posts: n/a
 
      01-30-2006
This may be trivial or stupid or both, but does anyone have a recipe
for gracefully using Cheetah to generate a text representation of an
object, but embedded in the object (so that it can be pickled,
unpickled, and told to display itself)?

Here is what I am thinking:

<pre>

import Cheetah.Template as T
class Foo:
def __init__(self, mystate, cheetah_template='./mytemplate.tmpl'):
self.mystate = mystate
self._template = T.compile(<stuff>)

def set_state(self, newstate):
self.mystate = newstate

def as_html(self):
print self._template(searchlist=<SOMETHING GENERIC>)

</pre>

I guess that would work pretty well, though it is untested completely.
Has anyone done anything fairly generic and similar? Pitfalls?

 
Reply With Quote
 
 
 
 
bruno at modulix
Guest
Posts: n/a
 
      01-30-2006
Fried Egg wrote:
> This may be trivial or stupid or both, but does anyone have a recipe
> for gracefully using Cheetah to generate a text representation of an
> object, but embedded in the object (so that it can be pickled,
> unpickled, and told to display itself)?
>
> Here is what I am thinking:
>
> <pre>
>
> import Cheetah.Template as T
> class Foo:
> def __init__(self, mystate, cheetah_template='./mytemplate.tmpl'):
> self.mystate = mystate
> self._template = T.compile(<stuff>)
>
> def set_state(self, newstate):
> self.mystate = newstate
>
> def as_html(self):
> print self._template(searchlist=<SOMETHING GENERIC>)
>
> </pre>
>
> I guess that would work pretty well, though it is untested completely.
> Has anyone done anything fairly generic and similar? Pitfalls?
>


I don't know if may be of any help, but David Mertz has done something
related (pickling/unpickling) with XML and metaclasses:

http://gnosis.cx/download/gnosis/


--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '(E-Mail Removed)'.split('@')])"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compile Cheetah Template on Windows brianrpsgt1 Python 3 11-30-2007 05:00 AM
cheetah - how do i use .refreshcaceh() in cheetah a Python 0 06-29-2006 04:02 AM
cheetah templating: place holders needed in a template ajay.padala@gmail.com Python 0 04-12-2006 05:31 PM
Seagate Cheetah 15K.4 ST3146854LC SCSI Hard Drive @ InsaneTe Silverstrand Front Page News 0 07-21-2005 02:13 PM
Cheetah best for templating? Roger Jack Python 5 01-05-2004 07:34 AM



Advertisments