Opened 16 years ago
Closed 5 years ago
#7537 closed New feature (invalid)
Make RegexURLResolver easier to subclass
Reported by: | Kenneth Arnold | Owned by: | nobody |
---|---|---|---|
Component: | Core (URLs) | Version: | dev |
Severity: | Normal | Keywords: | url, urlpatterns, resolver |
Cc: | kenneth.arnold@…, eallik@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Referencing the django-developers discussion, here's some simple patches to make the URL resolver easier to customize.
First is a nearly minimal patch to convert the url_patterns property to an accessor, get_url_patterns, to ease subclassing, and make the other methods use that consistently instead of duplicating its functionality. With only this patch you can make your own URL resolver without duplicating code, but it's still not clean.
The second patch cleans up the situation by abstracting the core functionality of a regex URL resolver into BaseRegexURLResolver
.
The third patch is an example of how newforms-admin might use this for URL dispatching. I don't have a deep understanding about what's going on, so treat what I did just as an example. Perhaps the cleanest way to accomplish some of what the old ad-hoc resolver did is to override resolve
, and if super().resolve
returns None, do the ad-hoc stuff.
You'd use a custom resolver in your urlconf like this:
urlpatterns += [AdminSite(r'^admin/')]
i.e., like a normal include
(at least, what that include
looks like under the hood).
The newforms-admin change would be backwards-incompatible, so if people think it's a good idea, it should get a separate ticket.
About the accessor: properties don't inherit well. Could add a url_patterns = property(lambda self: self.get_url_patterns())
if that's not too ugly.
Attachments (3)
Change History (13)
by , 16 years ago
Attachment: | dj-urlresolver-patch2.patch added |
---|
comment:1 by , 16 years ago
Needs tests: | set |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 16 years ago
Cc: | added |
---|
comment:3 by , 16 years ago
Cc: | added |
---|
comment:4 by , 16 years ago
Wouldn't this also solve the issue of not being able to reverse or {% url %} "into" the admin interface?
comment:6 by , 16 years ago
I cannot see how. If #6470 was applied, would I be able to do {% url admin_edit_view mymodel %}?
comment:7 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → New feature |
comment:8 by , 13 years ago
Easy pickings: | unset |
---|---|
Triage Stage: | Design decision needed → Accepted |
UI/UX: | unset |
me of a few years ago was silly, any way to better organize the code is a good idea.
comment:9 by , 12 years ago
Component: | Core (Other) → Core (URLs) |
---|
comment:10 by , 5 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
It seems that this ticket is not valid after #28593.
Patch 2: extract base functionality