# HG changeset patch # User Brian Neal # Date 1267395615 0 # Node ID 0fa78ef8035603511e1b1864668344960a6a3b77 # Parent b1766b1bda450716193b70c445346c59f15bf76c Implementing #55 - Add function to view a users posts from their profile. diff -r b1766b1bda45 -r 0fa78ef80356 gpp/forums/urls.py --- a/gpp/forums/urls.py Fri Feb 12 04:24:47 2010 +0000 +++ b/gpp/forums/urls.py Sun Feb 28 22:20:15 2010 +0000 @@ -22,6 +22,7 @@ url(r'^my-posts/$', 'my_posts', name='forums-my_posts'), url(r'^post/(\d+)/$', 'goto_post', name='forums-goto_post'), url(r'^post/new/(?P\d+)/$', 'new_post', name='forums-new_post'), + url(r'^posts/(?P[\w\d-]+)/$', 'posts_for_user', name='forums-posts_for_user'), url(r'^quick-reply/$', 'quick_reply_ajax', name='forums-quick_reply'), url(r'^unanswered/$', 'unanswered_topics', name='forums-unanswered_topics'), url(r'^unread/$', 'unread_topics', name='forums-unread_topics'), diff -r b1766b1bda45 -r 0fa78ef80356 gpp/forums/views.py --- a/gpp/forums/views.py Fri Feb 12 04:24:47 2010 +0000 +++ b/gpp/forums/views.py Sun Feb 28 22:20:15 2010 +0000 @@ -4,6 +4,7 @@ import datetime from django.contrib.auth.decorators import login_required +from django.contrib.auth.models import User from django.http import Http404 from django.http import HttpResponse from django.http import HttpResponseBadRequest @@ -714,9 +715,25 @@ @login_required def my_posts(request): """Displays a list of posts the requesting user made.""" + return _user_posts(request, request.user, request.user, 'My Posts') - forum_ids = Forum.objects.forum_ids_for_user(request.user) - posts = Post.objects.filter(user=request.user, + +@login_required +def posts_for_user(request, username): + """Displays a list of posts by the given user. + Only the forums that the requesting user can see are examined. + """ + target_user = get_object_or_404(User, username=username) + return _user_posts(request, target_user, request.user, 'Posts by %s' % username) + + +def _user_posts(request, target_user, req_user, page_title): + """Displays a list of posts made by the target user. + req_user is the user trying to view the posts. Only the forums + req_user can see are searched. + """ + forum_ids = Forum.objects.forum_ids_for_user(req_user) + posts = Post.objects.filter(user=target_user, topic__forum__id__in=forum_ids).order_by( '-creation_date').select_related() @@ -731,7 +748,7 @@ page_nav = render_to_string('forums/pagination.html', {'page': page}) return render_to_response('forums/post_list.html', { - 'title': 'My Posts', + 'title': page_title, 'page': page, 'page_nav': page_nav, }, diff -r b1766b1bda45 -r 0fa78ef80356 gpp/templates/bio/view_profile.html --- a/gpp/templates/bio/view_profile.html Fri Feb 12 04:24:47 2010 +0000 +++ b/gpp/templates/bio/view_profile.html Sun Feb 28 22:20:15 2010 +0000 @@ -65,6 +65,8 @@ {% if user.is_authenticated %}