473,662 Members | 2,596 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cheetah template driven object output? Pythonically?

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.Templat e as T
class Foo:
def __init__(self, mystate, cheetah_templat e='./mytemplate.tmpl '):
self.mystate = mystate
self._template = T.compile(<stuf f>)

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

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

</pre>

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

Jan 30 '06 #1
1 1137
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.Templat e as T
class Foo:
def __init__(self, mystate, cheetah_templat e='./mytemplate.tmpl '):
self.mystate = mystate
self._template = T.compile(<stuf f>)

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

def as_html(self):
print self._template( searchlist=<SOM ETHING 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 'o****@xiludom. gro'.split('@')])"
Jan 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1951
by: Timo Virkkala | last post by:
I tried to install Cheetah (0.9.15) and ran into trouble. When running the test suite, I get 61 failures and 57 errors. Most of the errors are "ImportError: No module named temp", with some "TypeError: update() takes exactly one argument (0 given)". The full output of the test suite is at (URL: http://www.cs.helsinki.fi/u/tjvirkka/out.txt ) I'd hate to spend hours debugging this thing, so I thought to ask here if someone has any ideas...
1
2405
by: Mike Grigorov | last post by:
I am using cheetah with jython 2.1 and I have problem generating templates that contain cyrillic text. Some texts are printed OK and others are not. I searched Jython and cheetah projects mailing lists on sourceforge.net as well as these groups and tried some other fixes proposed but without success. I call the template like this: PythonInterpreter pyiInterp = new PythonInterpreter(); pyiInterp.set("textTool",...
13
3513
by: Charlotte | last post by:
I am developing a web application and am looking for the best framework to do this in. I know this is an old question, and I have read the list archives and a couple of comparison pages on the web. I played around with some, and I have reduced my choices to two very different frameworks: cherrypy+cheetah and twisted+nevow. I am writing the prototype in cherrypy with cheetah, and I like it very much. I am very impressed with the speed of...
0
916
by: ajay.padala | last post by:
Hi I would like to be able to get the inputs that are needed into a template file programmatically. For example if we had a template: ===================== $name has $num marbles in his hand. =====================
1
1387
by: chun ping wang | last post by:
I am having trouble using cheetah and getting it to work the way i want (mvc) I have the following file. index.py : # imports BibleController and setting. BibleController.py that includes the Bible.py model to database (those works). At the end of it i have.
4
1350
by: Paolo Pantaleo | last post by:
I have a cheetah template something like this: x is: $x y is: $y z is: $z If for example $y is not defined I get an exception and the parsing of the template stops. Is there any way to substitute $y with an emty
2
1370
by: Sai Krishna M | last post by:
Hi, I have been working for some time developing web pages using python, modpython, cheetah. I find that this method has come inherent difficulties in it like if we want to generate a single page we have to write two separate files ( py & tmpl). Is there any other better way of doing things.? Also if we want to have partial processing of the pages, i.e, the
0
1190
by: manuel.reil | last post by:
Hello, currently i am developing a very small cms using python and cheetah. very early i have noticed that i was lacking the method to extract/recover the contents (html,text) from the html that is generated by cheetah and delivered to the site viewer. to explain it further: during the output processing by cheetah placeholders are replaced with my text/html input. to edit/alter the page i have to extract my personal input out of the...
1
3075
by: brianrpsgt1 | last post by:
Newbie here.... I have been able to successful pull info from a MySQL DB, get the results and output them in an HTML format using Cheetah to the screen using IDLE. I am doing this on a Windows Laptop, running WinXP, Python 2.5 and the latest version of Cheetah. I have two questions: 1. How and where do you compile Cheetah templates in Windows? The command in the docs is cheetah compile a, however, I believe that this
0
8345
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8768
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1999
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1754
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.