diff options
author | Dan McGee <dan@archlinux.org> | 2010-07-27 19:17:13 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-07-27 19:17:13 -0500 |
commit | 2d081bd8d43849cd62524501dfeef8f7edfc9bc1 (patch) | |
tree | 12d003a63509e28eca50e299bf142785e0e88a86 | |
parent | 90b79e3bb6284b897054cf2b3d3f7dd7435fe077 (diff) | |
download | website-2d081bd8d43849cd62524501dfeef8f7edfc9bc1.tar.gz website-2d081bd8d43849cd62524501dfeef8f7edfc9bc1.zip |
Add mark as ham/spam admin actions
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | mycomments/admin.py | 29 |
1 files changed, 28 insertions, 1 deletions
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) |