Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[django-website] Added spam protection via James Bennet's nifty comme…

…nt_utils app.

git-svn-id: http://code.djangoproject.com/svn/djangoproject.com@6472 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 87a26617abc361cb521165c3974fd21ef5867aaa 1 parent 94e15d0
jacob authored
View
13 django_website/apps/blog/models.py
@@ -1,4 +1,6 @@
+import datetime
from django.db import models
+from comment_utils.moderation import CommentModerator, moderator
class Entry(models.Model):
pub_date = models.DateTimeField()
@@ -22,3 +24,14 @@ def __unicode__(self):
def get_absolute_url(self):
return "/weblog/%s/%s/" % (self.pub_date.strftime("%Y/%b/%d").lower(), self.slug)
+
+ @property
+ def comments_enabled(self):
+ delta = datetime.datetime.now() - self.pub_date
+ return delta.days < 60
+
+class EntryModerator(CommentModerator):
+ akismet = True
+ enable_field = "comments_enabled"
+
+moderator.register(Entry, EntryModerator)
View
6 django_website/settings.py
@@ -47,6 +47,7 @@
'django_website.apps.docs',
'django_website.apps.aggregator',
'registration',
+ 'comment_utils',
)
ADMIN_MEDIA_PREFIX = 'http://media.djangoproject.com/admin/'
MEDIA_ROOT = "/home/html/djangoproject.com/m/"
@@ -74,4 +75,7 @@
USE_I18N = False
# django-registration settings
-ACCOUNT_ACTIVATION_DAYS = 3
+ACCOUNT_ACTIVATION_DAYS = 3
+
+# comment_utils settings
+AKISMET_API_KEY = "c892e4962244"
View
4 django_website/templates/blog/entry_archive.html
@@ -2,12 +2,12 @@
{% block content %}
-{% load comments.comments %}
+{% load comments comment_utils %}
<h1>Latest entries</h1>
{% for object in latest %}
- {% get_free_comment_count for blog.entry object.id as comment_count %}
+ {% get_public_free_comment_count for blog.entry object.id as comment_count %}
<h2><a href="{{ object.get_absolute_url }}">{{ object.headline }}</a></h2>
{{ object.body }}
<p class="date small">Posted by <strong>{{ object.author }}</strong> on {{ object.pub_date|date:"F j, Y" }} | <a href="{{ object.get_absolute_url }}#comments">{{ comment_count }} comment{{ comment_count|pluralize }}</a></p>
View
10 django_website/templates/blog/entry_detail.html
@@ -8,8 +8,8 @@
{{ object.body }}
<p class="date small">Posted by <strong>{{ object.author }}</strong> on {{ object.pub_date|date:"F j, Y" }}</p>
-{% load comments %}
-{% get_free_comment_list for blog.entry object.id as comment_list %}
+{% load comments comment_utils %}
+{% get_public_free_comment_list for blog.entry object.id as comment_list %}
<div id="content-secondary">
<h2 id="comments">Comments</h2>
@@ -21,8 +21,12 @@ <h2 id="comments">Comments</h2>
</div>
{% endfor %}
-<h2>Post a comment</h2>
+<h2>Comments are closed</h2>
+{% if object.comments_enabled %}
{% free_comment_form for blog.entry object.id %}
+{% else %}
+<p>To prevent spam, comments are no longer allowed after sixty days.</p>
+{% endif %}
</div>
{% endblock %}
View
5 django_website/templates/flatfiles/homepage.html
@@ -70,12 +70,11 @@ <h2 class="deck">Django is a high-level Python Web framework that encourages rap
{% block content-extra %}
<h2>Weblog</h2>
-{% load comments %}
-{% load latestblogentry %}
+{% load comments comment_utils latestblogentry %}
{% get_latest_blog_entries 4 as latest_entries %}
{% for latest_entry in latest_entries %}
- {% get_free_comment_count for blog.entry latest_entry.id as comment_count %}
+ {% get_public_free_comment_count for blog.entry latest_entry.id as comment_count %}
<h3><a href="{{ latest_entry.get_absolute_url }}">{{ latest_entry.headline }}</a></h3>
<p class="date">by <strong>{{ latest_entry.author }}</strong> on {{ latest_entry.pub_date|date:"M. j, Y" }}</p>
{{ latest_entry.summary }}
View
2  django_website/urls.py
@@ -9,7 +9,7 @@
from django.views.decorators.cache import cache_page
comments_info_dict = {
- 'queryset': FreeComment.objects.all(),
+ 'queryset': FreeComment.objects.filter(is_public=True),
'paginate_by': 15,
}
Please sign in to comment.
Something went wrong with that request. Please try again.