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

2

7

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!

Morissa answered 23/7, 2009 at 20:1 Comment(0)
D
3

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.
Dorren answered 23/7, 2009 at 20:34 Comment(1)
+1 for writing your own view that wraps the post_comment view.Doug
I
0

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

Indifference answered 23/7, 2009 at 20:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.