#15294: Use named urls instead of hard coded ones in admin views
---------------------------------------+-------------------------------
               Reporter:  julien       |          Owner:  ramiro
                   Type:  New feature  |         Status:  new
              Milestone:               |      Component:  contrib.admin
                Version:  1.2          |       Severity:  Normal
             Resolution:               |       Keywords:
           Triage Stage:  Accepted     |      Has patch:  0
    Needs documentation:  0            |    Needs tests:  0
Patch needs improvement:  0            |  Easy pickings:  0
---------------------------------------+-------------------------------

Comment (by burzak):

 Replying to [comment:10 julien]:
 > Replying to [comment:8 burzak]:
 > > I did something like that here [0]. I changed the default value to
 None and I made an 'if' like this in order to maintain backward
 compatibility:
 > >
 > > {{{
 > > #!python
 > >
 > >     if post_url_continue is not None:
 > >         post_url_continue = post_url_continue % pk_value
 > >     else:
 > >         post_url_continue = reverse("admin:%s_%s_change" %
 (opts.app_label, opts.module_name), args=(pk_value,),
 current_app=self.admin_site.name)
 > > }}}
 >
 > Cool, that makes sense. However, this could be a bit limiting as you
 couldn't pass a pre-formatted string -- it would necessarily require a
 string format to insert `pk_value`.
 >
 > I can think of 2 options, either/or:
 >
 > * we consider that `response_add` is not part of the official API (it's
 not documented) and therefore we don't worry about breaking backwards
 compatibility. We then just assume that `post_url_continue` is either
 `None` or a pre-formatted string.
 > * we first try to insert `pk_value` into `post_url_continue`, but if an
 exception is raised then we assumed it's a pre-formatted string and move
 on with it.
 >
 > Hope that makes sense. What do you think?


 I tend to think that if somebody pass a `post_url_continue` this have to
 be pre-formatted since the user must know where to go.

 I like the idea of keeping the code clean and do not add any try/catch. If
 the backward compatibility is not so much important in this situation I
 would be happy removing the `pk_value`.

 I like this...
 {{{
 #!python
     if post_url_continue is None:
         post_url_continue = reverse("admin:%s_%s_change" %
 (opts.app_label, opts.module_name), args=(pk_value,),
 current_app=self.admin_site.name)
 }}}

 rather than:
 {{{
 #!python
     if post_url_continue is None:
         post_url_continue = reverse("admin:%s_%s_change" %
 (opts.app_label, opts.module_name), args=(pk_value,),
 current_app=self.admin_site.name)
     else:
         try:
             post_url_continue = post_url_continue % pk_value
         except TypeError:
             pass
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/15294#comment:11>
Django <http://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 django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to