[Django] #27569: Resolve reverse url with named groups regular expression to sprintf output formatters not specifying kwargs key / value pairs.

12 views
Skip to first unread message

Django

unread,
Dec 3, 2016, 3:32:09 PM12/3/16
to django-...@googlegroups.com
#27569: Resolve reverse url with named groups regular expression to sprintf output
formatters not specifying kwargs key / value pairs.
-------------------------------------------+-----------------------------
Reporter: Dmitriy Sintsov | Owner: nobody
Type: New feature | Status: new
Component: Core (URLs) | Version: 1.10
Severity: Normal | Keywords: reverse url
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+-----------------------------
I wrote a pluggable app which supports Django reverse url calling from
client-side Javascript (AJAX) via sprintf.js library:
https://github.com/Dmitri-Sintsov/django-jinja-
knockout/blob/e28d83886c5da0f4661257146a9925aabbcc93b8/django_jinja_knockout/static/js/front/app.js#L1276

To inject resolved reverse url with regex named parameters replaced to
sprintf output formatters, without kwargs key / value pairs supplied, I
use Python inspect module when django.django.core.urlresolvers.reverse
throws NoReverseMatch exception to get values of caller variables f_locals
keys 'prefix_norm' / '_prefix':
https://github.com/Dmitri-Sintsov/django-jinja-
knockout/blob/e28d83886c5da0f4661257146a9925aabbcc93b8/django_jinja_knockout/tpl.py#L180

Unfortunately that is a very hacky way because the urlresolvers code
changes from one Django release to another one and I am afraid that at
some point there could be new incompatibility.

Is there any cleaner way to resolve reverse url with regex named
parameters replaced to sprintf output formatters not specifying actual
kwargs key / value pairs? Because internally urlresolvers module has these
as prefix_norm / _prefix values.

Or should I try to develop a core patch? That should be useful to many
modules which route Django url names from Javascript client-side.

--
Ticket URL: <https://code.djangoproject.com/ticket/27569>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 5, 2016, 8:47:56 AM12/5/16
to django-...@googlegroups.com
#27569: Resolve reverse url with named groups regular expression to sprintf output
formatters not specifying kwargs key / value pairs.
---------------------------------+-----------------------------------------

Reporter: Dmitriy Sintsov | Owner: nobody
Type: New feature | Status: new
Component: Core (URLs) | Version: 1.10
Severity: Normal | Resolution:
Keywords: reverse url | Triage Stage: Someday/Maybe

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------
Changes (by Tim Graham):

* stage: Unreviewed => Someday/Maybe


Comment:

A web search for "django reverse urls in javascript" gives
[https://github.com/ierror/django-js-reverse django-js-reverse] as the
first result. I'm not sure if that package is relevant but I think it
would be better to discuss the idea on the DevelopersMailingList because
it reaches a wider audience than this ticket tracker. It will be useful to
know what other solutions are other there. It would also be helpful to
describe the problem a high level rather than simply linking to the code
you wrote. It takes non-trivial effort to figure out what the use case is
by looking at the code, so you're less likely to get useful feedback.

--
Ticket URL: <https://code.djangoproject.com/ticket/27569#comment:1>

Django

unread,
Dec 6, 2016, 3:53:56 PM12/6/16
to django-...@googlegroups.com
#27569: Resolve reverse url with named groups regular expression to sprintf output
formatters not specifying kwargs key / value pairs.
---------------------------------+-----------------------------------------

Reporter: Dmitriy Sintsov | Owner: nobody
Type: New feature | Status: closed

Component: Core (URLs) | Version: 1.10
Severity: Normal | Resolution: fixed
Keywords: reverse url | Triage Stage: Someday/Maybe

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------
Changes (by Dmitriy Sintsov):

* status: new => closed
* resolution: => fixed


Comment:

Thank you for providing the link to django-js-reverse pluggable app, now I
was able to fix hackish way of reverse urls with regex named parameters
into sprintf formatters via much cleaner and more compatible way:

https://github.com/Dmitri-Sintsov/django-jinja-
knockout/commit/ac39fd0f3f37bb8ef5ce85a571a537ed3708b21d

The only thing I am unsure about is how the code is valid to different
namespaces, however I know that namespaces are rarely used in Django urls.

You asked why do I need this - it's because urls with different named
parameters (url kwargs) values has to be constructed in Javascript at
client-side for various AJAX calls to Django class-based views and I do
not want to use hard-coded urls at client-side.

--
Ticket URL: <https://code.djangoproject.com/ticket/27569#comment:2>

Django

unread,
Dec 6, 2016, 4:03:39 PM12/6/16
to django-...@googlegroups.com
#27569: Resolve reverse url with named groups regular expression to sprintf output
formatters not specifying kwargs key / value pairs.
---------------------------------+-----------------------------------------

Reporter: Dmitriy Sintsov | Owner: nobody
Type: New feature | Status: closed

Component: Core (URLs) | Version: 1.10
Severity: Normal | Resolution: wontfix
Keywords: reverse url | Triage Stage: Someday/Maybe

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+-----------------------------------------
Changes (by Tim Graham):

* resolution: fixed => wontfix


Comment:

(updating the resolution to reflect that fact that no changes were made in
Django as a result of this issue)

--
Ticket URL: <https://code.djangoproject.com/ticket/27569#comment:3>

Reply all
Reply to author
Forward
0 new messages