# HG changeset patch # User Steve Losh # Date 1232688073 18000 # Node ID c6f37ebd2f3ebe9701fa0fe8babffb5800039f91 # Parent 4f7cda859dc8ef528050b0a48836f0271437dd9c Added a field to mark spams to the Comment models. diff -r 4f7cda859dc8 -r c6f37ebd2f3e blog/admin.py --- 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',) diff -r 4f7cda859dc8 -r c6f37ebd2f3e blog/models.py --- 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) diff -r 4f7cda859dc8 -r c6f37ebd2f3e blog/views.py --- 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', diff -r 4f7cda859dc8 -r c6f37ebd2f3e projects/admin.py --- 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',) diff -r 4f7cda859dc8 -r c6f37ebd2f3e projects/models.py --- 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) diff -r 4f7cda859dc8 -r c6f37ebd2f3e projects/views.py --- 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') diff -r 4f7cda859dc8 -r c6f37ebd2f3e templates/blog/entry.html --- 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 @@
- {% ifnotequal entry.comment_set.count 0 %} + {% ifnotequal comments.count 0 %}

Comments

- {% for comment in entry.comment_set.all|dictsort:"submitted" %} + {% for comment in comments %}

{{ comment.name }} said:

diff -r 4f7cda859dc8 -r c6f37ebd2f3e templates/projects/project.html --- 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 @@

- {% ifnotequal project.comment_set.count 0 %} + {% ifnotequal comments.count 0 %}

Comments

- {% for comment in project.comment_set.all|dictsort:"submitted" %} + {% for comment in comments %}

{{ comment.name }} said: