Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rework dynamic list/detail actions#5705

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
carltongibson merged 13 commits intoencode:masterfromrpkilby:action-decorator
Jan 25, 2018

Conversation

@rpkilby
Copy link
Contributor

@rpkilbyrpkilby commentedDec 22, 2017
edited
Loading

Pulling a slightly more manageable chunk out of#5605 for review. The goal is to remove logic from the router in order to make the viewsets and list/detail actions more introspectable.

Changes:

  • Deprecatedlist_route &detail_route in favor ofaction decorator w/detail boolean.
  • Deprecated dynamic list/detail route variants in favor ofDynamicRoute w/detail boolean.
  • Addeddetail boolean argument to regularRoute
  • A route'sdetail is now provided as aninitkwarg to the ViewSet, similar tosuffix.
  • AddedViewSet.get_extra_actions() to formalize extra action access.
  • Addedurl_path andurl_name toaction signature. These values are no longer set/altered by the router, and can be more reliably inspected by the parent viewset.
  • Refactored dynamic route generation, replacing protected method w/ internal instance method.

For the release notes, I've added a section to discuss the changes as a larger feature.

TODO:

  • Add release notes
  • Replace deprecated functions in tests
  • Update docs w/ changes

@rpkilbyrpkilby added this to the3.8 Release milestoneDec 22, 2017
Copy link
Collaborator

@carltongibsoncarltongibson left a comment

Choose a reason for hiding this comment

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

I think this is nicely done. Good benefits. Worth having.

@rpkilby, again, thanks for the effort. If you can tick off the TODOs lets have it. 👍

* Merged`list_route` and`detail_route` into a single`action` decorator.
* Get all extra actions on a`ViewSet` with`.get_extra_actions()`.
* Extra actions now set the`url_name` and`url_path` on the decorated method.
* Enable action url reversing through`.reverse_action()` method (added in 3.6.4)
Copy link
Collaborator

Choose a reason for hiding this comment

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

...3.7.4...

@rpkilbyrpkilbyforce-pushed theaction-decorator branch 2 times, most recently from96b3531 toa591e16CompareJanuary 3, 2018 23:15
@rpkilbyrpkilbyforce-pushed theaction-decorator branch 2 times, most recently from01f568f to151c0c9CompareJanuary 3, 2018 23:49
@rpkilby
Copy link
ContributorAuthor

Okay, this should be ready to go now. The docs changes are not completely trivial and feedback would be appreciated.

...

@detail_route(methods=['post'], permission_classes=[IsAdminOrIsSelf])
@action(methods=['post'], detail=True, permission_classes=[IsAdminOrIsSelf])
Copy link
Collaborator

@carltongibsoncarltongibsonJan 4, 2018
edited
Loading

Choose a reason for hiding this comment

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

At this point thedetail parameter is mysterious. (Worth explaining it below the example.)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Would it be sufficient to link to the viewset docs first? e.g., "go read this first, then come back here"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. (I was thinking along those lines... 🙂)

Perhaps moving the note from ln124 up and into aNote: section may be worthwhile. (Who reads about Routers before ViewSets?)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Updated the docs. Integrated line 124 into the start of the section.



defdetail_route(methods=None,**kwargs):
defaction(methods=None,detail=True,url_path=None,url_name=None,**kwargs):
Copy link
Collaborator

Choose a reason for hiding this comment

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

So, thedetail parameter...:

  • Do we want an implied default? Or do we want to make it required, with a helpful assertion?
  • If implied which is the best default? i.e. Do we generatelist ordetail routes if you don't pass the parameter.
  • Do we want to document whichever we choose as not passing the parameter?@action(detail=True) and@action() in all the examples, say?

Not sure what I think there.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Do we want an implied default? Or do we want to make it required, with a helpful assertion?

I don't think a default is beneficial here. Making it a required arg seems 👍 to me.

Copy link
Collaborator

@carltongibsoncarltongibson left a comment

Choose a reason for hiding this comment

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

OK. This looks good.

