base.py
39 lines
| 910 B
| text/x-python
|
PythonLexer
neko259
|
r542 | from django.db import transaction | ||
from django.template import RequestContext | ||||
from django.views.generic import View | ||||
neko259
|
r690 | |||
neko259
|
r542 | from boards import utils | ||
neko259
|
r690 | from boards.models.user import Ban | ||
neko259
|
r542 | |||
BAN_REASON_SPAM = 'Autoban: spam bot' | ||||
neko259
|
r722 | CONTEXT_FORM = 'form' | ||
neko259
|
r542 | |||
class BaseBoardView(View): | ||||
def get_context_data(self, **kwargs): | ||||
neko259
|
r900 | """ | ||
This method is deprecated. You need to use dicts instead of context | ||||
instances in all places it is used now. | ||||
""" | ||||
neko259
|
r542 | request = kwargs['request'] | ||
context = RequestContext(request) | ||||
return context | ||||
@transaction.atomic | ||||
def _ban_current_user(self, request): | ||||
""" | ||||
Add current user to the IP ban list | ||||
""" | ||||
ip = utils.get_client_ip(request) | ||||
ban, created = Ban.objects.get_or_create(ip=ip) | ||||
if created: | ||||
ban.can_read = False | ||||
ban.reason = BAN_REASON_SPAM | ||||
ban.save() | ||||