utils.py
31 lines
| 1017 B
| text/x-python
|
PythonLexer
|
r2005 | from django.contrib.auth.decorators import permission_required | ||
|
r1899 | from django.shortcuts import redirect | ||
from django.utils.decorators import method_decorator | ||||
from django.views.decorators.csrf import csrf_protect | ||||
|
r1902 | |||
|
r1899 | from boards.models import Post, Ban | ||
|
r2005 | from boards.views.base import BaseBoardView | ||
from boards.views.mixins import DispatcherMixin | ||||
|
r1899 | |||
class UtilsView(BaseBoardView, DispatcherMixin): | ||||
@method_decorator(csrf_protect) | ||||
def get(self, request): | ||||
self.dispatch_method(request) | ||||
return redirect('index') | ||||
|
r1902 | @permission_required('boards.delete_post') | ||
|
r1899 | def ban_and_delete(self, request): | ||
post = Post.objects.get(id=request.GET['post_id']) | ||||
Ban.objects.get_or_create(ip=post.poster_ip) | ||||
|
r1901 | if post.is_opening(): | ||
post.get_thread().delete() | ||||
else: | ||||
post.delete() | ||||
|
r1899 | |||
|
r1904 | @permission_required('boards.add_ban') | ||
def ban(self, request): | ||||
post = Post.objects.get(id=request.GET['post_id']) | ||||
Ban.objects.get_or_create(ip=post.poster_ip) | ||||