# HG changeset patch # User Arne Babenhauserheide # Date 1242107749 -7200 # Node ID ab7622757bd7bb53ed13c5e04def41c2fdcdf659 # Parent cb721033390b4d0b6e18b7af81d11de33856caf5 Added tag "random_quote" to webapp: One random quote. diff -r cb721033390b -r ab7622757bd7 hgscm/apps/www/templatetags/extras.py --- a/hgscm/apps/www/templatetags/extras.py Tue May 12 07:32:44 2009 +0200 +++ b/hgscm/apps/www/templatetags/extras.py Tue May 12 07:55:49 2009 +0200 @@ -34,6 +34,16 @@ f.close() return result +class RandomQuoteNode(template.Node): + def __init__(self): + pass + + def render(self, context): + f = open(self._filename) + quote, author = random.choice(f.readlines()).split(" - ") + result = "

" + quote + "" + " - " + author + "

" + return result + class DownloadButtonNode(template.Node): def __init__(self, extended): self._extended = extended @@ -57,10 +67,14 @@ def do_mercurial_tricks_advanced (parser, token): return MercurialTricksAdvancedNode() +def do_random_quote (parser, token): + return RandomQuoteNode() + def do_download_button(parser, token): extended = len(token.split_contents()) > 1 return DownloadButtonNode(extended) register.tag('mercurial_tricks', do_mercurial_tricks) register.tag('mercurial_tricks_advanced', do_mercurial_tricks_advanced) +register.tag('random_quote', do_random_quote) register.tag('download_button', do_download_button) diff -r cb721033390b -r ab7622757bd7 hgscm/settings.py --- a/hgscm/settings.py Tue May 12 07:32:44 2009 +0200 +++ b/hgscm/settings.py Tue May 12 07:55:49 2009 +0200 @@ -71,6 +71,8 @@ MERCURIAL_TRICKS_ADVANCED = os.path.join(BASE_DIR, "templates/tricks_advanced") +MERCURIAL_QUOTES = os.path.join(BASE_DIR, "templates/quotes.txt") + TEMPLATE_DIRS = ( os.path.join(BASE_DIR, "templates"), )