from django.shortcuts import redirect from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_protect from boards.views.base import BaseBoardView, CONTEXT_FORM from boards.views.mixins import DispatcherMixin, PARAMETER_METHOD from boards.models import Post, Ban class UtilsView(BaseBoardView, DispatcherMixin): @method_decorator(csrf_protect) def get(self, request): self.dispatch_method(request) return redirect('index') def ban_and_delete(self, request): post = Post.objects.get(id=request.GET['post_id']) Ban.objects.get_or_create(ip=post.poster_ip) post.delete()