X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/1876ec0c8caf982704410cee305d0cde218421d4..7eca93637b2f696dcc140d36e44d5f4810346e2c:/forum/settings/forms.py diff --git a/forum/settings/forms.py b/forum/settings/forms.py index 15bbef6..3e3cc5a 100644 --- a/forum/settings/forms.py +++ b/forum/settings/forms.py @@ -1,9 +1,10 @@ import os from string import strip from django import forms -from base import Setting +from forum.settings.base import Setting from django.utils.translation import ugettext as _ from django.core.files.storage import FileSystemStorage +from django.core.urlresolvers import reverse class DummySetting: pass @@ -14,14 +15,22 @@ class UnfilteredField(forms.CharField): class SettingsSetForm(forms.Form): - def __init__(self, set, data=None, *args, **kwargs): - if data is None: - data = dict([(setting.name, setting.value) for setting in set]) + def __init__(self, set, data=None, unsaved=None, *args, **kwargs): + initial = dict([(setting.name, setting.value) for setting in set]) - super(SettingsSetForm, self).__init__(data, *args, **kwargs) + if unsaved: + initial.update(unsaved) + + super(SettingsSetForm, self).__init__(data, initial=initial, *args, **kwargs) for setting in set: - if isinstance(setting, (Setting.emulators.get(str, DummySetting), Setting.emulators.get(unicode, DummySetting))): + widget = setting.field_context.get('widget', None) + + if widget is forms.CheckboxSelectMultiple or widget is forms.SelectMultiple or isinstance(widget, forms.SelectMultiple): + field = forms.MultipleChoiceField(**setting.field_context) + elif widget is forms.RadioSelect or isinstance(widget, forms.RadioSelect): + field = forms.ChoiceField(**setting.field_context) + elif 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) @@ -38,6 +47,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]) @@ -76,7 +91,7 @@ class StringListWidget(forms.Widget): ret = "" for s in value: ret += """ -
+
@@ -96,12 +111,30 @@ class StringListWidget(forms.Widget): return data[name] class CommaStringListWidget(forms.Textarea): + def render(self, name, value, attrs=None): + return super(CommaStringListWidget, self).render(name, ', '.join(value), attrs) + + def value_from_datadict(self, data, files, name): if 'submit' in data: return map(strip, data[name].split(',')) else: return ', '.join(data[name]) +class TestEmailSettingsWidget(forms.TextInput): + def render(self, name, value, attrs=None): + if not value: + value = '' - - + return """ +
+ Test + +
+ +
+
+
+ """ % reverse("test_email_settings") \ No newline at end of file