Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django comments: how to prevent form errors from redirecting the user to the preview page?

Currently, django.contrib.comments sends the user to the preview page if there is any error on the form.

I am using comments in the context of a blog and I would much rather that the user stayed on the page they were on if something went wrong with the submission. As far as I can tell though, this is hard-coded in django.contrib.comments.views.comments.post_comment:

# If there are errors or if we requested a preview show the comment
if form.errors or preview:
    template_list = [
        "comments/%s_%s_preview.html" % tuple(str(model._meta).split(".")),
        "comments/%s_preview.html" % model._meta.app_label,
        "comments/preview.html",
    ]
    return render_to_response(
        template_list, {
            "comment" : form.data.get("comment", ""),
            "form" : form,
            "next": next,
        },
        RequestContext(request, {})
    )

Is there any way that I can change this behavior without changing the source code to django.contrib.comments?

Any pointer would be appreciated...

Thanks!

like image 651
Teebes Avatar asked Jul 23 '09 20:07

Teebes


1 Answers

Looks like you have two real options:

  • Write your own view. Possibly copy that view's code to get started.
  • Patch that view to take an extra parameter, such as 'preview_on_errors' which defaults to True but can be overridden. Contribute the patch back to Django so other people can benefit from it.
like image 151
Steve Losh Avatar answered Oct 05 '22 09:10

Steve Losh