Hi
I would like to be able to get the inputs that are needed into a
template file programmaticall y.
For example if we had a template:
=============== ======
$name has $num marbles in his hand.
=============== ======
I want to be able to initialise this template and call a method on it
to get the list ['name', 'num']
Is there anything in cheetah which does this?
At present, I am sending a "fake" dictionary into the searchList to do
this. This is coded as.
fake = Generic()
t = Template(file=a bsFileName, searchList=[fake])
print fake.calledAtts
=============== =============== ===========
class Generic(object) :
""" Generic object can pretend to be a dictionary or a list and
doesn't throw
any errors whatever you call it for """
# def __new__(cls, *args, **kwargs):
# if '_inst' not in vars(cls):
# cls._inst = object.__new__( cls, *args, **kwargs)
# return cls._inst
calledAtts = sets.Set()
def __init__(self, *args, **kwargs):
pass
def __call__(self, *args, **kwargs):
return self
def __repr__(self):
return "Generic"
def __nonzero__(sel f):
return True
def __getattr__(sel f, name):
return self
__delattr__ = __getattr__
def __setattr__(sel f, name, value):
return self
def __len__(self):
return 1
def __iter__(self):
return iter(("Generic" ,))
def __getitem__(sel f, i):
if isinstance(i,ty pes.StringType) :
self.calledAtts .add(str(i))
return self
def __setitem__(sel f, i, v):
return self
def __contains__(se lf, itemName):
print "contains " + itemName
return True
def has_key(self, *args, **kwargs):
# print "has key called"
return True
__delitem__ = __getitem__
=============== =============== ==========
This just logs each access to the dictionary and stores the key under
self.calledAtts
But obviously this won't work if I have #if statements etc. I am hoping
cheetah already has this feature somewhere which is much more robust
but I can't find it.
Ajay 0 923 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Roger Jack |
last post by:
I have just finished reading Code Generation In Action which uses Ruby for
code generation. I would like to use Python instead. Is Cheetah the best
tool to use for templating source code files and then generating code? Is
there something more mature or better?
Thanks!
--
Roger Jack
Elegance Technologies, Inc.
|
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",...
|
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...
|
by: lloyd christopher |
last post by:
im developing a template based web application in perl and need some
guidance. currently its all pretty simple stuff, we tell the designers
place holders to use and then &username; or %USERNAME% or <MYusername/>
would be replaced by the value. basically what the perl cookbook uses in a
few examples iirc.
however more and more we have to deal with more complex data. variable
length lists of data. say for example a list of new products...
|
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
| |
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
|
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
|
by: John Salerno |
last post by:
I always have the desire to learn one thing well instead of split my
attention between several options, so I'm trying to decide which of
these two to start learning. Are there any particular things I should
look at when deciding between them, in terms of features, for example?
Do they do all the same things?
Thanks.
|
by: jmDesktop |
last post by:
Hi, I was using .net and it uses templates. I like that it did not
mix the UI with logic. I saw there are many templating engines for
php usage. Can you recommend one? I don' t know which to pursue. I
don't need MVC at the moment, but I don't know that the templating
engines require it either.
Thank you.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |