views:

343

answers:

2

This is how I want commenting to work on my site:

  • if the user is logged in, they are presented with an "add comments" box which has a text field for the comment text, and a checkbox that will post the comment anonymously if checked
  • if the user is not logged in, it will present the user with everything above, plus an extra text field where they can enter a display name.

SO basically if the user is logged in they can ither comment anonymously or with their username. If they aren't logged in, they can either post anonymously or they can make up a name on the spot for display purposes only.

How can I go about doing this? I already have the template set up which presents the user with the appropriate textboxes and checkboxes depending on their logged in status.

I thought about a wrapper function around django.contrib.comments.views.post_comment, but that view only takes a request object, which is immutable. How would you go about this?

A: 

Just write your view cribbing what you can from django.contrib.comments.views.post_comment but more suited to your use case. Use a form which supports your specific UI (in terms of presentation and validation). It looks as if the email field is not nullable so you will have to put a dummy value in if one is not available.

It would have been nice if you could have wrapped the existing functionality, but I don't think that's practical. For a wrapping approach to work, the existing code would have had to be written with wrappability in mind - and that hasn't happened.

Vinay Sajip
+1  A: 

Sounds like you might be needing a custom comments app -- check out the docs. Here's another example (this one adds a CAPTCHA to the standard comment form). Seems like a pretty straightforward process :)

elo80ka