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

Add SimplePathRouter#6789

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
auvipy merged 6 commits intoencode:masterfromsevdog:path-router
Jan 12, 2023
Merged

Add SimplePathRouter#6789

auvipy merged 6 commits intoencode:masterfromsevdog:path-router
Jan 12, 2023

Conversation

@sevdog
Copy link
Contributor

@sevdogsevdog commentedJul 6, 2019
edited
Loading

Description

AddSimplePathRouter to handle Django 2.xpath converters (refs#6148).

no-dap, stefanitsky, jun0jang, greenled, l1b3r, dyohan9, elonzh, AlexDaniel, gabbork, niccolomineo, and 11 more reacted with thumbs up emoji
@lovelydinosaur
Copy link
Contributor

Milestoning for review. Thanks!

sevdog and niccolomineo reacted with thumbs up emoji

@sevdog
Copy link
ContributorAuthor

It may be improved a bit if support for Django 1.x gets dropped (ie: some badif will be removed).

@rpkilby
Copy link
Contributor

I'm thinking this should be pushed to the 3.11 release, as that is when we'll likely drop Django 1.11

auvipy and niccolomineo reacted with thumbs up emoji

@lovelydinosaur
Copy link
Contributor

@rpkilby Good call

@sevdog
Copy link
ContributorAuthor

@rpkilby I have updated with CRUD tests and removed Django 1.11 compact. Tell me if everything is fine for you.

Copy link
Collaborator

@auvipyauvipy left a comment

Choose a reason for hiding this comment

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

can you skip tests for Django 1.11 for this PR? dj1.11 seems to be supported for some more time.

@sevdog
Copy link
ContributorAuthor

sevdog commentedNov 21, 2019
edited
Loading

can you skip tests for Django 1.11 for this PR? dj1.11 seems to be supported for some more time.

I have also added an assertion inSimplePathRouter.get_urls to raise an assertion error ifpath is not defined.

@sevdog
Copy link
ContributorAuthor

Ok... seems thatpytest.mark.skipif has not worked as expected. I will recheck it as soon as I can.

Copy link
Collaborator

@auvipyauvipy left a comment

Choose a reason for hiding this comment

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

can you rebase plz?

@sevdogsevdogforce-pushed thepath-router branch 2 times, most recently from17af0e1 toc1348cfCompareDecember 5, 2019 20:05
@sevdog
Copy link
ContributorAuthor

Rebased.

@lovelydinosaur
Copy link
Contributor

We've not dropped 1.11 on this pass, since its LTS.

Wondering if we might just outright switch the behavior on the next release - I'd rather wedidn't have two different have two different class implementations here.

@sevdog
Copy link
ContributorAuthor

@tomchristie you are right that a single-class implementation would be better.

I think that it can be done since the difference between those two are just two methods (get_urls andget_get_lookup_*). Those methods could be guided with some initialization param in class constructor.

I will try to refactor the code to have a single class.

@lovelydinosaur
Copy link
Contributor

When we drop 1.11 I'd actually probably be okay with us justcompletely switching to.path, so long as there'ssome kind of way for users to stick with the older behavior.

There's not really any great options for us here.

@sevdogsevdogforce-pushed thepath-router branch 2 times, most recently fromb1d231f to4696b19CompareDecember 12, 2019 19:42
@stalestalebot removed the stale labelOct 16, 2022
@sevdog
Copy link
ContributorAuthor

@auvipy I have rebased the branch with current master. Let me know if any other change is needed.

@auvipy
Copy link
Collaborator

the workflow need to be triggered

@camuthig
Copy link

I am playing around with this PR a bit, and in my case the major reason I am trying to move topath over regular expressions is to get custom converter behaviors for the URL arguments. I have a function that transforms my model IDs as they come into and out of the API layer, and I have implemented this as a custom converter to do something like<encoded:pk> instead of<int:pk> to automatically decode the IDs before they reach any of my code.

I am able to make this work with the code in this PR by settinglookup_value_regex = "encoded" on my views. However, since I am not defining a regex here, the usage feels a little unnatural. The same behavior would apply to standard converters, likeuuid.

This isn't a blocker, since it seems to be working just fine, but figured it was worth bringing up while it is still in PR. If there is an alternative way to approach these custom converters, let me know, and I will give that a try too.

sevdog reacted with thumbs up emojiauvipy reacted with heart emoji

@sevdog
Copy link
ContributorAuthor

@camuthig you pointed out an interesting use case. I could change the code to use an "alternative" attribute with a more readable name to solve it, but this feels quite a mock-fix IMO.

Preserve backwards compatibility and handle this use case in an elegant way is a bit hard.

I would like to go back to my first implementation where there were 2 base router classes: one for regex and one for path, so there is no chance of mixing code and name would be quite expressive (but the project ownerclearly expressed he prefers to have a single class).

The other way I see is to rework the current implementation in order to handle the choice between regex or path on aper view basis and not globally on the router, the problem here is to handleRoute andDynamicRoute url attribute (which is currently a way orrible hack also in this implementation, since there is no guarantee that route url templates do not contains any other regex-language characters other than an initial^ and a final$).

@tomchristie what do you think would fit better?

@auvipy
Copy link
Collaborator

Let us focus on the actual issue first. we are going to make the SimplRouter allowing new path based routing. should we also do the same for the DefaultRouter?

@sevdog
Copy link
ContributorAuthor

@auvipy, do you mean this line?

root_url=re_path(r'^$',view,name=self.root_view_name)

Apart from thatDefaultRouter should inherit fromSimpleRouter

@auvipy
Copy link
Collaborator

yeah, OK. I got commit access recently. so want to prioritize this one and draw a conclusion very soon to get this merged. of course considering all the natural edge cases are ironed out

notes_router=SimpleRouter()
notes_router.register(r'notes',NoteViewSet)

notes_path_router=SimpleRouter(use_regex_path=False)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we add another test case which use DeafultRouter please?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

It should not be a problem to replicate that test also with the other router.

@sevdog
Copy link
ContributorAuthor

I have added a small change to address the semantic issue pointed by@camuthig.

camuthig reacted with thumbs up emoji

@auvipy
Copy link
Collaborator

that's great. do you see any other documentation changes needed for this?


class MyPathModelViewSet(mixins.RetrieveModelMixin, viewsets.GenericViewSet):
lookup_field = 'my_model_uuid'
lookup_value_converter = 'uuid'
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we use better name for lookup_value_converter?any better suited name instead of converter?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I used "converter" since django calls these elementspath converters, maybe we can use the full expanded name to havelookup_value_pathconverter (orlookup_value_path_converter).

Any suggestion is welcome.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would inclined to@tomchristie for a better insight here as I'm bit confused about naming

Copy link
Collaborator

Choose a reason for hiding this comment

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

what about just lookup_value_path? this alighned with the name lookup_value_regex

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I think that it would be better to use the same naming of django.

In this case it was named "converter" thus an attribute which should define one should be named after that. In this way it is easier to find references to what this element does.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK I am going to merge this, we can improve it if needed

sevdog reacted with hooray emoji
@auvipyauvipy merged commit2d19f23 intoencode:masterJan 12, 2023
krysal pushed a commit to WordPress/openverse that referenced this pull requestDec 12, 2024
krysal pushed a commit to WordPress/openverse that referenced this pull requestDec 13, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@auvipyauvipyauvipy approved these changes

+3 more reviewers

@merwokmerwokmerwok left review comments

@ZagrebelinZagrebelinZagrebelin left review comments

@rpkilbyrpkilbyrpkilby requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.15

Development

Successfully merging this pull request may close these issues.

12 participants

@sevdog@lovelydinosaur@rpkilby@auvipy@hmpf@AlexDaniel@phillipuniverse@jackton1@sshishov@camuthig@merwok@Zagrebelin

[8]ページ先頭

©2009-2025 Movatter.jp