logo       

Re: the "Cheetah files" (part 1): msg#00011

python.cheetah

Subject: Re: the "Cheetah files" (part 1)

Mike Orr wrote:

I've always done it this way. I think DTML has some special variables
to cover this situation, if I remember right. But whenever something
is "ugly", the easiest thing is to encapsulate it in a method:

$html_list([
"Item 1",
"Item 2",
], "<P> No message found,</P>")

where the method might be:

#def html_list($items, $messageIfNone=None, $listType='U'>
## $listType may be 'U' or 'O'.
#if $items
<${listType}L>
#for $item in $items
<LI> $item
#end for $item
</${listType}L>
#elif $messageIfNone
$messageIfNone
#end if $items
#end def html_list

ouch, this is not as clear as my solution. see mike, most of the times
i don't have a simple list to display, i have a list with a text an hyperlink and a datetime object to format for each item or a table row to populate... that's why i prefer to directly loop over the sequence and do whaterver is more appropriate for the context.

I would also use a method to generate the hyperlinks. My favorite is:

def href(url, label, quoteLabel=True, **attributes):
(...)


Here are a few other functions I use frequently:

def mailto(address, label=None):
label = label or address
if '@' in label and '@' not in address:
raise ValueError("arguments in wrong order")
return '<A HREF="mailto:%s";>%s</A>' % (address, label)

def chattyMailto(address, label):
if '@' in label and '@' not in address:
raise ValueError("arguments in wrong order")
return '%s &lt;<A HREF="mailto:%s";>%s</A>&gt;' % (label, address, address)


def menu1(*items):
"""A simple but elegant horizontal text menu (normally of hyperlinks)."""
return "&nbsp;|&nbsp;\n".join(items)

def anchor(name, quote=True):
"""Make the target of a "#fragment" URL."""
if quote:
name = quoteUrl(name)
return '<A NAME="%s"></A>' % name

these pretty great and general-purpose enough to copy/paste
on my projects ^__^

thanks a million.

later,
deelan







-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise