I've posted a patch at the trac which would allow you to access the
template string.

This would work:

class MyTable(W.TableForm):
  def __init__(self, name=None, **kw):
    super(MyTable, self).__init__(name, **kw)
    template = self.template
    # modify template as you feel ...
    self.template = template

I know it's not exactly the use case you described (modify the template
at class declaration), but I just noticed that when I was writing this
message :/

It's at:
http://trac.turbogears.org/turbogears/attachment/ticket/536/template_as_a_string.patch

It passes all unittests but some more (real-world and unit) testing
should be needed. Give it a try see if it helps

Regards, Alberto

Alberto Valverde wrote:

> >
> > How can I get at a widget's template text.  I first tried
> > TableForm.template, but it's a type, not a string.  Lovely metaclass
> > black magic.
> >
> > I'm trying to create a slightly varied TableForm, but I want to build
> > on the existing template so when it's changed or updated, my variant is
> > updated also.  Something like this:
> >
> > class MyTableForm(TableForm):
> >     template = "<a href="">blah</a><br />" + TableForm.template
> >
> > Of course this doesn't work.  Any ideas?
> >
> > Randall
> >
> >
>
> Hi Randall,
>
> cls.template get's compiled when the class is created (yeah, lovely
> metaclass black magic ;), which means its a kid.Template instance once the
> class is loaded. Right now there's no way to do what you want (maybe
> digging into the Template instance's kid internals, I dunno..., however,
> it would be ver hackish)
>
> RFC:
>
> Maybe whe should save the original template string at cls.template and a
> compiled version at cls._template_c, with a property that transparently
> compiles the string into the private attribute every time it's set? (for
> faster display, etc...)
> 
> Alberto

Reply via email to