Opened 6 years ago

Closed 3 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 6 years ago.
10838.diff (1.2 KB) - added by thejaswi_puthraya 6 years ago.
git-patch against the latest checkout

Download all attachments as: .zip

Change History (11)

Changed 6 years ago by pigletto

comment:1 Changed 6 years ago by pigletto

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from 1.0 to SVN

comment:2 Changed 6 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 6 years ago by thejaswi_puthraya

git-patch against the latest checkout

comment:3 Changed 6 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 6 years ago by anonymous

  • Triage Stage changed from Unreviewed to Design decision needed

comment:5 Changed 6 years ago by wayla

  • Cc waylan@… added

comment:6 Changed 5 years ago by SmileyChris

  • Severity set to Normal
  • Type set to New feature

comment:7 Changed 4 years ago by thejaswi_puthraya

  • Easy pickings unset
  • UI/UX unset

Slightly related to #12742

comment:8 Changed 4 years ago by thejaswi_puthraya

comment:9 Changed 3 years ago by jacob

  • Resolution set to wontfix
  • Status changed from new to closed

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