Comments redirect after posting is not honoured if comment contains errors or is previewed

27 views
Skip to first unread message

Jeff Winters

unread,
May 12, 2009, 6:10:18 PM5/12/09
to Django users
Hello,



In using the comments framework, I have experienced some odd behaviour
with regard to the "next" redirection. Provided that one specifies a
value for "next" as part of the context

for the template that contains the comment form, users posting valid

comments without previewing them will indeed be redirected as
expected. However, if the commenter previews his comment before
posting, or if his comment contains errors, the "next" value is not
honoured.



If this is indeed a bug, it seems that it occurs in post_comment() in
django.contrib.comments.views.comments. Following is the relevant code
snippet:



if form.errors or preview:

...

return render_to_response(

template_list, {

"comment" : form.data.get("comment", ""),

"form" : form,

"next": next,

},

RequestContext(request, {})

)



As you can see, the "next" value in the template's context is set to
the variable next, which is set to a default value of None in the
function's declaration. As a result, when the comment form is
redisplayed for the user to preview or correct his comment, the form's
"next" hidden element is not created. Since "next" is not included in
the POST request made when the user submits his corrected or previewed
comment, the default template of comments/posted.html is rendered, and
the user is not redirected to the "next" value desired by the
developer.



Is this a bug that should be reported within the bug tracker, or
should I attempt to work around the problem by subclassing CommentForm
and adding fields to it?



Thanks,



Jeff
Reply all
Reply to author
Forward
0 new messages