views:

376

answers:

2

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!

A: 

Yes! There's now a way to customize the Comments app. Good luck!

Emil Stenström
+3  A: 

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.
Steve Losh
Thanks, I will patch and contribute it back to Django. Appreciate the answer!
Teebes
+1 for writing your own view that wraps the post_comment view.
Soviut