comparison antispam/decorators.py @ 679:89b240fe9297

For Django 1.5.2: import json; django.utils.simplejson is deprecated.
author Brian Neal <bgneal@gmail.com>
date Thu, 15 Aug 2013 20:14:33 -0500
parents ee87ea74d46b
children 988782c6ce6c
comparison
equal deleted inserted replaced
678:38a198ea8c61 679:89b240fe9297
1 """ 1 """
2 This module contains decorators for the antispam application. 2 This module contains decorators for the antispam application.
3 3
4 """ 4 """
5 from datetime import timedelta 5 from datetime import timedelta
6 import json
6 from functools import wraps 7 from functools import wraps
7 8
8 from django.shortcuts import render 9 from django.shortcuts import render
9 from django.utils import simplejson
10 10
11 from antispam.rate_limit import RateLimiter, RateLimiterUnavailable 11 from antispam.rate_limit import RateLimiter, RateLimiterUnavailable
12 12
13 13
14 def rate_limit(count=10, interval=timedelta(minutes=1), 14 def rate_limit(count=10, interval=timedelta(minutes=1),
39 success = False 39 success = False
40 if not request.is_ajax(): 40 if not request.is_ajax():
41 success = (response and response.has_header('location') and 41 success = (response and response.has_header('location') and
42 response.status_code == 302) 42 response.status_code == 302)
43 elif response: 43 elif response:
44 json_resp = simplejson.loads(response.content) 44 json_resp = json.loads(response.content)
45 success = json_resp['success'] 45 success = json_resp['success']
46 46
47 if not success: 47 if not success:
48 try: 48 try:
49 blocked = rate_limiter.incr() 49 blocked = rate_limiter.incr()