changeset 216:fe900598f81c

Implement #85 - display who has posted from a post's IP address.
author Brian Neal <bgneal@gmail.com>
date Sun, 30 May 2010 20:51:41 +0000
parents 8c1832b9d815
children 237710206167
files gpp/forums/urls.py gpp/forums/views.py gpp/templates/forums/display_post.html gpp/templates/forums/post_ip.html
diffstat 4 files changed, 39 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/forums/urls.py	Sat May 29 04:51:28 2010 +0000
+++ b/gpp/forums/urls.py	Sun May 30 20:51:41 2010 +0000
@@ -21,6 +21,7 @@
     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/ip/(\d+)/$', 'post_ip_info', name='forums-post_ip_info'),
     url(r'^post/new/(?P<topic_id>\d+)/$', 'new_post', name='forums-new_post'),
     url(r'^posts/(?P<username>[\w\d-]+)/$', 'posts_for_user', name='forums-posts_for_user'),
     url(r'^quick-reply/$', 'quick_reply_ajax', name='forums-quick_reply'),
--- a/gpp/forums/views.py	Sat May 29 04:51:28 2010 +0000
+++ b/gpp/forums/views.py	Sun May 30 20:51:41 2010 +0000
@@ -748,6 +748,24 @@
     return _user_posts(request, target_user, request.user, 'Posts by %s' % username)
 
 
+@login_required
+def post_ip_info(request, post_id):
+    """Displays information about the IP address the post was made from."""
+    post = get_object_or_404(Post.objects.select_related(), pk=post_id)
+
+    if not _can_moderate(post.topic.forum, request.user):
+        return HttpResponseForbidden("You don't have permission for this post.")
+
+    ip_users = sorted(set(Post.objects.filter(
+        user_ip=post.user_ip).values_list('user__username', flat=True)))
+
+    return render_to_response('forums/post_ip.html', {
+        'post': post,
+        'ip_users': ip_users,
+        },
+        context_instance=RequestContext(request))
+
+
 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
--- a/gpp/templates/forums/display_post.html	Sat May 29 04:51:28 2010 +0000
+++ b/gpp/templates/forums/display_post.html	Sun May 30 20:51:41 2010 +0000
@@ -27,7 +27,7 @@
       {% if post.unread %}<img src="{{ MEDIA_URL }}icons/new.png" alt="New" title="New" />{% endif %}
       <a href="{{ post.get_absolute_url }}"><img src="{{ MEDIA_URL }}icons/link.png" alt="Link" title="Link to this post" /></a>
          Posted on {% forum_date post.creation_date user %}
-         {% if can_moderate %}from IP: {{ post.user_ip }}{% endif %}
+         {% if can_moderate %}from IP: <a href="{% url forums-post_ip_info post.id %}">{{ post.user_ip }}</a>{% endif %}
       </div>
       <div class="forum-post-body">
          {{ post.html|safe }}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/templates/forums/post_ip.html	Sun May 30 20:51:41 2010 +0000
@@ -0,0 +1,19 @@
+{% extends 'base.html' %}
+{% block title %}Post IP Address Info: {{ post.user_ip }}{% endblock %}
+{% block content %}
+<h2>Post IP Address Info: {{ post.user_ip }}</h2>
+<p>
+This <a href="{{ post.get_absolute_url }}">post</a> was created by
+<a href="{% url bio-view_profile username=post.user.username %}">{{ post.user.username }}</a> from the IP address
+<a href="http://www.dnsstuff.com/tools/whois/?ip={{ post.user_ip }}">{{ post.user_ip }}</a>.
+</p>
+{% if ip_users %}
+<p>All users who have posted from {{ post.user_ip }}:</p>
+<ul>
+{% for user in ip_users %}
+<li><a href="{% url bio-view_profile username=user %}">{{ user }}</a>
+   (<a href="{% url forums-posts_for_user username=user %}">posts</a>)</li>
+{% endfor %}
+</ul>
+{% endif %}
+{% endblock %}