]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/settings/forms.py
Cleaning up a small mess.
[osqa.git] / forum / settings / forms.py
index c0d3a49a4029e0ffce6688613b7dcf00673c283e..0c123011cbc99976a71a9107eba0f50a858fd850 100644 (file)
@@ -14,16 +14,22 @@ class UnfilteredField(forms.CharField):
 
 
 class SettingsSetForm(forms.Form):
-    def __init__(self, set, data=None, *args, **kwargs):
-        if data is None:
-            initial = dict([(setting.name, setting.value) for setting in set])
-        else:
-            initial = None
+    def __init__(self, set, data=None, unsaved=None, *args, **kwargs):
+        initial = dict([(setting.name, setting.value) for setting in set])
+
+        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)
@@ -104,6 +110,10 @@ 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(','))
@@ -113,3 +123,4 @@ class CommaStringListWidget(forms.Textarea):
 
 
 
+