views:

48

answers:

1

I am working with the new version of django-threadedcomments and making some progress; it integrates nicely with django's commenting system, however, I'm stuck and not sure how to proceed.

For threaded comments to work, the user needs to select a comment to "reply to" and then the correct submit form is brought up (with the appropriate hidden fields) via javascript.

Not using javascript, I would simply use:

{% render_comment_form for [object] with [parent_id] %}

However, I am not sure how I can use this template tag within a javascript function because it will compile/create itself only once; how can I pass it the [parent_id] variable dynacmically via javascript/ajax?

+1  A: 

You could do this with Ajax, passing the id of the comment to a dedicated view which just renders the form, but I don't think there's any need. I haven't looked at threaded-comments, but I guess that each comment is of the same object type. Therefore, the only thing that differs in the rendered form would be the id of the comment you're replying to.

So, use the normal template tag render a default form using the first comment on the page, inside a hidden div. Then all your javascript function needs to do is to change the value of the object_pk hidden field within that form, depending on the comment you're replying to. If that id isn't already easily accessible, make it available in the template via the class or id of each comment. Then you can parse it out of there, stuff it into your ready-made form, display it, and you should be good to go.

Daniel Roseman
I had tried changing the `parent` value this way (in the hidden field), however, I think django is using this field when creating the security hash, because whenever I swap it out, I get a security error saying the form has been tampered with (which it has!). That's why I thought I would have to generate a new one from scratch each time ...
thornomad