Opened 5 years ago

Closed 5 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 5 years ago.
16377.2.diff (622 bytes) - added by Aymeric Augustin 5 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 5 years ago by Aymeric Augustin

Description: modified (diff)

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

Changed 5 years ago by Aymeric Augustin

Attachment: 16377.diff added

comment:2 Changed 5 years ago by Aymeric Augustin

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

comment:3 Changed 5 years ago by Julien Phalip

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 Changed 5 years ago by Jannis Leidel

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

if 'delete_selected' in actions:
    # whatever
Last edited 5 years ago by Jannis Leidel (previous) (diff)

comment:5 Changed 5 years ago by Julien Phalip

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

Changed 5 years ago by Aymeric Augustin

Attachment: 16377.2.diff added

comment:6 Changed 5 years ago by Aymeric Augustin

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 Changed 5 years ago by Julien Phalip

Triage Stage: AcceptedReady for checkin

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

comment:8 Changed 5 years ago by Jannis Leidel

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 Changed 5 years ago by Jannis Leidel

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