[stringtemplate-interest] Multimethods
Roman Odaisky
roma at qwertty.com
Sun Nov 9 07:17:27 PST 2008
Greetings,
I’m developing a site using Django and StringTemplate. It has so far been
wonderful.
However, a question has arisen which I seem unable to solve using the current
framework.
Following Django conventions, I add ‘get_absolute_url’ methods to model
classes. Then I use <a href="$something.absolute_url$"> to create links. That
allows me to change the URL layout of the site however I like, and links stay
correct. (The site is still under construction, so I don’t have to worry
about dangling references.) A typical construct is:
<p>You have the following gadgets and widgets:
<ul>
$user.allof_gadget:{g|
<li><p>$g.title$</p>
<ol>$g.allof_widget:{w|
<li><a href="$w.absolute_url$">$w$</a></li>
}$
</li>
}$
</ul></p>
However, some pages need URLs that refer to more than one item, neither of
which is deducible from the other. This one is similar to my needs:
https://bugs.launchpad.net/ubuntu/+source/linux-source-2.6.20/+bug/42160
So, what I need is to call a Python function that would determine a URL for
two items. How is it possible to invoke such a multimethod from within
StringTemplate? Can ST create templates that would call user-defined
functions, like this:
stg.defineTemplate("foo", foo)
def foo(**kwargs):
...do something
return something
and $foo(x=1, y=2)$ would call the function with the required keyword
arguments?
--
TIA
Roman.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2286 bytes
Desc: not available
Url : http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20081109/7641bd9e/attachment.bin
More information about the stringtemplate-interest
mailing list