c6f37ebd2f3e

Added a field to mark spams to the Comment models.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Fri, 23 Jan 2009 00:21:13 -0500
parents 4f7cda859dc8
children 9a43a0ef2602
branches/tags (none)
files blog/admin.py blog/models.py blog/views.py projects/admin.py projects/models.py projects/views.py templates/blog/entry.html templates/projects/project.html

Changes

--- a/blog/admin.py	Wed Jan 21 18:48:24 2009 -0500
+++ b/blog/admin.py	Fri Jan 23 00:21:13 2009 -0500
@@ -17,10 +17,10 @@
     prepopulated_fields = { 'slug': ('title',) }
 
 class CommentAdmin(admin.ModelAdmin):
-    fields = ('name', 'body', 'submitted', 'entry')
-    list_display = ('entry', 'name', 'submitted', 'body')
+    fields = ('name', 'body', 'submitted', 'entry', 'spam')
+    list_display = ('entry', 'name', 'submitted', 'body', 'spam')
     search_fields = ('name', 'body')
-    list_filter = ('name', 'entry')
+    list_filter = ('name', 'entry', 'spam')
     date_hierarchy = 'submitted'
     ordering = ('-submitted',)
 
--- a/blog/models.py	Wed Jan 21 18:48:24 2009 -0500
+++ b/blog/models.py	Fri Jan 23 00:21:13 2009 -0500
@@ -24,6 +24,7 @@
     body = models.TextField('Comment', blank=False, null=False)
     submitted = models.DateTimeField(default=datetime.datetime.now)
     entry = models.ForeignKey(Entry)
+    spam = models.BooleanField(default=False)
     
     def get_absolute_url(self):
         return self.entry.get_absolute_url() + "#comment-" + str(self.id)
--- a/blog/views.py	Wed Jan 21 18:48:24 2009 -0500
+++ b/blog/views.py	Fri Jan 23 00:21:13 2009 -0500
@@ -10,7 +10,10 @@
 def entry(request, year, month, day, slug):
     entry = get_object_or_404(Entry, slug=slug, pub_date__year=year, 
                               pub_date__month=month, pub_date__day=day,)
-    return render_to_response('blog/entry.html', { 'entry': entry, })
+    comments = entry.comment_set.filter(spam=False).order_by('submitted')
+    
+    return render_to_response('blog/entry.html', 
+                              { 'entry': entry, 'comments': comments })
 
 def old_entry(request, year, month, day, slug):
     return HttpResponsePermanentRedirect(reverse('blog-entry',
--- a/projects/admin.py	Wed Jan 21 18:48:24 2009 -0500
+++ b/projects/admin.py	Fri Jan 23 00:21:13 2009 -0500
@@ -22,10 +22,10 @@
     list_filter = ('project',)
 
 class CommentAdmin(admin.ModelAdmin):
-    fields = ('name', 'body', 'submitted', 'project')
-    list_display = ('project', 'name', 'submitted', 'body')
+    fields = ('name', 'body', 'submitted', 'project', 'spam')
+    list_display = ('project', 'name', 'submitted', 'body', 'spam')
     search_fields = ('name', 'body')
-    list_filter = ('name', 'project')
+    list_filter = ('name', 'project', 'spam')
     date_hierarchy = 'submitted'
     ordering = ('-submitted',)
 
--- a/projects/models.py	Wed Jan 21 18:48:24 2009 -0500
+++ b/projects/models.py	Fri Jan 23 00:21:13 2009 -0500
@@ -53,10 +53,11 @@
     body = models.TextField(blank=False, null=False)
     submitted = models.DateTimeField(default=datetime.datetime.now)
     project = models.ForeignKey(Project)
+    spam = models.BooleanField(default=False)
     
     def get_absolute_url(self):
         return self.project.get_absolute_url() + "#comment-" + str(self.id)
     
     def __unicode__(self):
-        return u'%s on %s' % (self.name, self.entry.title)
+        return u'%s on %s' % (self.name, self.project.name)
     
--- a/projects/views.py	Wed Jan 21 18:48:24 2009 -0500
+++ b/projects/views.py	Fri Jan 23 00:21:13 2009 -0500
@@ -7,8 +7,10 @@
 
 def project(request, slug):
     project = get_object_or_404(Project, slug=slug)
+    comments = project.comment_set.filter(spam=False).order_by('submitted')
+    
     return render_to_response('projects/project.html', 
-                              { 'project': project, })
+                              { 'project': project, 'comments': comments })
 
 def list(request):
     projects = Project.objects.all().order_by('-posted')
--- a/templates/blog/entry.html	Wed Jan 21 18:48:24 2009 -0500
+++ b/templates/blog/entry.html	Fri Jan 23 00:21:13 2009 -0500
@@ -31,10 +31,10 @@
 		</div>
 	</div>
 	<hr />
-	{% ifnotequal entry.comment_set.count 0 %}
+	{% ifnotequal comments.count 0 %}
 		<div id="blog-entry-comments">
 			<h1>Comments</h1>
-			{% for comment in entry.comment_set.all|dictsort:"submitted" %}
+			{% for comment in comments %}
 				<div class="blog-entry-comment">
 					<a name="comment-{{ comment.id }}"></a>
 					<h2>{{ comment.name }} said:</h2>
--- a/templates/projects/project.html	Wed Jan 21 18:48:24 2009 -0500
+++ b/templates/projects/project.html	Fri Jan 23 00:21:13 2009 -0500
@@ -34,10 +34,10 @@
 		</div>
 	</div>
 	<hr />
-	{% ifnotequal project.comment_set.count 0 %}
+	{% ifnotequal comments.count 0 %}
 		<div id="projects-project-comments">
 			<h1>Comments</h1>
-			{% for comment in project.comment_set.all|dictsort:"submitted" %}
+			{% for comment in comments %}
 				<div class="projects-project-comment">
 					<a name="comment-{{ comment.id }}"></a>
 					<h2>{{ comment.name }} said:</h2>