I'm just going to pause on this for now, since once it's in we're kind of committed to rolling a 3.8. (which is fine, but I just want to plan that first. 🙂) //cc@tomchristie

@carltongibsoncarltongibson merged commit73203e6 intoencode:masterJan 25, 2018
@rpkilbyrpkilby deleted the action-decorator branchJanuary 25, 2018 08:41
@rpkilbyrpkilby mentioned this pull requestJan 25, 2018
7 tasks
@xordoquy
Copy link
Contributor

It seems that there are some regression on list_route & detail_route.
If nourl_name was provided, it used to default on theurl_path:

url_name = initkwargs.pop("url_name", None) or url_path

With the new code, it default to the function name:

func.url_name = url_name or func.__name__.replace('_', '-')

which breaks a couple of tests here and there.

@carltongibson
Copy link
Collaborator

Hey@xordoquy. Would you be able to put a regression test together for that?

@xordoquy
Copy link
Contributor

need to investigate another issue and I'll do that.

@rpkilby
Copy link
ContributorAuthor

Hi@xordoquy - this was an intentional change, as theurl_path is not always a suitable default for the name. eg, when the path contains URL parameters.

Also, sorry for being afk lately - life has been pretty busy the last couple of months.

@xordoquy
Copy link
Contributor

that's ok, but this should be added to the breaking changes since it requires changes ondetail_route andlist_route.

@rpkilby
Copy link
ContributorAuthor

Maybe the path forward is foraction to have this new behavior, withlist_route anddetail_route maintaining the old behavior.

@carltongibson
Copy link
Collaborator

I need to have a look at exactly what’s going on here but could we not handle the change in the shim?

@carltongibson
Copy link
Collaborator

@rpkilby you must not apologise for life. Contribution to Open Source needs to be scoped. There is no problem with that. Ever. The only problem is with the opposite. 🙂

@rpkilby
Copy link
ContributorAuthor

Thanks - just letting you know I'm still around.

@xordoquy
Copy link
Contributor

xordoquy commentedApr 4, 2018
edited
Loading

Maybe the path forward is for action to have this new behavior, with list_route and detail_route maintaining the old behavior.

sounds sensible to me.

Also, sorry for being afk lately

Didn't react but seconding@carltongibson on that point, you don't need to apologize for that. You did a lot of work so far, and for that we owe you one.

@carltongibson
Copy link
Collaborator

v.3.8.1 restores the old behaviour (via#5915). It's on PyPI now.

jaap3 reacted with hooray emoji

@jaap3
Copy link
Contributor

Thanks you for the fix and the prompt release of v3.8.1

carltongibson reacted with thumbs up emoji

nijel added a commit to WeblateOrg/weblate that referenced this pull requestApr 18, 2018
This is needed to avoid deprecation warnigs on recent versions,seeencode/django-rest-framework#5705Signed-off-by: Michal Čihař <michal@cihar.com>
@Allan-Nava

This comment has been minimized.

@carltongibson
Copy link
Collaborator

@Allan-Nava Please direct usage questions to Stack Overflow or the mailing list. (Again, the issue tracker is for bug reports.) Thanks.

Allan-Nava reacted with confused emoji

pchiquet pushed a commit to pchiquet/django-rest-framework that referenced this pull requestNov 17, 2020
* Merge list/detail route decorators into 'action'* Merge dynamic routes, add 'detail' attribute* Add 'ViewSet.get_extra_actions()'* Refactor dynamic route checking & collection* Refactor dynamic route generation* Add 'ViewSet.detail' initkwarg* Fixup schema test* Add release notes for dynamic action changes* Replace list/detail route decorators in tests* Convert tabs to spaces in router docs* Update docs* Make 'detail' a required argument of 'action'* Improve router docs
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@carltongibsoncarltongibsoncarltongibson approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

3.8.0 Release

Development

Successfully merging this pull request may close these issues.

5 participants

@rpkilby@xordoquy@carltongibson@jaap3@Allan-Nava

[8]ページ先頭

©2009-2025 Movatter.jp