# HG changeset patch # User Brian Neal # Date 1264913528 0 # Node ID 7071b196ddd54e18fb3db1e4fad97b7a5569237a # Parent e6d4dfdfbc64c793a8d709b431a100e25b6d2ba7 Implement #54; add a forum query to display a user's posts. diff -r e6d4dfdfbc64 -r 7071b196ddd5 gpp/forums/urls.py --- a/gpp/forums/urls.py Tue Jan 26 04:10:11 2010 +0000 +++ b/gpp/forums/urls.py Sun Jan 31 04:52:08 2010 +0000 @@ -19,6 +19,7 @@ url(r'^mod/topic/move/(\d+)/$', 'mod_topic_move', name='forums-mod_topic_move'), url(r'^mod/topic/split/(\d+)/$', 'mod_topic_split', name='forums-mod_topic_split'), url(r'^mod/topic/stick/(\d+)/$', 'mod_topic_stick', name='forums-mod_topic_stick'), + 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'^quick-reply/$', 'quick_reply_ajax', name='forums-quick_reply'), diff -r e6d4dfdfbc64 -r 7071b196ddd5 gpp/forums/views.py --- a/gpp/forums/views.py Tue Jan 26 04:10:11 2010 +0000 +++ b/gpp/forums/views.py Sun Jan 31 04:52:08 2010 +0000 @@ -13,6 +13,7 @@ from django.core.paginator import InvalidPage from django.shortcuts import get_object_or_404 from django.shortcuts import render_to_response +from django.shortcuts import redirect from django.template.loader import render_to_string from django.template import RequestContext from django.views.decorators.http import require_POST @@ -75,9 +76,11 @@ # check for special forum queries query = request.GET.get("query") if query == "unread": - return HttpResponseRedirect(reverse('forums-unread_topics')) + return redirect('forums-unread_topics') elif query == "unanswered": - return HttpResponseRedirect(reverse('forums-unanswered_topics')) + return redirect('forums-unanswered_topics') + elif query == "mine": + return redirect('forums-my_posts') forums = Forum.objects.forums_for_user(request.user) get_forum_unread_status(forums, request.user) @@ -697,6 +700,33 @@ context_instance=RequestContext(request)) +@login_required +def my_posts(request): + """Displays a list of posts the requesting user made.""" + + forum_ids = Forum.objects.forum_ids_for_user(request.user) + posts = Post.objects.filter(user=request.user, + topic__forum__id__in=forum_ids).order_by( + '-creation_date').select_related() + + paginator = create_post_paginator(posts) + page_num = get_page_num(request) + try: + page = paginator.page(page_num) + except InvalidPage: + raise Http404 + + # we do this for the template since it is rendered twice + page_nav = render_to_string('forums/pagination.html', {'page': page}) + + return render_to_response('forums/post_list.html', { + 'title': 'My Posts', + 'page': page, + 'page_nav': page_nav, + }, + context_instance=RequestContext(request)) + + def _can_moderate(forum, user): """ Determines if a user has permission to moderate a given forum. diff -r e6d4dfdfbc64 -r 7071b196ddd5 gpp/templates/forums/post_list.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gpp/templates/forums/post_list.html Sun Jan 31 04:52:08 2010 +0000 @@ -0,0 +1,30 @@ +{% extends 'base.html' %} +{% load forum_tags %} +{% block title %}Forums: {{ title }}{% endblock %} +{% block content %} +

Forums: {{ title }}

+

+SurfGuitar101 Forum Index » {{ title }} +

+
+{{ page_nav }} +{% if page.object_list %} +
+ {% for post in page.object_list %} +
+ {{ post.topic.forum.name }} » + {{ post.topic.name }} » + + {% forum_date post.creation_date user %} +
+
+ {{ post.html|safe }} +
+ {% endfor %} +
+{% else %} +

No posts found.

+{% endif %} +{{ page_nav }} +
+{% endblock %} diff -r e6d4dfdfbc64 -r 7071b196ddd5 media/css/base.css --- a/media/css/base.css Tue Jan 26 04:10:11 2010 +0000 +++ b/media/css/base.css Sun Jan 31 04:52:08 2010 +0000 @@ -309,3 +309,14 @@ #forum-query-form { text-align:right; } +#forums-post-list dt { + margin-top: 0.5em; + padding: 3px 0 3px 0; +} +#forums-post-list dd { + border: 1px solid #555; + padding: 0.5em 0.5em; +} +#forums-post-list dd.even { + background-color:#e5ecf9; +}