ban.py
24 lines
| 763 B
| text/x-python
|
PythonLexer
|
r553 | from django.db import transaction | ||
|
r561 | from django.shortcuts import get_object_or_404 | ||
|
r690 | from boards import utils | ||
|
r553 | |||
from boards.views.base import BaseBoardView | ||||
from boards.models import Post, Ban | ||||
|
r563 | from boards.views.mixins import RedirectNextMixin | ||
|
r553 | |||
|
r561 | |||
|
r563 | class BanUserView(BaseBoardView, RedirectNextMixin): | ||
|
r553 | |||
@transaction.atomic | ||||
def get(self, request, post_id): | ||||
|
r690 | user = utils.get_user(request) | ||
|
r553 | post = get_object_or_404(Post, id=post_id) | ||
if user.is_moderator(): | ||||
# TODO Show confirmation page before ban | ||||
ban, created = Ban.objects.get_or_create(ip=post.poster_ip) | ||||
if created: | ||||
ban.reason = 'Banned for post ' + str(post_id) | ||||
ban.save() | ||||
return self.redirect_to_next(request) | ||||