Add a view to list all items tagged with a given tag name.
--- a/pytask/taskapp/urls.py Tue Feb 01 04:50:18 2011 +0530
+++ b/pytask/taskapp/urls.py Tue Feb 01 15:01:46 2011 +0530
@@ -20,7 +20,6 @@
url(r'^submit/report/(?P<task_id>\d+)$', 'submit_report',
name='submit_report'),
url(r'^browse/$', 'browse_tasks', name='browse_tasks'),
- url(r'^suggest_tags/$', 'suggest_task_tags', name='suggest_task_tags'),
)
# URL patterns specific to textbook projects.
@@ -46,3 +45,9 @@
'view_chapter',
name='view_chapter'),
)
+
+# URL patterns specific to tags.
+urlpatterns += patterns('pytask.taskapp.views.task',
+ url(r'^tag/suggest/$', 'suggest_task_tags', name='suggest_task_tags'),
+ url(r'^tag/view/(?P<tag_name>[\w. ]+)$', 'view_tag', name='view_tag'),
+)
--- a/pytask/taskapp/views/task.py Tue Feb 01 04:50:18 2011 +0530
+++ b/pytask/taskapp/views/task.py Tue Feb 01 15:01:46 2011 +0530
@@ -24,6 +24,7 @@
from django.utils.translation import ugettext
from tagging.models import Tag
+from tagging.models import TaggedItem
from pytask.helpers import exceptions
from pytask.views import show_msg
@@ -655,3 +656,18 @@
json_response = json.dumps(response)
return http.HttpResponse(json_response)
+
+def view_tag(request, tag_name, template='task/view_tag.html'):
+ """View that displays all the tasks tagged with the given name
+ """
+
+ tag = Tag.objects.filter(name=tag_name)
+ tasks = TaggedItem.objects.get_by_model(taskapp_models.Task, tag)
+
+ context = {
+ 'tag_name': tag_name,
+ 'tasks': tasks,
+ }
+
+ return shortcuts.render_to_response(
+ template, RequestContext(request, context))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pytask/templates/task/view_tag.html Tue Feb 01 15:01:46 2011 +0530
@@ -0,0 +1,14 @@
+{% extends "base.html" %}
+
+
+{% load browse_helpers %}
+
+
+{% block title %}
+ {{ tag_name|capfirst }}
+{% endblock %}
+
+
+{% block content %}
+ {% as_list_tasks tasks tag_name %}
+{% endblock %}