ban.py
26 lines
| 881 B
| text/x-python
|
PythonLexer
neko259
|
r553 | from django.db import transaction | ||
neko259
|
r561 | from django.shortcuts import get_object_or_404 | ||
neko259
|
r553 | |||
neko259
|
r728 | from boards.abstracts.settingsmanager import SettingsManager, \ | ||
PERMISSION_MODERATE | ||||
neko259
|
r553 | from boards.views.base import BaseBoardView | ||
from boards.models import Post, Ban | ||||
neko259
|
r563 | from boards.views.mixins import RedirectNextMixin | ||
neko259
|
r553 | |||
neko259
|
r561 | |||
neko259
|
r563 | class BanUserView(BaseBoardView, RedirectNextMixin): | ||
neko259
|
r553 | |||
@transaction.atomic | ||||
def get(self, request, post_id): | ||||
post = get_object_or_404(Post, id=post_id) | ||||
neko259
|
r728 | settings_manager = SettingsManager(request.session) | ||
if settings_manager.has_permission(PERMISSION_MODERATE): | ||||
neko259
|
r553 | # 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) | ||||