Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#10505 closed (fixed)

Integrate django-batchadmin

Reported by: jezdez Owned by: jacob
Component: contrib.admin Version: master
Severity: Keywords:
Cc: bartTC Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:

Description

The integration of django-batchadmin is one of the "maby" features of 1.1 (Admin-02).

It allows the user to define lists of callables in ModelAdmin classes that are used to perform custom actions on a list of objects retrieved from checkbox inputs.

Attachments (10)

admin-actions.1.diff (15.9 KB) - added by jezdez 5 years ago.
Initial patch, partly based on django-batchadmin
admin-actions.2.diff (23.9 KB) - added by jezdez 5 years ago.
Refactored action loading and choices. Only the queryset of the selection is passed to actions (in model admin methods and function) now. Model methods don't get the whole queryset anymore but are called each (~obj.action()). Added tests, yay!
admin-actions.3.diff (24.4 KB) - added by jezdez 5 years ago.
Small fix for admin_registration tests
admin-actions.4.diff (24.4 KB) - added by jezdez 5 years ago.
Fixed redundancy in condition with callable_actions dictionary
admin-actions.5.diff (24.4 KB) - added by jezdez 5 years ago.
Isolated the logic to look for callable actions inside the get_action method
admin-actions.6.diff (29.9 KB) - added by jezdez 5 years ago.
Updated to work with merged list_editable code. Now only passes the queryset to response_action method and fixes some stylesheet issues.
admin-actions.7.diff (34.4 KB) - added by jezdez 5 years ago.
Fixed problem with URLs in delete_selected action in a backwards compatible way.
admin-actions.8.diff (34.6 KB) - added by bartTC 5 years ago.
URL resolving now takes care of AdminSite's
admin-actions.9.diff (34.8 KB) - added by jezdez 5 years ago.
Refactored get_action code. Removed support for model level actions. Added ability to add actions to all model admins of a admin site. Subclasses are now loaded from subclasses, too (get_actions). Now passes the request to get_actions and get_action_choices, e.g. for user permission dependent actions. Courtesy of Alex Gaynor
admin-actions.diff (34.7 KB) - added by Alex 5 years ago.

Download all attachments as: .zip

Change History (18)

Changed 5 years ago by jezdez

Initial patch, partly based on django-batchadmin

comment:1 Changed 5 years ago by jezdez

  • Has patch set
  • Needs documentation set
  • Needs tests set
  • Owner changed from nobody to jezdez
  • Patch needs improvement unset
  • Status changed from new to assigned

The current code can also be found at Github, http://github.com/jezdez/django/commits/admin-actions.

The code differs from django-batchadmin in multiple ways:

  • Removed dependency on jQuery, added unobtrusive Actions code
  • Replaced select/deselect button with global checkbox (screenshot: http://www.quicksnapper.com/jezdez/image/batchadmin)
  • Added ability to directly use callables as actions, also looks in model class for action with given name (~list_display)
  • Fixes various bugs in batchadmin regarding non-ASCII data, e.g. i18n

Needs tests and docs

comment:2 Changed 5 years ago by Alex

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 5 years ago by jacob

  • milestone changed from 1.1 to 1.1 beta
  • Owner changed from jezdez to jacob
  • Status changed from assigned to new

Changed 5 years ago by jezdez

Refactored action loading and choices. Only the queryset of the selection is passed to actions (in model admin methods and function) now. Model methods don't get the whole queryset anymore but are called each (~obj.action()). Added tests, yay!

Changed 5 years ago by jezdez

Small fix for admin_registration tests

Changed 5 years ago by jezdez

Fixed redundancy in condition with callable_actions dictionary

Changed 5 years ago by jezdez

Isolated the logic to look for callable actions inside the get_action method

Changed 5 years ago by jezdez

Updated to work with merged list_editable code. Now only passes the queryset to response_action method and fixes some stylesheet issues.

comment:4 Changed 5 years ago by jezdez

Oh, the last patch also includes a better default delete action that will ask for confirmation before deleting, courtesy of Martin Mahner.

Changed 5 years ago by jezdez

Fixed problem with URLs in delete_selected action in a backwards compatible way.

comment:5 Changed 5 years ago by jacob

There's a set of usecases I shared with jezdez that I want this to solve; posting 'em here for posterity:

  1. I want to be able to add an action to a particular modeladmin and have that action available. I assume this works :)
  2. I want to be able to create an abstract ModelAdmin subclass -- think GeoAdmin -- that has actions available to any admin registered with that subclass or any of *its* subclasses.
  3. I want to be able to define some abstract function and make it available for anyone who wants to use it as an action on some modeladmin I don't know anything about (this is the reusable app usecase).
  4. I want to be able to create an action that's available on every registered model on my site that doesn't explicitly exclude that action. Think a "csv export" reusable app that provides an "Export" feature on every changelist.
  5. Finally, I want to be able to reach in and dynamically add an action to some other model admin -- think reaching in and adding a "ban this user" action to UserAdmin.

comment:6 Changed 5 years ago by bartTC

  • Cc bartTC added

Changed 5 years ago by bartTC

URL resolving now takes care of AdminSite's

Changed 5 years ago by jezdez

Refactored get_action code. Removed support for model level actions. Added ability to add actions to all model admins of a admin site. Subclasses are now loaded from subclasses, too (get_actions). Now passes the request to get_actions and get_action_choices, e.g. for user permission dependent actions. Courtesy of Alex Gaynor

Changed 5 years ago by Alex

comment:7 Changed 5 years ago by jacob

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

(In [10121]) Fixed #10505: added support for bulk admin actions, including a globally-available "delete selected" action. See the documentation for details.

This work started life as Brian Beck's "django-batchadmin." It was rewritten for inclusion in Django by Alex Gaynor, Jannis Leidel (jezdez), and Martin Mahner (bartTC). Thanks, guys!

comment:8 Changed 3 years ago by jacob

  • milestone 1.1 beta deleted

Milestone 1.1 beta deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.