diff options
author | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2012-08-29 16:39:40 -0600 |
---|---|---|
committer | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2012-08-29 16:39:40 -0600 |
commit | 34f21ec2519a819d865583f046235366300176f9 (patch) | |
tree | ed1fd35cdbf53fb155eef5cb61c6ae179979eb40 /askbot/views/widgets.py | |
parent | e00b048a7f850f1b7dfa25988db1fd48cba8b637 (diff) | |
download | askbot-34f21ec2519a819d865583f046235366300176f9.tar.gz askbot-34f21ec2519a819d865583f046235366300176f9.tar.bz2 askbot-34f21ec2519a819d865583f046235366300176f9.zip |
moved forms, partially broken due to Tag/Group model migration
Diffstat (limited to 'askbot/views/widgets.py')
-rw-r--r-- | askbot/views/widgets.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/askbot/views/widgets.py b/askbot/views/widgets.py index d0707a73..281c4cf9 100644 --- a/askbot/views/widgets.py +++ b/askbot/views/widgets.py @@ -22,8 +22,8 @@ WIDGETS_MODELS = { } WIDGETS_FORMS = { - 'ask': models.widgets.CreateAskWidgetForm, - 'question': models.widgets.CreateQuestionWidgetForm, + 'ask': forms.CreateAskWidgetForm, + 'question': forms.CreateQuestionWidgetForm, } def _get_model(key): @@ -154,10 +154,12 @@ def list_widgets(request, model): @decorators.admins_only def create_widget(request, model): form_class = _get_form(model) + model_class = _get_model(model) if request.method == 'POST': form = form_class(request.POST) if form.is_valid(): - form.save() + instance = model_class(**form.cleaned_data) + instance.save() return redirect('list_widgets', model=model) else: form = form_class() @@ -174,13 +176,15 @@ def edit_widget(request, model, widget_id): form_class = _get_form(model) widget = get_object_or_404(model_class, pk=widget_id) if request.method == 'POST': - form = form_class(request.POST, - instance=widget) + form = form_class(request.POST) if form.is_valid(): - form.save() + instance = model_class(**form.cleaned_data) + instance.save() return redirect('list_widgets', model=model) else: - form = form_class(instance=widget) + initial_dict = dict.copy(widget.__dict__) + del initial_dict['_state'] + form = form_class(initial=initial_dict) data = {'form': form, 'action': 'edit', |