# HG changeset patch # User David Soria Parra # Date 1235139153 -3600 # Node ID fb737a306703fa40f0093c772082fc949202dc9a # Parent 16ee6de925d167b3c676f36bf78409edfb859215 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. diff -r 16ee6de925d1 -r fb737a306703 hgscm/apps/www/templatetags/__init__.py diff -r 16ee6de925d1 -r fb737a306703 hgscm/apps/www/templatetags/extras.py --- /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 = "

Tricks

" + f.read() + "

" + f.close() + return result + +def do_mercurial_tricks (parser, token): + return MercurialTricksNode() + +register.tag('mercurial_tricks', do_mercurial_tricks) diff -r 16ee6de925d1 -r fb737a306703 hgscm/settings.py --- 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"), ) diff -r 16ee6de925d1 -r fb737a306703 hgscm/templates/about.html --- 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 %}
@@ -39,6 +40,7 @@ Mercurial 2.42 Windows XP | Vista | 7 + {% mercurial_tricks %}
diff -r 16ee6de925d1 -r fb737a306703 hgscm/templates/tricks/01 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hgscm/templates/tricks/01 Fri Feb 20 15:12:33 2009 +0100 @@ -0,0 +1,7 @@ +Reedit last commit message +
+$ hg qimport -r tip
+$ hg qrefresh -e
+.. edit ..
+$ hg qfinish -a
+
diff -r 16ee6de925d1 -r fb737a306703 hgscm/templates/tricks/02 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hgscm/templates/tricks/02 Fri Feb 20 15:12:33 2009 +0100 @@ -0,0 +1,8 @@ +Fold commits +
+$ hg qimport -r tip -n 'tofold.patch'
+$ hg qpop
+$ hg qimport -r tip
+$ hg qfold 'tofold.patch'
+$ hg qfinish -a
+