Inheriting from a compiled cheetah template as part of a cherrypy URL tree?

View: New views
1 Messages — Rating Filter:   Alert me  

Inheriting from a compiled cheetah template as part of a cherrypy URL tree?

by Webb Sprague :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi List, and sorry for the double posting to the cherrypy list...

I have the compiled a simple template to index.py. I would like to
have a class that inherits this template and can thus know how to
display itself and transparently get to its attributes.  Here is what
I tried (if I leave out the "object" inheritance, I get the same
thing):

The template is the following (compiled with cheetah-compile):

$header
blah blah blah
$footer

The python code is:

import index    # the compiled template file
class Foo(index.index, object):
    def __init__(self):
        self.header = 'HEADER'
        self.footer = 'FOOTER'
        return None
foo = Foo()
print foo

I would like the last line to print the template with $header and
$footer filled in from the object attributes, but I get the following:

Traceback (most recent call last):
  File "/opt/local/lib/python2.5/site-packages/cherrypy/_cprequest.py",
line 606, in respond
    cherrypy.response.body = self.handler()
  File "/opt/local/lib/python2.5/site-packages/cherrypy/_cpdispatch.py",
line 24, in __call__
    return self.callable(*self.args, **self.kwargs)
  File "foo.py", line 41, in __call__
    return self.__str__()
  File "/opt/local/lib/python2.5/site-packages/Cheetah/Template.py",
line 982, in __str__
    def __str__(self): return getattr(self, mainMethName)()
  File "index.py", line 73, in respond
    if (not trans and not self._CHEETAH__isBuffering and not
callable(self.transaction)):
AttributeError: 'Index' object has no attribute '_CHEETAH__isBuffering'

My rationale is that here the object "index" is a complete entity in a
cherrypy tree: url, methods, and a template for display (there would
also be a database connection).

I would also like my child class be able to define its own __init__
method, so dropping that method and writing index.footer = 'footer'
(etc) won't cut it.

Could anyone give me pointers?  Perhaps my design is wacked, perhaps I
need a little metaclass magic I don't know about, etc?

Thanks to all!

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users@...
To unsubscribe from this group, send email to cherrypy-users+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---

LightInTheBox - Buy quality products at wholesale price!