Define a templatetag to display list of tags and make them linked.
--- a/pytask/templates/task/view.html Tue Feb 01 15:02:52 2011 +0530
+++ b/pytask/templates/task/view.html Tue Feb 01 15:03:24 2011 +0530
@@ -52,13 +52,7 @@
<br /><br /><hr />
{% if task.tags.count %}
-
- Tags:
- {% for tag in task.tags %}
- {{tag}}
- {% endfor %}
- <hr />
-
+ Tags: {% as_tags task.tags %}<hr />
{% endif %}
{% if selected_users %}
--- a/pytask/templates/task/view_textbook.html Tue Feb 01 15:02:52 2011 +0530
+++ b/pytask/templates/task/view_textbook.html Tue Feb 01 15:03:24 2011 +0530
@@ -24,8 +24,7 @@
<hr />
{% if textbook.tags.count %}
- Tags: {{ textbook.tags_field }}
- <hr />
+ Tags: {% as_tags textbook.tags %}<hr />
{% endif %}
<h3>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pytask/templates/templatetags/_as_tags.html Tue Feb 01 15:03:24 2011 +0530
@@ -0,0 +1,5 @@
+<div id="tags">
+ {% for tag in tags %}
+ <a href="{% url view_tag tag.name %}">{{ tag }}</a>,
+ {% endfor %}
+</div>
\ No newline at end of file
--- a/pytask/templatetags/browse_helpers.py Tue Feb 01 15:02:52 2011 +0530
+++ b/pytask/templatetags/browse_helpers.py Tue Feb 01 15:03:24 2011 +0530
@@ -47,3 +47,13 @@
return {
'message': message,
}
+
+@register.inclusion_tag('templatetags/_as_tags.html')
+def as_tags(tags):
+ """Returns a context dictionary containing the fields necessary
+ to render list of tags.
+ """
+
+ return {
+ 'tags': tags,
+ }