comparison shoutbox/forms.py @ 581:ee87ea74d46b

For Django 1.4, rearranged project structure for new manage.py.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 May 2012 17:10:48 -0500
parents gpp/shoutbox/forms.py@dbd703f7d63a
children 4aadaf3bc234
comparison
equal deleted inserted replaced
580:c525f3e0b5d0 581:ee87ea74d46b
1 """
2 Forms for the Shoutbox application.
3 """
4
5 import re
6 from django import forms
7
8 url_re = re.compile('('
9 r'^https?://' # http:// or https://
10 r'(?:(?:[A-Z0-9-]+\.)+[A-Z]{2,6}|' #domain...
11 r'localhost|' #localhost...
12 r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
13 r'(?::\d+)?' # optional port
14 r'(?:/?|/\S+))', re.IGNORECASE)
15
16
17 class ShoutBoxForm(forms.Form):
18 msg = forms.CharField(label='', max_length=2048, required=True)
19
20 def get_shout(self):
21 msg = self.cleaned_data['msg']
22 msg = re.sub(url_re, r'<a href="\1">URL</a>', msg)
23 return msg
24