def next_redirect(request, default, default_view, **get_kwargs):
    """
    Handle the "where should I go next?" part of comment views.

    The next value could be a kwarg to the function (``default``), or a
    ``?next=...`` GET arg, or the URL of a given view (``default_view``). See
    the view modules for examples.

    Returns an ``HttpResponseRedirect``.
    """
    next = request.POST.get('next', default)
    if not is_safe_url(url=next, host=request.get_host()):
        next = urlresolvers.reverse(default_view)

    if get_kwargs:
        if '#' in next:
            tmp = next.rsplit('#', 1)
            next = tmp[0]
            anchor = '#' + tmp[1]
        else:
            anchor = ''

        joiner = ('?' in next) and '&' or '?'
        next += joiner + urllib.urlencode(get_kwargs) + anchor
    return HttpResponseRedirect(next)
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.4/django/contrib/comments/views/utils.py/next_redirect/original