Mercurial > public > sg101
annotate antispam/decorators.py @ 917:0365fdbb4d78
Fix app conflict with messages.
Django's messages app label conflicts with our messages app.
We can't easily rename our label as that will make us rename database tables.
Since our app came first we'll just customize Django messages label.
For Django 1.7.7 upgrade.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Mon, 06 Apr 2015 20:02:25 -0500 |
parents | 4a49d4ac319f |
children |
rev | line source |
---|---|
bgneal@472 | 1 """ |
bgneal@472 | 2 This module contains decorators for the antispam application. |
bgneal@472 | 3 |
bgneal@472 | 4 """ |
bgneal@472 | 5 from functools import wraps |
bgneal@690 | 6 import logging |
bgneal@472 | 7 |
bgneal@472 | 8 |
bgneal@690 | 9 def log_auth_failures(auth_type): |
bgneal@472 | 10 |
bgneal@472 | 11 def decorator(fn): |
bgneal@690 | 12 logger = logging.getLogger('auth') |
bgneal@472 | 13 |
bgneal@472 | 14 @wraps(fn) |
bgneal@472 | 15 def wrapped(request, *args, **kwargs): |
bgneal@472 | 16 |
bgneal@472 | 17 response = fn(request, *args, **kwargs) |
bgneal@472 | 18 |
bgneal@472 | 19 if request.method == 'POST': |
bgneal@505 | 20 |
bgneal@692 | 21 # Figure out if the view succeeded; success means a redirect is |
bgneal@692 | 22 # about to occur. |
bgneal@692 | 23 success = (response and response.has_header('location') and |
bgneal@692 | 24 response.status_code == 302) |
bgneal@505 | 25 |
bgneal@505 | 26 if not success: |
bgneal@690 | 27 username = request.POST.get('username') |
bgneal@690 | 28 username = username if username else '(None)' |
bgneal@690 | 29 logger.error("%s failure from [%s] for %s", |
bgneal@690 | 30 auth_type, |
bgneal@690 | 31 request.META.get('REMOTE_ADDR', '?'), |
bgneal@690 | 32 username) |
bgneal@479 | 33 |
bgneal@472 | 34 return response |
bgneal@472 | 35 |
bgneal@472 | 36 return wrapped |
bgneal@472 | 37 return decorator |