X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/c5240df75267cc1201c0e4673c34cc25149698e4..9c16cbca82809745d8658a618434f814d0df8ec8:/forum/settings/forms.py diff --git a/forum/settings/forms.py b/forum/settings/forms.py index a187683..27581d5 100644 --- a/forum/settings/forms.py +++ b/forum/settings/forms.py @@ -1,4 +1,5 @@ import os +import socket from string import strip from django import forms from base import Setting @@ -109,5 +110,36 @@ class CommaStringListWidget(forms.Textarea): return ', '.join(data[name]) +class IPListField(forms.CharField): + def clean(self, value): + ips = [ip.strip() for ip in value.strip().strip(',').split(',')] + iplist = [] + + if len(ips) < 1: + raise forms.ValidationError(_('Please input at least one ip address')) + + for ip in ips: + try: + socket.inet_aton(ip) + except socket.error: + raise forms.ValidationError(_('Invalid ip address: %s' % ip)) + + if not len(ip.split('.')) == 4: + raise forms.ValidationError(_('Please use the dotted quad notation for the ip addresses')) + + iplist.append(ip) + + return iplist + +class MaintenanceModeForm(forms.Form): + ips = IPListField(label=_('Allow ips'), + help_text=_('Comma separated list of ips allowed to access the site while in maintenance'), + required=True, + widget=forms.TextInput(attrs={'class': 'longstring'})) + + message = forms.CharField(label=_('Message'), + help_text=_('A message to display to your site visitors while in maintainance mode'), + widget=forms.Textarea) +