annotate gpp/shoutbox/forms.py @ 479:32cec6cd8808
Refactor RateLimiter so that if Redis is not running, everything still runs normally (minus the rate limiting protection). My assumption that creating a Redis connection would throw an exception if Redis wasn't running was wrong. The exceptions actually occur when you issue a command. This is for #224.
author |
Brian Neal <bgneal@gmail.com> |
date |
Sun, 25 Sep 2011 00:49:05 +0000 |
parents |
dbd703f7d63a |
children |
|
rev |
line source |
gremmie@1
|
1 """
|
gremmie@1
|
2 Forms for the Shoutbox application.
|
gremmie@1
|
3 """
|
gremmie@1
|
4
|
gremmie@1
|
5 import re
|
gremmie@1
|
6 from django import forms
|
gremmie@1
|
7
|
gremmie@1
|
8 url_re = re.compile('('
|
gremmie@1
|
9 r'^https?://' # http:// or https://
|
gremmie@1
|
10 r'(?:(?:[A-Z0-9-]+\.)+[A-Z]{2,6}|' #domain...
|
gremmie@1
|
11 r'localhost|' #localhost...
|
gremmie@1
|
12 r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
|
gremmie@1
|
13 r'(?::\d+)?' # optional port
|
gremmie@1
|
14 r'(?:/?|/\S+))', re.IGNORECASE)
|
gremmie@1
|
15
|
gremmie@1
|
16
|
gremmie@1
|
17 class ShoutBoxForm(forms.Form):
|
gremmie@1
|
18 msg = forms.CharField(label='', max_length=2048, required=True)
|
gremmie@1
|
19
|
gremmie@1
|
20 def get_shout(self):
|
gremmie@1
|
21 msg = self.cleaned_data['msg']
|
gremmie@1
|
22 msg = re.sub(url_re, r'<a href="\1">URL</a>', msg)
|
gremmie@1
|
23 return msg
|
gremmie@1
|
24
|