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

Add '.basename' and '.reverse_action()' to ViewSet #5648

Merged
merged 3 commits into from
Dec 4, 2017

Conversation

rpkilby
Copy link
Member

@rpkilby rpkilby commented Dec 4, 2017

Just breaking out a portion of #5605.

Description

ViewSets cannot effectively reverse their action URLs, as they aren't aware of the basename they were registered to the router with. This value can be hardcoded in the view class, however this is problematic when the ViewSet is registered with a different basename.

  • Routers now provide the basename with the viewset's initkwargs.
  • Added .reverse_action() convenience method to viewsets.

@carltongibson carltongibson added this to the v3.7.4 milestone Dec 4, 2017
@carltongibson
Copy link
Collaborator

OK. Good: I was going to look at #5605 so breaking it up is a win.

Copy link
Collaborator

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass I'd be happy to see this go in as is.

Anyone else want to review?

@tomchristie
Copy link
Member

Bit agnostic on this - I'll leave it to you fellas.

@rpkilby
Copy link
Member Author

rpkilby commented Dec 4, 2017

For context, supporting #5605 would at least require the router to provide the basename to the the viewset's initkwargs.

.revese_action() isn't essential, but it seemed beneficial to provide a more formalized method of getting the action URLs.

@carltongibson
Copy link
Collaborator

...supporting #5605 ...

Which is taking on (inter alia) #2062 — Support extra actions in Browsable API — which is from Nov 2014. It would be nice to take that on. (And it seems a reasonable request right...)

OK. Lets have this.

@carltongibson carltongibson merged commit 7855d3b into encode:master Dec 4, 2017
@rpkilby rpkilby deleted the viewset-reverse branch December 4, 2017 11:08
pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull request Nov 17, 2020
* Router sets 'basename' on ViewSet

* Add 'ViewSet.reverse_action()' method

* Test router setting initkwargs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants