Mercurial > hg-website
changeset 77:fb737a306703
templatetags: Add mercurial_tricks templatetag
mercurial_tricks displays a random 'trick' from the templates/tricks/ directory.
The intention is to show the visitor various tricks around mercurial, how to
do certain things during browsing.
author | David Soria Parra <dsp@php.net> |
---|---|
date | Fri, 20 Feb 2009 15:12:33 +0100 |
parents | 16ee6de925d1 |
children | 8d25e34c21c2 |
files | hgscm/apps/www/templatetags/__init__.py hgscm/apps/www/templatetags/extras.py hgscm/settings.py hgscm/templates/about.html hgscm/templates/tricks/01 hgscm/templates/tricks/02 |
diffstat | 5 files changed, 43 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hgscm/apps/www/templatetags/extras.py Fri Feb 20 15:12:33 2009 +0100 @@ -0,0 +1,24 @@ +from django import template +from django.conf import settings +import random, os + +register = template.Library() + +class MercurialTricksNode(template.Node): + def __init__(self): + self._filename = self._random() + + def _random(self): + file = random.choice(os.listdir(settings.MERCURIAL_TRICKS)) + return os.path.join(settings.MERCURIAL_TRICKS, file) + + def render(self, context): + f = open(self._filename) + result = "<p><h3>Tricks</h3>" + f.read() + "</p>" + f.close() + return result + +def do_mercurial_tricks (parser, token): + return MercurialTricksNode() + +register.tag('mercurial_tricks', do_mercurial_tricks)
--- a/hgscm/settings.py Thu Feb 19 15:05:00 2009 +0100 +++ b/hgscm/settings.py Fri Feb 20 15:12:33 2009 +0100 @@ -67,6 +67,8 @@ ROOT_URLCONF = 'hgscm.urls' +MERCURIAL_TRICKS = os.path.join(BASE_DIR, "templates/tricks") + TEMPLATE_DIRS = ( os.path.join(BASE_DIR, "templates"), )
--- a/hgscm/templates/about.html Thu Feb 19 15:05:00 2009 +0100 +++ b/hgscm/templates/about.html Fri Feb 20 15:12:33 2009 +0100 @@ -1,5 +1,6 @@ {% extends "base.html" %} +{% load extras %} {% block content %} <div class="row"> @@ -39,6 +40,7 @@ Mercurial <em>2.42</em> <span>Windows XP | Vista | 7</span> </a> + {% mercurial_tricks %} </div> </div>