From 2d081bd8d43849cd62524501dfeef8f7edfc9bc1 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Tue, 27 Jul 2010 19:17:13 -0500 Subject: Add mark as ham/spam admin actions Signed-off-by: Dan McGee --- mycomments/admin.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/mycomments/admin.py b/mycomments/admin.py index e2be463..bad9ebd 100644 --- a/mycomments/admin.py +++ b/mycomments/admin.py @@ -2,10 +2,13 @@ from django.core.exceptions import PermissionDenied from django.contrib import admin from django.contrib.comments.admin import CommentsAdmin from django.utils.encoding import force_unicode + from mycomments.models import MyComment, BannedIP, BannedUserName +from mycomments.utils import akismet_ham, akismet_spam class MyCommentsAdmin(CommentsAdmin): - actions = ['delete_and_ban_ip', 'delete_and_ban_user', 'delete_and_ban_both'] + actions = ['delete_and_ban_ip', 'delete_and_ban_user', 'delete_and_ban_both', + 'mark_ham', 'mark_spam'] def delete_set(self, request, objset): c = 0 @@ -62,6 +65,30 @@ class MyCommentsAdmin(CommentsAdmin): self.delete_and_ban(request, queryset, banip=True, banuser=True) delete_and_ban_both.short_description = "Delete and ban selected IP addresses and user names" + def mark_comment(self, request, queryset, action=akismet_spam, type="spam"): + if not self.has_change_permission(request): + raise PermissionDenied + + count = queryset.count() + if count: + for comment in queryset: + action(request, comment) + self.message_user(request, + "Successfully marked %(count)d comments as %(type)s." % { + "count": count, "type": type + }) + + def mark_ham(self, request, queryset): + self.mark_comment(request, queryset, akismet_ham, "ham") + queryset.update(is_public=True) + mark_ham.short_description = \ + "Mark as visible and submit to Akismet as ham" + + def mark_spam(self, request, queryset): + self.mark_comment(request, queryset, akismet_spam, "spam") + queryset.update(is_public=False) + mark_spam.short_description = \ + "Mark as hidden and submit to Akismet as spam" admin.site.register(MyComment, MyCommentsAdmin) admin.site.register(BannedIP) -- cgit v1.2.3-55-g3dc8