question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple actions in lists

See original GitHub issue

For a project of mine, I need to select multiple items to carry out an action (in my case consolidate duplicate records).

I’ve started implementing a generalised format so other actions can be added by individuals (inspired by actions in Django with some implementation details cribbed from flask-peewee’s admin module).

I’ve started with delete selected. I plan on cleaning it up for more general use but wanted to open it up to feedback before I go completely down the path.

https://github.com/beyondwords/flask-admin/commit/c7a3ba94fa425610b41df8b3fd59d6128bf7a744

Please contribute any comments on architecture.

  • An action is called with the BaseModelView sub-class, request, and id_list
  • The action must have label specified for the drop-down list
  • The action must check for permissions is_accessible, can_delete etc.
  • The action can either return a redirect/rendered page or None and use a flash message to return to the list
  • The action can be a simple function or a class instance with __call__ implemented

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
mrjoescommented, Aug 19, 2012

Hi,

I pushed my changes. You can see how mass delete action was implemented for SQLA models here:

https://github.com/mrjoes/flask-admin/blob/master/flask_admin/contrib/sqlamodel/view.py#L553

So, if you want to add your custom action:

  1. Create method which accepts list of ids
  2. Decorate it with @action
  3. Change is_action_allowed to do some fancy logic

Checkboxes won’t be displayed if no actions are visible (drop down element won’t be displayed either). I also separated actions library into separate file, so file admin is now using it and can mass-delete files too.

Hope it helps.

Serge.

On Sun, Aug 19, 2012 at 6:02 AM, F. Gabriel Gosselin < notifications@github.com> wrote:

I agree that Flask-Peewee’s approach is not ideal (the delete and export are hard coded).

Please do look at the code I contributed. It does have the potential to be flexible. Actions can be added to self._actions through a setter instead to make it more flexible on a per-AdminModel basis.

In particular I’m curious how you would handle universal actions (available to all Admin lists).

— Reply to this email directly or view it on GitHubhttps://github.com/mrjoes/flask-admin/issues/44#issuecomment-7850159.

0reactions
R2calexcommented, Apr 22, 2019

Hi,

I pushed my changes. You can see how mass delete action was implemented for SQLA models here:

https://github.com/mrjoes/flask-admin/blob/master/flask_admin/contrib/sqlamodel/view.py#L553

So, if you want to add your custom action:

  1. Create method which accepts list of ids
  2. Decorate it with @action
  3. Change is_action_allowed to do some fancy logic

Checkboxes won’t be displayed if no actions are visible (drop down element won’t be displayed either). I also separated actions library into separate file, so file admin is now using it and can mass-delete files too.

Hope it helps.

Serge.

On Sun, Aug 19, 2012 at 6:02 AM, F. Gabriel Gosselin < notifications@github.com> wrote:

I agree that Flask-Peewee’s approach is not ideal (the delete and export are hard coded). Please do look at the code I contributed. It does have the potential to be flexible. Actions can be added to self._actions through a setter instead to make it more flexible on a per-AdminModel basis. In particular I’m curious how you would handle universal actions (available to all Admin lists). — Reply to this email directly or view it on GitHubhttps://github.com/mrjoes/flask-admin/issues/44#issuecomment-7850159.

Page not found 😦, could you make it post it again please?

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Using multiple Actions in Action<object> list - Stack Overflow
Using multiple Actions in Action<object> list · 1 · How Updater. · Simply loop your elements in the list and call the delegate:...
Read more >
Add multiple actions and advanced options to a cloud flow
In this procedure, you'll add an action in the middle of the flow. This action will save a file in your Dropbox, archiving...
Read more >
Use list actions in Shortcuts on iPhone or iPad - Apple Support
When working with multiple items in a shortcut, use list actions to create ordered lists of data that are passed onto the next...
Read more >
Two possible list designs: How to depict per-item actions?
The debate is whether to put the actions on each list item, hidden in an ellipsis icon, or at the top of the...
Read more >
[List] Allow adding multiple secondary actions #31865 - GitHub
To allow both actions, we add two IconButtons to the list items (see example above). Our application is mainly used on desktop browsers,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found