Opened 13 years ago
Closed 13 years ago
#16377 closed Cleanup/optimization (fixed)
"Conditionally disabling actions" documentation needs updating
Reported by: | 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 )
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)
Change History (11)
comment:1 by , 13 years ago
Description: | modified (diff) |
---|
by , 13 years ago
Attachment: | 16377.diff added |
---|
comment:2 by , 13 years ago
Easy pickings: | set |
---|---|
Has patch: | set |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 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 , 13 years ago
Please don't use has_key
. It's idiomatic to do:
if 'delete_selected' in actions: # whatever
by , 13 years ago
Attachment: | 16377.2.diff added |
---|
comment:6 by , 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 , 13 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Thanks for the updated patch. IMO, writing the key twice is the lesser evil in this case ;)
Fixed formatting (please use a little bit of wiki syntax and the preview to make your reports readable).