Opened 8 years ago

Closed 4 years ago

#10838 closed New feature (wontfix)

Pass user object to CommentForm (initial data)

Reported by: pigletto Owned by: nobody
Component: contrib.comments Version: master
Severity: Normal Keywords: comments
Cc: pigletto@…, waylan@… Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


CommentForm should check if current user is authenticated and if so, initial data for user's 'name' and 'email' should be filled.
Also, it is very useful to have access to at last user object (request?) in form's init. This way you're able to customize it a lot, eg. hide some fields or mark them readonly depending on user.
Proposed patch passes user object to CommentForm and then initial data are populated with 'name' and 'email' from user object

Attachments (2)

comments.diff (2.1 KB) - added by pigletto 8 years ago.
10838.diff (1.2 KB) - added by Thejaswi Puthraya 8 years ago.
git-patch against the latest checkout

Download all attachments as: .zip

Change History (11)

Changed 8 years ago by pigletto

Attachment: comments.diff added

comment:1 Changed 8 years ago by pigletto

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Version: 1.0SVN

comment:2 Changed 8 years ago by Thejaswi Puthraya

Ideally, you shouldn't change the API because Django is committed to
backwards-compatibility. The CommentForm always had access to initial
kwarg that would display the default values.

I have attached a patch that doesn't break compatibility but I somehow
feel that I am violating DRY at

Let's see what the core-devs have to tell.

Changed 8 years ago by Thejaswi Puthraya

Attachment: 10838.diff added

git-patch against the latest checkout

comment:3 Changed 7 years ago by pigletto

Cc: pigletto@… added

Patch from thejaswi_puthraya only adds username and e-mail to inital_data while my original idea was also to pass user object to form's init function. This way it is possible to customize form, eg. by hiding some fields for specific users.
Backward compatibility is only broken if one has own comment form with overriden init function that doesn't accept kwargs.

comment:4 Changed 7 years ago by anonymous

Triage Stage: UnreviewedDesign decision needed

comment:5 Changed 7 years ago by Waylan Limberg

Cc: waylan@… added

comment:6 Changed 6 years ago by Chris Beaven

Severity: Normal
Type: New feature

comment:7 Changed 5 years ago by Thejaswi Puthraya

Easy pickings: unset
UI/UX: unset

Slightly related to #12742

comment:8 Changed 5 years ago by Thejaswi Puthraya

comment:9 Changed 4 years ago by Jacob

Resolution: wontfix
Status: newclosed

django.contrib.comments has been deprecated and is no longer supported, so I'm closing this ticket. We're encouraging users to transition to a custom solution, or to a hosted solution like Disqus.

The code itself has moved to; if you want to keep using it, you could move this bug over there.

Note: See TracTickets for help on using tickets.
Back to Top