# HG changeset patch
# User Brian Neal
# Date 1239847217 0
# Node ID 777451a98f9d4b068f5e8bc6017bbb35b8caee22
# Parent f408971657b9788644f90f9c3c128f0816779f3a
Shoutbox work: shouts now have absolute URLs. Shouts can now be flagged as abuse. Minor tweak to breadcrumbs css. Added flag date to comments admin.
diff -r f408971657b9 -r 777451a98f9d gpp/comments/admin.py
--- a/gpp/comments/admin.py Wed Apr 15 01:13:17 2009 +0000
+++ b/gpp/comments/admin.py Thu Apr 16 02:00:17 2009 +0000
@@ -25,7 +25,7 @@
raw_id_fields = ('user', 'content_type')
class CommentFlagAdmin(admin.ModelAdmin):
- list_display = ('__unicode__', 'get_comment_url')
+ list_display = ('__unicode__', 'flag_date', 'get_comment_url')
admin.site.register(Comment, CommentAdmin)
admin.site.register(CommentFlag, CommentFlagAdmin)
diff -r f408971657b9 -r 777451a98f9d gpp/shoutbox/admin.py
--- a/gpp/shoutbox/admin.py Wed Apr 15 01:13:17 2009 +0000
+++ b/gpp/shoutbox/admin.py Thu Apr 16 02:00:17 2009 +0000
@@ -3,9 +3,17 @@
"""
from django.contrib import admin
from shoutbox.models import Shout
+from shoutbox.models import ShoutFlag
class ShoutAdmin(admin.ModelAdmin):
- list_display = ('shout_date', '__unicode__')
- raw_id_fields = ('user', )
+ list_display = ('shout_date', '__unicode__')
+ raw_id_fields = ('user', )
+
+class ShoutFlagAdmin(admin.ModelAdmin):
+ list_display = ('__unicode__', 'flag_date', 'get_shout_url')
+
admin.site.register(Shout, ShoutAdmin)
+admin.site.register(ShoutFlag, ShoutFlagAdmin)
+
+# vim: ts=4 sw=4
diff -r f408971657b9 -r 777451a98f9d gpp/shoutbox/models.py
--- a/gpp/shoutbox/models.py Wed Apr 15 01:13:17 2009 +0000
+++ b/gpp/shoutbox/models.py Thu Apr 16 02:00:17 2009 +0000
@@ -4,14 +4,38 @@
from django.db import models
from django.contrib.auth.models import User
+
class Shout(models.Model):
- user = models.ForeignKey(User)
- shout_date = models.DateTimeField(auto_now_add=True)
- shout = models.TextField()
+ user = models.ForeignKey(User)
+ shout_date = models.DateTimeField(auto_now_add=True)
+ shout = models.TextField()
- def __unicode__(self):
- shout = self.shout[:60]
- return u'Shout from %s: %s' % (self.user.username, shout)
+ @models.permalink
+ def get_absolute_url(self):
+ return ('shoutbox-view', [str(self.id)])
- class Meta:
- ordering = ('-shout_date', )
+ def __unicode__(self):
+ shout = self.shout[:60]
+ return u'Shout from %s: %s' % (self.user.username, shout)
+
+ class Meta:
+ ordering = ('-shout_date', )
+
+
+class ShoutFlag(models.Model):
+ """This model represents a user flagging a shout as inappropriate."""
+ user = models.ForeignKey(User)
+ shout = models.ForeignKey(Shout)
+ flag_date = models.DateTimeField(auto_now_add=True)
+
+ def __unicode__(self):
+ return u'Shout ID %s flagged by %s' % (self.shout_id, self.user.username)
+
+ class Meta:
+ ordering = ('flag_date', )
+
+ def get_shout_url(self):
+ return 'Shout' % self.shout.id
+ get_shout_url.allow_tags = True
+
+# vim: ts=4 sw=4
diff -r f408971657b9 -r 777451a98f9d gpp/shoutbox/urls.py
--- a/gpp/shoutbox/urls.py Wed Apr 15 01:13:17 2009 +0000
+++ b/gpp/shoutbox/urls.py Thu Apr 16 02:00:17 2009 +0000
@@ -7,7 +7,11 @@
urlpatterns = patterns('shoutbox.views',
url(r'^delete/$', 'delete', name='shoutbox-delete'),
url(r'^edit/$', 'edit', name='shoutbox-edit'),
+ url(r'^flag/$', 'flag', name='shoutbox-flag'),
url(r'^shout/$', 'shout', name='shoutbox-shout'),
url(r'^text/$', 'text', name='shoutbox-text'),
- url(r'^view/(?P\d+)/$', 'view', name='shoutbox-view'),
+ url(r'^view/(\d+)/$', 'view_shout', name='shoutbox-view'),
+ url(r'^view/history/(?P\d+)/$', 'view_history', name='shoutbox-history'),
)
+
+# vim: ts=4 sw=4
diff -r f408971657b9 -r 777451a98f9d gpp/shoutbox/views.py
--- a/gpp/shoutbox/views.py Wed Apr 15 01:13:17 2009 +0000
+++ b/gpp/shoutbox/views.py Thu Apr 16 02:00:17 2009 +0000
@@ -13,8 +13,10 @@
from django.views.decorators.http import require_POST
from core.paginator import DiggPaginator
+from core.functions import email_admins
from shoutbox.forms import ShoutBoxForm
from shoutbox.models import Shout
+from shoutbox.models import ShoutFlag
SHOUTS_PER_PAGE = 10
@@ -33,7 +35,21 @@
context_instance = RequestContext(request))
-def view(request, page=1):
+def view_shout(request, id):
+ """This view is for viewing an individual shout."""
+ try:
+ shout = Shout.objects.get(pk=id)
+ except Shout.DoesNotExist:
+ return render_to_response('shoutbox/missing_shout.html', {},
+ context_instance = RequestContext(request))
+
+ return render_to_response('shoutbox/view_shout.html', {
+ 'shout': shout,
+ },
+ context_instance = RequestContext(request))
+
+
+def view_history(request, page=1):
"""This view allows one to view the shoutbox history."""
paginator = DiggPaginator(Shout.objects.all(), SHOUTS_PER_PAGE, body=5, tail=3, margin=3, padding=2)
try:
@@ -107,4 +123,32 @@
return HttpResponseForbidden()
+
+@require_POST
+def flag(request):
+ """
+ This function handles the flagging of shouts by users. This function should
+ be the target of an AJAX post.
+ """
+ if not request.user.is_authenticated():
+ return HttpResponse('Please login or register to flag a shout.')
+
+ id = request.POST.get('id', None)
+ if id is None:
+ return HttpResponseBadRequest('No id')
+
+ try:
+ shout = Shout.objects.get(pk=id)
+ except Shout.DoesNotExist:
+ return HttpResponseBadRequest('No shout with id %s' % id)
+
+ flag = ShoutFlag(user=request.user, shout=shout)
+ flag.save()
+ email_admins('A Shout Has Been Flagged', """Hello,
+
+A user has flagged a shout for review.
+""")
+ return HttpResponse('The shout was flagged. A moderator will review the shout shortly. ' \
+ 'Thanks for helping to improve the quality of this site.')
+
# vim: ts=4 sw=4
diff -r f408971657b9 -r 777451a98f9d gpp/templates/shoutbox/missing_shout.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/templates/shoutbox/missing_shout.html Thu Apr 16 02:00:17 2009 +0000
@@ -0,0 +1,7 @@
+{% extends 'base.html' %}
+{% block title %}Shout Not Found{% endblock %}
+{% block content %}
+
+Shout Not Found
+We're sorry, it looks like that shout no longer exists.
+{% endblock %}
diff -r f408971657b9 -r 777451a98f9d gpp/templates/shoutbox/shout_detail.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/templates/shoutbox/shout_detail.html Thu Apr 16 02:00:17 2009 +0000
@@ -0,0 +1,21 @@
+{% load avatar_tags %}
+{% load smiley_tags %}
+
+
+{% avatar shout.user %}
+{{ shout.user.username }}
+ |
+
+ {{ shout.shout|smilify|urlize }}
+
+
+{{ shout.shout_date|date:"D M d Y H:i:s" }}
+
+
+{% ifequal user shout.user %}
+
+{% endifequal %}
+ |
+
diff -r f408971657b9 -r 777451a98f9d gpp/templates/shoutbox/shoutbox.html
--- a/gpp/templates/shoutbox/shoutbox.html Wed Apr 15 01:13:17 2009 +0000
+++ b/gpp/templates/shoutbox/shoutbox.html Thu Apr 16 02:00:17 2009 +0000
@@ -11,7 +11,7 @@
{% endfor %}
-Shout History
+Shout History
{% if user.is_authenticated %}