Opened 13 years ago

Closed 13 years ago

#16377 closed Cleanup/optimization (fixed)

"Conditionally disabling actions" documentation needs updating

Reported by: pgullekson@… Owned by: nobody
Component: Documentation Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by Aymeric Augustin)

The docs in question are:
https://docs.djangoproject.com/en/1.3/ref/contrib/admin/actions/#conditionally-enabling-or-disabling-actions

The suggestion is to use del actions['delete_selected'], which worked fine in Django 1.2. However, because of changes made to django.contrib.admin.options.get_actions, in the case that IS_POPUP_VAR == True, this del statement will result in an exception. Need a try/except or something.

Attachments (2)

16377.diff (570 bytes ) - added by Aymeric Augustin 13 years ago.
16377.2.diff (622 bytes ) - added by Aymeric Augustin 13 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 by Aymeric Augustin, 13 years ago

Description: modified (diff)

Fixed formatting (please use a little bit of wiki syntax and the preview to make your reports readable).

by Aymeric Augustin, 13 years ago

Attachment: 16377.diff added

comment:2 by Aymeric Augustin, 13 years ago

Easy pickings: set
Has patch: set
Triage Stage: UnreviewedAccepted

comment:3 by Julien Phalip, 13 years ago

Patch needs improvement: set

I think it would be a bit cleaner and read better using the conditional test: if actions.has_key('delete_selected'). What do you think?

comment:4 by Jannis Leidel, 13 years ago

Please don't use has_key. It's idiomatic to do:

if 'delete_selected' in self.actions:
    # whatever
Version 0, edited 13 years ago by Jannis Leidel (next)

comment:5 by Julien Phalip, 13 years ago

Agreed, that's even better. Thanks for correcting me :p

by Aymeric Augustin, 13 years ago

Attachment: 16377.2.diff added

comment:6 by Aymeric Augustin, 13 years ago

Patch needs improvement: unset

I'm sure we could write a whole book on the respective merits of

mydict.pop('mykey', None)    # that's unpythonic.

vs.

if 'mykey' in mydict:
    del mydict['mykey']      # we're writing the dict and key names twice!

vs.

try:
    del mydict['mykey']
except KeyError:
    pass                     # four lines for this?

Anyway, here's an updated patch...

Now, back to triaging the unreviewed tickets queue.

comment:7 by Julien Phalip, 13 years ago

Triage Stage: AcceptedReady for checkin

Thanks for the updated patch. IMO, writing the key twice is the lesser evil in this case ;)

comment:8 by Jannis Leidel, 13 years ago

FTR, I've mentioned that because Alex specifically removed the use of has_key in r14392 to speed up Django a bit. I think it was regarding using Django on PyPy.

comment:9 by Jannis Leidel, 13 years ago

Resolution: fixed
Status: newclosed

In [16567]:

Fixed #16377 -- Fixed docs about how to disable the admin actions conditionally to match the current code. Thanks, Aymeric Augustin.

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