Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Improvement) Support custom actions via ActionAPI #115

Merged
merged 1 commit into from
Oct 6, 2022

Conversation

stevelacey
Copy link
Contributor

@stevelacey stevelacey commented Oct 3, 2022

Support custom actions via PUT requests that proxy to model or view methods.

  1. Inherit ActionAPI in the view
  2. Define some actions on the view (a list of strings)
  3. Register the action route (last, it's wildcard)
path("profiles/<uuid:id>/", views.ProfileDetail.as_view()),
path("profiles/<uuid:id>/<str:action>/", views.ProfileDetail.as_view()),

ActionAPI will call a corresponding view method if one exists, this is handy if more complex validation needs to happen before the action is run, otherwise, the model method is called directly.

The bundle and request.user are passed through via kwargs to the action be it a model or view action, primarily this is so that model actions can store the user acting upon the instance.

Action names are defined in snake_case but passing kebab-case via the URL is supported.

ActionAPI can be used with or without DetailAPI and UpdateAPI.

@stevelacey stevelacey force-pushed the improvement/actions-api branch 4 times, most recently from 6ce8004 to b587b39 Compare October 3, 2022 11:37
@stevelacey stevelacey changed the title (Improvement) Support custom actions (Improvement) Support custom actions via ActionAPI Oct 3, 2022
@stevelacey stevelacey force-pushed the improvement/actions-api branch 6 times, most recently from d074fc6 to c3ae296 Compare October 6, 2022 05:17
@stevelacey stevelacey force-pushed the improvement/actions-api branch from c3ae296 to 15dbfe0 Compare October 6, 2022 05:57
@stevelacey stevelacey merged commit a58127a into master Oct 6, 2022
@stevelacey stevelacey deleted the improvement/actions-api branch October 6, 2022 06:03
This was referenced Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant