+class StringListWidget(forms.Widget):
+ def render(self, name, value, attrs=None):
+ ret = ""
+ for s in value:
+ ret += """
+ <div class="string-list-input">
+ <input type="text" name="%(name)s" value="%(value)s" />
+ <button class="string_list_widget_button">-</button>
+ </div>
+ """ % {'name': name, 'value': s}
+
+ return """
+ <div class="string_list_widgets">
+ %(ret)s
+ <div><button name="%(name)s" class="string_list_widget_button add">+</button></div>
+ </div>
+ """ % dict(name=name, ret=ret)
+
+ def value_from_datadict(self, data, files, name):
+ if 'submit' in data:
+ return data.getlist(name)
+ else:
+ 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 """
+ <div id="test_email_settings">
+ <a href="%s" onclick="return false;" class="button test_button" href="/">Test</a>