diff options
author | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2012-09-07 12:10:32 -0600 |
---|---|---|
committer | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2012-09-07 12:10:32 -0600 |
commit | 38f7631b55da2401de73ccec8b3e2425e4b21377 (patch) | |
tree | 6a651607b5a2a42b3ad53dd8e53993002e7f5bc3 | |
parent | 7a529933b5dc593261c458b9761c183fe3b39de6 (diff) | |
download | askbot-38f7631b55da2401de73ccec8b3e2425e4b21377.tar.gz askbot-38f7631b55da2401de73ccec8b3e2425e4b21377.tar.bz2 askbot-38f7631b55da2401de73ccec8b3e2425e4b21377.zip |
fixed bug in widget creation
-rw-r--r-- | askbot/forms.py | 4 | ||||
-rw-r--r-- | askbot/views/widgets.py | 20 |
2 files changed, 22 insertions, 2 deletions
diff --git a/askbot/forms.py b/askbot/forms.py index 38ba73fa..b720ad77 100644 --- a/askbot/forms.py +++ b/askbot/forms.py @@ -919,7 +919,9 @@ class AskWidgetForm(forms.Form, FormWithHideableFields): self.fields['text'] = QuestionEditorField() if not include_text: self.hide_field('text') - self.fields['text'].required=False + #hack to make it validate + self.fields['text'].required = False + self.fields['text'].min_length = 0 class CreateAskWidgetForm(forms.Form, FormWithHideableFields): title = forms.CharField(max_length=100) diff --git a/askbot/views/widgets.py b/askbot/views/widgets.py index ae5ad435..8699cdf1 100644 --- a/askbot/views/widgets.py +++ b/askbot/views/widgets.py @@ -177,11 +177,29 @@ def edit_widget(request, model, widget_id): if request.method == 'POST': form = form_class(request.POST) if form.is_valid(): - widget.__dict__.update(form.cleaned_data) + form_dict = dict.copy(form.cleaned_data) + for key in widget.__dict__: + if key.endswith('_id'): + form_key = key.split('_id')[0] + if form_dict[form_key]: + form_dict[key] = form_dict[form_key].id + del form_dict[form_key] + else: + continue + + widget.__dict__.update(form_dict) widget.save() return redirect('list_widgets', model=model) else: initial_dict = dict.copy(widget.__dict__) + for key in initial_dict: + if key.endswith('_id'): + new_key = key.split('_id')[0] + initial_dict[new_key] = initial_dict[key] + del initial_dict[key] + else: + continue + del initial_dict['_state'] form = form_class(initial=initial_dict) |