Mercurial > public > sg101
annotate antispam/decorators.py @ 821:71db8076dc3d
Bandmap WIP: geocoding integrated with add form.
Add form works. Before submitting the form, client side JS makes
a geocode request to Google and populates hidden lat/lon fields
with the result. Successfully created a model instance on the
server side.
Still need to update admin dashboard, admin approval, and give
out badges for adding bands to the map. Once that is done, then
work on displaying the map with filtering.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 23 Sep 2014 20:40:31 -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 |