Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#13922 closed (fixed)

Enhanced URL Resolver Match

Reported by: nbstrite Owned by: nobody
Component: Uncategorized Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When Django 1.1 was released URLs gained the ability to be nested with
namespaces by adding "app_name" and "namespace" attributes to the
include(...) functions within urls.py. The reverse(...) function was
updated to allow you to specify namespace and current_app when
resolving URLs, however, we never brought the resolve(...) function up
to speed to include the relevant namespace and app_name data of the
resolved URL. I have taken an initial stab with code and tests (minus
documentation, until this feature is completed and agreed upon by the
community).

In order to achieve this I have graduated the result of the
resolve(...) method to be a ResolverMatch class as opposed to the old
tuple(func, args, kwargs). I have also implemented this feature to
provides backwards compatibility for the old "func, args, kwargs =
resolve(...)" so this feature should hopefully be completely backwards
compatible. The new ResolverMatch class provides access to all
attributes of the resolved URL match such as (url_name, app_name,
namespace, func, args, kwargs).

You can review the diff for this proposal on GitHub.

http://github.com/nowells/django/compare/master...resolver-match

As well as check out the code:

http://github.com/nowells/django/tree/resolver-match

Thanks!
Nowell Strite

Attachments (1)

resolver-match.diff (8.6 KB) - added by nbstrite 4 years ago.
Patch against trunk (created from the referenced GitHub branch)

Download all attachments as: .zip

Change History (5)

comment:1 Changed 4 years ago by nbstrite

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

The discussion for this topic can be viewed on Django-Dev at: http://groups.google.com/group/django-developers/browse_thread/thread/a1fb87e997fc923

Changed 4 years ago by nbstrite

Patch against trunk (created from the referenced GitHub branch)

comment:2 Changed 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [13479]) Fixed #13922 -- Updated resolve() to support namespaces. Thanks to Nowell Strite for the report and patch.

comment:3 Changed 4 years ago by russellm

For future reference, here's the minor changes between the most patch and what got submitted:

  • PEP8: [var] , not [ var ]
  • Passing in [] as a default argument is a no-no (e.g., namespaces=[]). Instead, pass in None and check for the default value. If you use [] as a default variable, you can get some interesting bugs. The default value is only instantiated once, so it's possible to accidentally modify it over time, and as a result the 'default' value for the function can change.
  • A light cleanup of the docs.
    • Fully documenting the ResolverMatch class
    • Rephrasing the 'versionchanged' notice.
  • Added some extra test cases to catch the unnamed arguments cases. What caught my eye was that all the test cases were expecting tuple() as the value for args.
  • Added some documentation annotating the tests that are being run.
  • Dropped the 'reverse()' method of ResolverMatch. It wasn't tested, and it doesn't make much sense to me for a return value to need a method to return the original input.
  • For the sake of being explicit, I've added tests that match can be assigned to a triple. This is implied by the 'legacy' tests, but better to be explicit with a common use case.

comment:4 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.