diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-06-12 22:51:11 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2010-06-12 22:51:11 -0400 |
commit | 3a3a11d32c72ab79ce94679aae7a549230c7104f (patch) | |
tree | 3ac36a302b85d5497b3d335238044c8f481ac0fd /forum/deps/livesettings/forms.py | |
parent | 8b6a10ead45bcd915f5da223de2b3fd3c30fc7b5 (diff) | |
download | askbot-3a3a11d32c72ab79ce94679aae7a549230c7104f.tar.gz askbot-3a3a11d32c72ab79ce94679aae7a549230c7104f.tar.bz2 askbot-3a3a11d32c72ab79ce94679aae7a549230c7104f.zip |
moved livesettings and django_authopenid into forum/deps
Diffstat (limited to 'forum/deps/livesettings/forms.py')
-rw-r--r-- | forum/deps/livesettings/forms.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/forum/deps/livesettings/forms.py b/forum/deps/livesettings/forms.py new file mode 100644 index 00000000..f8d40895 --- /dev/null +++ b/forum/deps/livesettings/forms.py @@ -0,0 +1,38 @@ +from django import forms +from forum.deps.livesettings import * +import logging + +log = logging.getLogger('configuration') + +class SettingsEditor(forms.Form): + "Base editor, from which customized forms are created" + + def __init__(self, *args, **kwargs): + settings = kwargs.pop('settings') + super(SettingsEditor, self).__init__(*args, **kwargs) + flattened = [] + groups = [] + for setting in settings: + if isinstance(setting, ConfigurationGroup): + for s in setting: + flattened.append(s) + else: + flattened.append(setting) + + for setting in flattened: + # Add the field to the customized field list + kw = { + 'label': setting.description, + 'help_text': setting.help_text, + # Provide current setting values for initializing the form + 'initial': setting.editor_value + } + field = setting.make_field(**kw) + + k = '%s__%s' % (setting.group.key, setting.key) + self.fields[k] = field + if not setting.group in groups: + groups.append(setting.group) + #log.debug("Added field: %s = %s" % (k, str(field))) + + self.groups = groups
\ No newline at end of file |