tags:

views:

81

answers:

2

When I post a comment with the django's comment framework, I have a hidden next value set in hopes that once the comment is posted, it will bring the user to view their own comment. The next field renders like this:

<input type="hidden" name="next" value="http://example.com/item/1#c23" />

However, when a comment is posted, django is adding a ?c=23 to the end of the url so the fully formed url that the user is redirected to becomes:

http://example.com/item/1#c23?c=23

In Firefox and Safari (brief testing) this prevents the page from moving down to the correct id=23 and just shows the very top of the page (I want it to show the just posted comment). Removing the ?c=23 fixes the problem (by hand) but I don't know how to tell Django to stop adding it.

Ideas?

A: 

This jQuery line allows you to change the current URL:

$(this).attr("href", "NEW_URL");

Replace NEW_URL by the new URL. You can split http://example.com/item/1#c23?c=23 using the question mark and then use the first part of the array as the new URL.

Nick Brooks
+1  A: 

Not a solution to your problem but just wanted to add that this is a bug in Django. It would be great if you could open a ticket for it.

For 1.1, it seems ticket 10585 took care of already existing query strings in the next value. That is, if next was http://example.com/item/1?a=1 then it became http://example.com/item/1?a=1?c=23 after a comment was posted. The code changes look pretty simple so you might even be able to provide a patch yourself.

Good luck!

lemonad
Do you consider the best approach another hidden field in the comment form that says whether to include the `?c=` bit or not? Or rather a setting in `settings.py`? I can see why some people would want to use it - it's just that I don't. Thanks.
thornomad
Or maybe another truth tests to see if the redirect is taking you back to the same page the comment was posted on and a `#` is present in the url?
thornomad
Perhaps I'm reading your comments incorrectly but I don't see that it needs to be more complicated than identifying that there is a # fragment in the URL and inserting `?c=23` before it. That is, in your case the URL should become `http://example.com/item/1?c=23#c23` after posting the comment.
lemonad
Duh! That would, of course, be a *lot* easier. Smile. I'll look at that again - thanks.
thornomad
You're welcome :D
lemonad