[PATCH 1 of 2] Add "nonempty" template filter

Martin Geisler mg at daimi.au.dk
Sun Apr 5 06:10:03 CDT 2009


Rocco Rutte <pdmef at gmx.net> writes:

> # HG changeset patch
> # User Rocco Rutte <pdmef at gmx.net>
> # Date 1238927568 -7200
> # Node ID f5750b18bc83001b096bef156c2d81c7b9823df9
> # Parent  7b813bdbd5d072285af45e15cb95b80fd29268fa
> Add "nonempty" template filter
>
> It ensures at least "(none)" is returned in case the argument passed
> is None or ''. This is primarily useful to render empty changelog
> messages for hgweb but may be useful for others, too.

Good idea!

> diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
> --- a/mercurial/templatefilters.py
> +++ b/mercurial/templatefilters.py
> @@ -154,6 +154,11 @@ def json(obj):
>      else:
>          raise TypeError('cannot encode type %s' % obj.__class__.__name__)
>  
> +def nonempty(str):
> +    if str and str != '':

if str implies str != '' since the empty string is False in Python.

-- 
Martin Geisler

VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://selenic.com/pipermail/mercurial-devel/attachments/20090405/466b1fd8/attachment.pgp 


More information about the Mercurial-devel mailing list