#30038: New shortcut: redirect_with_params()
-----------------------------------+--------------------------------------
     Reporter:  agustin bacigalup  |                    Owner:  nobody
         Type:  New feature        |                   Status:  new
    Component:  Uncategorized      |                  Version:  2.1
     Severity:  Normal             |               Resolution:
     Keywords:                     |             Triage Stage:  Unreviewed
    Has patch:  0                  |      Needs documentation:  0
  Needs tests:  0                  |  Patch needs improvement:  0
Easy pickings:  0                  |                    UI/UX:  0
-----------------------------------+--------------------------------------
Description changed by agustin bacigalup:

Old description:

> I'd like to contribute to Django by adding a shorcut, similar to
> `django.shortcuts.redirect` but also appends request's GET parameters. I
> found myself using it a lot, and I wonder if it's useful for the
> community. If so, should I fork Django on Github and submit a pull
> request?
>
> {{{
> def redirect_with_params(request, to, *args, **kwargs):
>     """
>     Same as `django.shortcuts.redirect` but recieves a `request` as first
> parameter.
>     """
>     response = redirect(to, *args, **kwargs)
>     url = response.url
>     params = request.GET.urlencode()
>     if params:
>         url = "%s?%s" % (response.url, params)
>     return response.__class__(url)
> }}}

New description:

 I'd like to contribute to Django by adding a shorcut, similar to
 `django.shortcuts.redirect` but also appends request's GET parameters. I
 found myself using it a lot, and I wonder if it's useful for the
 community. If so, should I fork Django on Github and submit a pull
 request?

 {{{
 def redirect_with_params(request, to, *args, **kwargs):
     """
     Same as `django.shortcuts.redirect` but recieves a `request` as first
 parameter.
     It preserves the GET parameters from the `request` in the URL
 redirected.
     """
     response = redirect(to, *args, **kwargs)
     url = response.url
     params = request.GET.urlencode()
     if params:
         url = "%s?%s" % (response.url, params)
     return response.__class__(url)
 }}}

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30038#comment:1>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.9be4755bee9ad028dc40ae5cca6fe68d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to