Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[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
authored
13  django_website/apps/blog/models.py
... ...
@@ -1,4 +1,6 @@
  1
+import datetime
1 2
 from django.db import models
  3
+from comment_utils.moderation import CommentModerator, moderator
2 4
 
3 5
 class Entry(models.Model):
4 6
     pub_date = models.DateTimeField()
@@ -22,3 +24,14 @@ def __unicode__(self):
22 24
 
23 25
     def get_absolute_url(self):
24 26
         return "/weblog/%s/%s/" % (self.pub_date.strftime("%Y/%b/%d").lower(), self.slug)
  27
+        
  28
+    @property
  29
+    def comments_enabled(self):
  30
+        delta = datetime.datetime.now() - self.pub_date
  31
+        return delta.days < 60
  32
+
  33
+class EntryModerator(CommentModerator):
  34
+    akismet = True
  35
+    enable_field = "comments_enabled"
  36
+
  37
+moderator.register(Entry, EntryModerator)
6  django_website/settings.py
@@ -47,6 +47,7 @@
47 47
     'django_website.apps.docs',
48 48
     'django_website.apps.aggregator',
49 49
     'registration',
  50
+    'comment_utils',
50 51
 )
51 52
 ADMIN_MEDIA_PREFIX = 'http://media.djangoproject.com/admin/'
52 53
 MEDIA_ROOT = "/home/html/djangoproject.com/m/"
@@ -74,4 +75,7 @@
74 75
 USE_I18N = False
75 76
 
76 77
 # django-registration settings
77  
-ACCOUNT_ACTIVATION_DAYS = 3
  78
+ACCOUNT_ACTIVATION_DAYS = 3
  79
+
  80
+# comment_utils settings
  81
+AKISMET_API_KEY = "c892e4962244"
4  django_website/templates/blog/entry_archive.html
@@ -2,12 +2,12 @@
2 2
 
3 3
 {% block content %}
4 4
 
5  
-{% load comments.comments %}
  5
+{% load comments comment_utils %}
6 6
 
7 7
 <h1>Latest entries</h1>
8 8
 
9 9
 {% for object in latest %}
10  
-    {% get_free_comment_count for blog.entry object.id as comment_count %}
  10
+    {% get_public_free_comment_count for blog.entry object.id as comment_count %}
11 11
     <h2><a href="{{ object.get_absolute_url }}">{{ object.headline }}</a></h2>
12 12
     {{ object.body }}
13 13
     <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>
10  django_website/templates/blog/entry_detail.html
@@ -8,8 +8,8 @@
8 8
 {{ object.body }}
9 9
 <p class="date small">Posted by <strong>{{ object.author }}</strong> on {{ object.pub_date|date:"F j, Y" }}</p>
10 10
 
11  
-{% load comments %}
12  
-{% get_free_comment_list for blog.entry object.id as comment_list %}
  11
+{% load comments comment_utils %}
  12
+{% get_public_free_comment_list for blog.entry object.id as comment_list %}
13 13
 
14 14
 <div id="content-secondary">
15 15
 <h2 id="comments">Comments</h2>
@@ -21,8 +21,12 @@ <h2 id="comments">Comments</h2>
21 21
 </div>
22 22
 {% endfor %}
23 23
 
24  
-<h2>Post a comment</h2>
  24
+<h2>Comments are closed</h2>
25 25
 
  26
+{% if object.comments_enabled %}
26 27
 {% free_comment_form for blog.entry object.id %}
  28
+{% else %}
  29
+<p>To prevent spam, comments are no longer allowed after sixty days.</p>
  30
+{% endif %}
27 31
 </div>
28 32
 {% endblock %}
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
70 70
 {% block content-extra %}
71 71
 <h2>Weblog</h2>
72 72
 
73  
-{% load comments %}
74  
-{% load latestblogentry %}
  73
+{% load comments comment_utils latestblogentry %}
75 74
 {% get_latest_blog_entries 4 as latest_entries %}
76 75
 
77 76
 {% for latest_entry in latest_entries %}
78  
-    {% get_free_comment_count for blog.entry latest_entry.id as comment_count %}
  77
+    {% get_public_free_comment_count for blog.entry latest_entry.id as comment_count %}
79 78
     <h3><a href="{{ latest_entry.get_absolute_url }}">{{ latest_entry.headline }}</a></h3>
80 79
     <p class="date">by <strong>{{ latest_entry.author }}</strong> on {{ latest_entry.pub_date|date:"M. j, Y" }}</p>
81 80
     {{ latest_entry.summary }}
2  django_website/urls.py
@@ -9,7 +9,7 @@
9 9
 from django.views.decorators.cache import cache_page
10 10
 
11 11
 comments_info_dict = {
12  
-    'queryset': FreeComment.objects.all(),
  12
+    'queryset': FreeComment.objects.filter(is_public=True),
13 13
     'paginate_by': 15,
14 14
 }
15 15
 

0 notes on commit 87a2661

Please sign in to comment.
Something went wrong with that request. Please try again.