changeset 148:ab7622757bd7

Added tag "random_quote" to webapp: One random quote.
author Arne Babenhauserheide <bab@draketo.de>
date Tue, 12 May 2009 07:55:49 +0200
parents cb721033390b
children 2d6b15433c60
files hgscm/apps/www/templatetags/extras.py hgscm/settings.py
diffstat 2 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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 = "<p><em>" + quote + "</em>" + " - " + author + "</p>"
+        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)
--- 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"),
 )