Mercurial > public > sg101
comparison shoutbox/forms.py @ 991:4aadaf3bc234
Added SITE_SCHEME setting.
Configure site scheme to be either http or https based on SITE_SCHEME setting.
Updated code to use it.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 01 Nov 2015 15:56:05 -0600 |
parents | ee87ea74d46b |
children |
comparison
equal
deleted
inserted
replaced
990:81b96f3c9e59 | 991:4aadaf3bc234 |
---|---|
1 """ | 1 """ |
2 Forms for the Shoutbox application. | 2 Forms for the Shoutbox application. |
3 """ | 3 """ |
4 | |
5 import re | |
6 from django import forms | 4 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 | 5 |
17 class ShoutBoxForm(forms.Form): | 6 class ShoutBoxForm(forms.Form): |
18 msg = forms.CharField(label='', max_length=2048, required=True) | 7 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 |