Django

Code

Ticket #6991 (new)

Opened 1 year ago

Last modified 1 year ago

Omit redundant "if" judgements

Reported by: Liang Feng <hutuworm@gmail.com> Assigned to: alexkoshelev
Milestone: Component: django.contrib.admin
Version: newforms-admin Keywords: nfa-someday yandex-sprint ep2008
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description (Last modified by ramiro)

django/contrib/admin/views/decorators.py:
if request.user.is_authenticated() and request.user.is_staff:

### COMMENT: request.user.is_staff is True implied that request.user.is_authenticated() is True, so request.user.is_authenticated() could be omitted.

docs/authentication.txt:
if not (request.user.is_authenticated() and request.user.has_perm('polls.can_vote')):

### COMMENT: request.user.has_perm('polls.can_vote') is True implied that request.user.is_authenticated() is True, so request.user.is_authenticated() could be omitted.

p.s. may save some precious cpu cycles on Google App Engine. :P

Attachments

6991.diff (2.0 kB) - added by alexkoshelev on 07/12/08 05:28:51.
Patch for this ticket and #6990
6991.2.diff (3.3 kB) - added by Ivan Sagalaev <Maniac@SoftwareManiacs.Org> on 07/12/08 09:21:25.
New patch with couple more places

Change History

06/16/08 15:51:17 changed by ramiro

  • needs_better_patch changed.
  • description changed.
  • needs_tests changed.
  • needs_docs changed.

06/28/08 15:31:26 changed by Karen Tracey <kmtracey@gmail.com>

  • keywords changed from Omit redundant "if" judgements to nfa-someday.
  • version changed from SVN to newforms-admin.
  • stage changed from Unreviewed to Design decision needed.

Like #6990, these checks were not redundant before the fix for #3032. They are still there in newforms-admin so someone needs to decide if it is worth removing them.

07/12/08 04:39:16 changed by alexkoshelev

  • owner changed from nobody to alexkoshelev.

07/12/08 05:28:51 changed by alexkoshelev

  • attachment 6991.diff added.

Patch for this ticket and #6990

07/12/08 08:20:06 changed by Honza_Kral

  • keywords changed from nfa-someday to nfa-someday ep2008.
  • needs_better_patch set to 1.
  • has_patch set to 1.
  • stage changed from Design decision needed to Accepted.

After #3032 being fixed, this is really trivial, all tests pass. Just make sure to catch every occurrence of this behavior.

07/12/08 09:21:25 changed by Ivan Sagalaev <Maniac@SoftwareManiacs.Org>

  • attachment 6991.2.diff added.

New patch with couple more places

07/12/08 09:25:16 changed by Ivan Sagalaev <Maniac@SoftwareManiacs.Org>

  • needs_better_patch deleted.

Catched couple more places. Looks like they're all here. Honza mentioned create_update.py in generic views but there are only standalone request.user.is_authenticated() checks that are all needed.

07/12/08 09:28:25 changed by Honza_Kral

  • stage changed from Accepted to Ready for checkin.

thanks

07/13/08 07:33:27 changed by Ivan Sagalaev <Maniac@SoftwareManiacs.Org>

  • keywords changed from nfa-someday ep2008 to nfa-someday yandex-sprint ep2008.

Add/Change #6991 (Omit redundant "if" judgements)




Change Properties
Action