[Grok-dev] Conditional linking to static images
Luciano Ramalho
luciano at ramalho.org
Wed Jul 4 13:50:34 EDT 2007
On 7/3/07, Darryl Cousins <darryl at darrylcousins.net.nz> wrote:
> Would this be what you need?:
>
> os.path.join(os.path.dirname(__file__), 'static')
Thanks, Darryl. Leo Rochael was here last night and we discovered a
very elegant and Zope3-ish solution:
def coverUrl(self, name):
cover_name = 'covers/medium/'+name+'.jpg'
return self.static.get(cover_name,
self.static['covers/small-placeholder.jpg'])()
Initially we were confused by the API docs for DirectoryResource and
FileResource, but that is because they are very Pythonic and a lot of
their functionality is in their dictionary-like interface. And the
FileResource is called to render it's URL, which is also obvious after
we hit upon it (getting the URL is really the most common thing to do
with a static file).
I'm really thrilled to discover how much more pythonic Zope 3 compared
to Zope 2.
Cheers,
Luciano
More information about the Grok-dev
mailing list