Example #1
0
File: app.py Project: zestyping/go
def go(name):
    """Redirects to a link."""
    url = data.get_url(name)
    if not url:
        return redirect('/.edit?name=' + urlquote(name))
    qs = (request.query_string or '').encode('utf-8')
    if qs:
        url += ('&' if '?' in url else '?') + qs
    data.log('redirect', name, url)
    data.update_count(name)
    return redirect(url)
Example #2
0
def go(name):
    """Redirects to a link."""
    url = data.get_url(name)
    if not url:
        return redirect('/.edit?name=' + urlquote(name))
    qs = (request.query_string or '').encode('utf-8')
    if qs:
        url += ('&' if '?' in url else '?') + qs
    data.log('redirect', name, url)
    data.update_count(name)
    return redirect(url)
Example #3
0
File: app.py Project: waveremit/go
def go(name):
    """Redirects to a link."""
    url = data.get_url(name) or data.get_url(normalize(name))
    # If "foo/bar/baz" is not found, try "foo/bar" and append "/baz";
    # if that's not found, try "foo" and append "/bar/baz".
    suffix = ''
    while not url and '/' in name:
        name, part = name.rsplit('/', 1)
        suffix = '/' + part + suffix
        url = data.get_url(name) or data.get_url(normalize(name))
    if not url:
        return redirect('/.edit?name=' + urlquote(name + suffix))
    if '%s' in url:
        url = url.replace('%s', urlquote(suffix.lstrip('/')))
    else:
        url += suffix
    qs = (request.query_string or '').encode('utf-8')
    if qs:
        url += ('&' if '?' in url else '?') + qs
    data.log('redirect', name, url)
    data.update_count(name)
    return redirect(url)
Example #4
0
File: app.py Project: waveremit/go
def go(name):
    """Redirects to a link."""
    url = data.get_url(name) or data.get_url(normalize(name))
    # If "foo/bar/baz" is not found, try "foo/bar" and append "/baz";
    # if that's not found, try "foo" and append "/bar/baz".
    suffix = ''
    while not url and '/' in name:
        name, part = name.rsplit('/', 1)
        suffix = '/' + part + suffix
        url = data.get_url(name) or data.get_url(normalize(name))
    if not url:
        return redirect('/.edit?name=' + urlquote(name + suffix))
    if '%s' in url:
        url = url.replace('%s', urlquote(suffix.lstrip('/')))
    else:
        url += suffix
    qs = (request.query_string or '').encode('utf-8')
    if qs:
        url += ('&' if '?' in url else '?') + qs
    data.log('redirect', name, url)
    data.update_count(name)
    return redirect(url)