Cheetah template driven object output? Pythonically?

Discussion in 'Python' started by Fried Egg, Jan 30, 2006.

  1. Fried Egg

    Fried Egg Guest

    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.Template as T
    class Foo:
    def __init__(self, mystate, cheetah_template='./mytemplate.tmpl'):
    self.mystate = mystate
    self._template = T.compile(<stuff>)

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

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

    </pre>

    I guess that would work pretty well, though it is untested completely.
    Has anyone done anything fairly generic and similar? Pitfalls?
     
    Fried Egg, Jan 30, 2006
    #1
    1. Advertising

  2. 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.Template as T
    > class Foo:
    > def __init__(self, mystate, cheetah_template='./mytemplate.tmpl'):
    > self.mystate = mystate
    > self._template = T.compile(<stuff>)
    >
    > def set_state(self, newstate):
    > self.mystate = newstate
    >
    > def as_html(self):
    > print self._template(searchlist=<SOMETHING 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 ''.split('@')])"
     
    bruno at modulix, Jan 30, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brendan
    Replies:
    10
    Views:
    587
    Stefan Rank
    Nov 8, 2005
  2. Replies:
    0
    Views:
    289
  3. a
    Replies:
    0
    Views:
    288
  4. brianrpsgt1

    Compile Cheetah Template on Windows

    brianrpsgt1, Nov 24, 2007, in forum: Python
    Replies:
    3
    Views:
    667
    Tim Roberts
    Nov 30, 2007
  5. Replies:
    4
    Views:
    292
    Paul McGuire
    Feb 25, 2008
Loading...

Share This Page