Loading ...
Sorry, an error occurred while loading the content.

[Cheetahtemplate-discuss] Inheriting from a compiled cheetah template as part of a cherrypy URL tree?

Expand Messages
  • Webb Sprague
    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
    Message 1 of 1 , Sep 27, 2008
    • 0 Attachment
      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!

      -------------------------------------------------------------------------
      This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
      Build the coolest Linux based applications with Moblin SDK & win great prizes
      Grand prize is a trip for two to an Open Source event anywhere in the world
      http://moblin-contest.org/redirect.php?banner_id=100&url=/
      _______________________________________________
      Cheetahtemplate-discuss mailing list
      Cheetahtemplate-discuss@...
      https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
    Your message has been successfully submitted and would be delivered to recipients shortly.