#16391: New URL tag for reversing urls with placeholder args/kwargs
--------------------------------+-----------------------------------------
     Reporter:  h.a.clifford@…  |                    Owner:  nobody
         Type:  New feature     |                   Status:  new
    Component:  Core (Other)    |                  Version:  1.3
     Severity:  Normal          |               Resolution:
     Keywords:                  |             Triage Stage:  Someday/Maybe
    Has patch:  0               |      Needs documentation:  0
  Needs tests:  0               |  Patch needs improvement:  0
Easy pickings:  0               |                    UI/UX:  0
--------------------------------+-----------------------------------------

Comment (by mitar):

 Maybe I am wrong. This simple version works quite nicely:

 {{{
 @register.simple_tag
 def urltemplate(viewname):
     urlconf = urlresolvers.get_urlconf()
     resolver = urlresolvers.get_resolver(urlconf)
     prefix = urlresolvers.get_script_prefix()

     possibilities = resolver.reverse_dict.getlist(viewname)

     if len(possibilities) != 1:
         # TODO: Template tags should not the throwing exceptions (only if
 TEMPLATE_DEBUG is true)
         raise NotImplementedError

     possibility, pattern, defaults = possibilities[0]

     if len(possibility) != 1:
         # TODO: Template tags should not the throwing exceptions (only if
 TEMPLATE_DEBUG is true)
         raise NotImplementedError

     result, params = possibility[0]

     for param in params:
         result = result.replace('%%(%s)s' % param, '{%s}' % param)

     return prefix + result
 }}}

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to