# HG changeset patch # User neko259 # Date 2015-02-01 20:53:07 # Node ID 29fca307b3133d5a7606c3338e36f4e5e11da2d3 # Parent 8ba6c857a9a57395d89f7c0ac3782f98f3a7826f Added admin action to ban user that posted given messages diff --git a/boards/admin.py b/boards/admin.py --- a/boards/admin.py +++ b/boards/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin from boards.models import Post, Tag, Ban, Thread +from django.utils.translation import ugettext_lazy as _ @admin.register(Post) @@ -11,6 +12,17 @@ class PostAdmin(admin.ModelAdmin): exclude = ('referenced_posts', 'refmap') readonly_fields = ('poster_ip', 'thread_new') + def ban_poster(self, request, queryset): + bans = 0 + for post in queryset: + poster_ip = post.poster_ip + ban, created = Ban.objects.get_or_create(ip=poster_ip) + if created: + bans += 1 + self.message_user(request, _('{} posters were banned').format(bans)) + + actions = ['ban_poster'] + @admin.register(Tag) class TagAdmin(admin.ModelAdmin): diff --git a/boards/views/base.py b/boards/views/base.py --- a/boards/views/base.py +++ b/boards/views/base.py @@ -1,5 +1,4 @@ from django.db import transaction -from django.template import RequestContext from django.views.generic import View from boards import utils