summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Seguin <guillaume@segu.in>2008-04-07 12:49:42 +0200
committerGuillaume Seguin <guillaume@segu.in>2008-04-07 12:49:42 +0200
commit06d185cd5222c1781a135f262d44eadb160bdd2d (patch)
tree39ef3e50181ccaa9dde3c21bdad8c2f9d5c24be9
parent6cb8999c2bdd24e57b88293d26c6be1f6e3d1d7a (diff)
downloadmarks-06d185cd5222c1781a135f262d44eadb160bdd2d.tar.gz
marks-06d185cd5222c1781a135f262d44eadb160bdd2d.tar.bz2
* Modify rounded_block_start tag to be able to include variables in the title
-rw-r--r--main/templatetags/marks_tags.py49
-rw-r--r--templates/main/home.html12
2 files changed, 40 insertions, 21 deletions
diff --git a/main/templatetags/marks_tags.py b/main/templatetags/marks_tags.py
index 783d27a..1bcaf30 100644
--- a/main/templatetags/marks_tags.py
+++ b/main/templatetags/marks_tags.py
@@ -21,22 +21,41 @@ from django import template
register = template.Library ()
-@register.simple_tag
-def rounded_block_start (classes, title):
- base = '''<div class="%s">
- <b class="block-bg">
- <b class="block-bg1"><b></b></b>
- <b class="block-bg2"><b></b></b>
- <b class="block-bg3"></b>
- <b class="block-bg4"></b>
- <b class="block-bg5"></b></b>
-
- <div class="block-bgfg block">
-''' % classes
- if title:
- return "%s<h3>%s</h3>" % (base, title)
+@register.tag (name = "rounded_block_start")
+def do_upper (parser, token):
+ try:
+ classes = token.split_contents ()[1:]
+ except ValueError:
+ classes = []
+ if type (classes) == type ([]):
+ classes = " ".join (map (lambda s: s[1:-1], classes))
else:
- return base
+ classes = classes[1:-1]
+ nodelist = parser.parse (("end_rounded_block_start",))
+ parser.delete_first_token ()
+ return RoundedBlockStartNode (classes, nodelist)
+
+class RoundedBlockStartNode (template.Node):
+
+ def __init__ (self, classes, nodelist):
+ self.classes = classes
+ self.nodelist = nodelist
+
+ def render (self, context):
+ base = '''<div class="%s">
+ <b class="block-bg">
+ <b class="block-bg1"><b></b></b>
+ <b class="block-bg2"><b></b></b>
+ <b class="block-bg3"></b>
+ <b class="block-bg4"></b>
+ <b class="block-bg5"></b></b>
+
+ <div class="block-bgfg block">''' % self.classes
+ output = self.nodelist.render (context)
+ if output:
+ return "%s<h3>%s</h3>" % (base, output % context)
+ else:
+ return base
@register.simple_tag
def rounded_block_end ():
diff --git a/templates/main/home.html b/templates/main/home.html
index 921aa9e..79cd1f5 100644
--- a/templates/main/home.html
+++ b/templates/main/home.html
@@ -2,7 +2,7 @@
{% load marks_tags %}
{% block content %}
-{% rounded_block_start 'halfblock' 'Ajouter une épreuve' %}
+{% rounded_block_start 'halfblock' %}Ajouter une épreuve{% end_rounded_block_start %}
<div class="blockcontent">
<form method="post" action="/">
<ul>
@@ -15,7 +15,7 @@
</form>
</div>
{% rounded_block_end %}
-{% rounded_block_start 'halfblock' 'Épreuves' %}
+{% rounded_block_start 'halfblock' %}Épreuves{% end_rounded_block_start %}
{% if exams %}
<div class="blockcontent">
<ul>
@@ -27,7 +27,7 @@
{% endif %}
{% rounded_block_end %}
<div class="spacer"></div>
-{% rounded_block_start 'halfblock' 'Ajouter un jeu de coefficients' %}
+{% rounded_block_start 'halfblock' %}Ajouter un jeu de coefficients{% end_rounded_block_start %}
<div class="blockcontent">
<form method="post" action="/">
<ul>
@@ -40,7 +40,7 @@
</form>
</div>
{% rounded_block_end %}
-{% rounded_block_start 'halfblock' 'Jeux de coefficients' %}
+{% rounded_block_start 'halfblock' %}Jeux de coefficients{% end_rounded_block_start %}
{% if ratings %}
<div class="blockcontent">
<ul>
@@ -52,7 +52,7 @@
{% endif %}
{% rounded_block_end %}
<div class="spacer"></div>
-{% rounded_block_start 'halfblock' 'Ajouter un jeu de notes' %}
+{% rounded_block_start 'halfblock' %}Ajouter un jeu de notes{% end_rounded_block_start %}
<div class="blockcontent">
<form method="post" action="/">
<ul>
@@ -65,7 +65,7 @@
</form>
</div>
{% rounded_block_end %}
-{% rounded_block_start 'halfblock' 'Jeux de notes' %}
+{% rounded_block_start 'halfblock' %}Jeux de notes{% end_rounded_block_start %}
{% if marks %}
<div class="blockcontent">
<ul>