base.py
32 lines
| 763 B
| text/x-python
|
PythonLexer
|
r542 | from django.db import transaction | ||
from django.views.generic import View | ||||
|
r690 | |||
|
r1993 | from boards import utils, settings | ||
|
r690 | from boards.models.user import Ban | ||
|
r542 | |||
BAN_REASON_SPAM = 'Autoban: spam bot' | ||||
|
r722 | CONTEXT_FORM = 'form' | ||
|
r542 | |||
class BaseBoardView(View): | ||||
def get_context_data(self, **kwargs): | ||||
|
r919 | return dict() | ||
|
r542 | |||
@transaction.atomic | ||||
def _ban_current_user(self, request): | ||||
""" | ||||
Add current user to the IP ban list | ||||
""" | ||||
ip = utils.get_client_ip(request) | ||||
|
r1993 | whitelist = settings.get_list('Forms', 'BanWhitelist') | ||
if not ip in whitelist: | ||||
ban, created = Ban.objects.get_or_create(ip=ip) | ||||
if created: | ||||
ban.can_read = False | ||||
ban.reason = BAN_REASON_SPAM | ||||
ban.save() | ||||
|
r542 | |||