Re: Clearsilver with CherryPy

Brandon Long <[email protected]> Mon, 20 Apr 2009 12:30:00 -0700
Newsgroups gmane.text.clearsilver.general
Organization Fiction L Networks
Message-ID <20090420193000.GA12250@bl1>
Although I haven't used CherryPy, there is nothing to prevent you from
using ClearSilver without the CGI trappings.

You definitely don't need to have all of your HDF data in HDF files.
Sometimes there is static data, and the HDF files make that easy.

If you aren't using the CGI wrappings in neo_cgi, you can do something
like:

# You still need to load neo_cgi, because the other two modules are
# fakes actually located in neo_cgi, a probably poor design decision
import neo_cgi, neo_cs, neo_util

hdf = neo_util.HDF()
cs = neo_cs.CS(hdf)
cs.parseFile(template_file)
cs.render()

As for getting data into the HDF, there is hdf.setValue(k,v) which
takes strings for key and value.

It shouldn't be hard to write functions that convert various python
datatypes into hdf, ie for a dictionary:

for (k, v) in dict.items():
  hdf.setValue("%s.%s" % (prefix, k), v)

or for a list:

for x in range(length(array)):
  hdf.setValue("%s.%d" % (prefix, x), array[x])

There's also a simple ORM in the codebase in python/examples/base called
odb, with a row object in hdfhelp.py which exports rows from a database
by making them into a prefix.colname=value format.

Brandon

Oe 04/20/09 vsapre80 uttered the following other thing:
> Hi,
> 
> Has anyone worked here with Clearsilver (using its python wrapper) and
> CherryPy?
> 
> I would like to make a simple application using ClearSilver as the
> templating engine.
> 
> The examples on ClearSilver website seem to be using CGI
> very much... can we use ClearSilver otherwise also?
> 
> Is it necessary that the data to be presented should be available as
> an HDF file?  I would like to do this at runtime...which is why we are
> using the templating system in the first place.  I am confused about
> how to hand-off the data from the database using Python, assuming we
> get the data into some local variables...and then make an HDF out of
> it(would that be a Python dictionary)...and then pass this to the
> neo_util.CS()?  any help would be great!!
> 
> Thanks and best regards, Vishal Sapre

-- 
  "He felt that his whole life was some kind of dream and he sometimes
    wondered whose it was and whether they were enjoying it."
                -- Douglas Adams         http://www.fiction.net/blong/