changeset 169:7071b196ddd5

Implement #54; add a forum query to display a user's posts.
author Brian Neal <bgneal@gmail.com>
date Sun, 31 Jan 2010 04:52:08 +0000 (2010-01-31)
parents e6d4dfdfbc64
children 6f14970b103a
files gpp/forums/urls.py gpp/forums/views.py gpp/templates/forums/post_list.html media/css/base.css
diffstat 4 files changed, 74 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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<topic_id>\d+)/$', 'new_post', name='forums-new_post'),
     url(r'^quick-reply/$', 'quick_reply_ajax', name='forums-quick_reply'),
--- 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.
--- /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 %}
+<h2>Forums: {{ title }}</h2>
+<h3>
+<a href="{% url forums-index %}">SurfGuitar101 Forum Index</a> &raquo; {{ title }}
+</h3>
+<div class="forum-block">
+{{ page_nav }}
+{% if page.object_list %}
+<dl id="forums-post-list">
+   {% for post in page.object_list %}
+   <dt>
+      <a href="{{ post.topic.forum.get_absolute_url }}" title="Visit Forum">{{ post.topic.forum.name }}</a> &raquo;
+         <a href="{{ post.topic.get_absolute_url }}" title="Visit Topic">{{ post.topic.name }}</a> &raquo;
+         <a href="{{ post.get_absolute_url }}" title="View Post in Context">
+            {% forum_date post.creation_date user %}</a>
+   </dt>
+   <dd class="{% cycle 'odd' 'even' %}">
+      {{ post.html|safe }}
+   </dd>
+   {% endfor %}
+</dl>
+{% else %}
+   <h4>No posts found.</h4>
+{% endif %}
+{{ page_nav }}
+</div>
+{% endblock %}
--- 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;
+}