# HG changeset patch # User Madhusudan.C.S # Date 1296552706 -19800 # Node ID 3a86d85333a3bba5fab39f149fb45d7bf1cf7d88 # Parent 17c60a9c24396c43cda14079f110380e4bb59a6e Add a view to list all items tagged with a given tag name. diff -r 17c60a9c2439 -r 3a86d85333a3 pytask/taskapp/urls.py --- 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\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[\w. ]+)$', 'view_tag', name='view_tag'), +) diff -r 17c60a9c2439 -r 3a86d85333a3 pytask/taskapp/views/task.py --- 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)) diff -r 17c60a9c2439 -r 3a86d85333a3 pytask/templates/task/view_tag.html --- /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 %}