X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/410bfa05ee36ed1d99356c443a5f3f6aa3ee9578..58120aed9b7ba336d9935358f0716e9e0de8b7f0:/forum/settings/forms.py diff --git a/forum/settings/forms.py b/forum/settings/forms.py index aa5a352..27581d5 100644 --- a/forum/settings/forms.py +++ b/forum/settings/forms.py @@ -1,4 +1,6 @@ import os +import socket +from string import strip from django import forms from base import Setting from django.utils.translation import ugettext as _ @@ -20,7 +22,9 @@ class SettingsSetForm(forms.Form): super(SettingsSetForm, self).__init__(data, *args, **kwargs) for setting in set: - if isinstance(setting, Setting.emulators.get(str, DummySetting)): + if isinstance(setting, (Setting.emulators.get(str, DummySetting), Setting.emulators.get(unicode, DummySetting))): + if not setting.field_context.get('widget', None): + setting.field_context['widget'] = forms.TextInput(attrs={'class': 'longstring'}) field = forms.CharField(**setting.field_context) elif isinstance(setting, Setting.emulators.get(float, DummySetting)): field = forms.FloatField(**setting.field_context) @@ -35,6 +39,12 @@ class SettingsSetForm(forms.Form): self.set = set + def as_table(self): + return self._html_output( + u'%(label)s' + ('
%s|%s' % ( + _('context'), _('default'))) + u'%(errors)s%(field)s%(help_text)s', + u'%s', '', u'
%s', False) + def save(self): for setting in self.set: setting.set_value(self.cleaned_data[setting.name]) @@ -73,7 +83,7 @@ class StringListWidget(forms.Widget): ret = "" for s in value: ret += """ -
+
@@ -92,4 +102,44 @@ class StringListWidget(forms.Widget): else: return data[name] +class CommaStringListWidget(forms.Textarea): + def value_from_datadict(self, data, files, name): + if 'submit' in data: + return map(strip, data[name].split(',')) + else: + 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) + +