def redirect_to_term(request, version, term):
    # Check for an admin oneoff first.
    oneoff_redirect = find_oneoff_redirect(version, term)
    if oneoff_redirect:
        return oneoff_redirect

    form = RedirectForm(request.GET or None)

    # If we're explicitly choosing a new URL for this term, just go ahead and
    # do that. This could also insert new URLs, so do a brief sanity check to
    # make sure this service can't be used for spam.
    if 'url' in request.GET:
        if form.is_valid():
            # Make sure the new URL is in the set of URLs and increment its score.
            url = form.cleaned_data['url']
            r.sadd((version, term) % 'redirects:v2:%s:%s', url)
            r.incr('redirects:v2:%s:%s:%s' % (version, term, url))
            return redirect(request.GET.get('return_to', url))

    urls = get_urls(version, term)
    if urls:
        scoregroups = group_urls(urls)

        # The first group is the URLs with the highest score.
        score, winners = scoregroups.next()

        # If there's only a single winning URL, we're done. Count the redirect and
        # then issue it.
        if len(winners) == 1:
            url = winners[0]
            r.incr('redirects:v2:%s:%s:%s' % (version, term, url))
            return redirect(url)

        # Otherwise we need to display a list of all choices. We'll present this into
        # two buckets: the tied URLs with the high score (which is the list of winners
        # we've already gotten) and the tied URLs with a lower score. This second
        # bucket might be empty.
        losers = [losing_group for score, losing_group in scoregroups]

    else:
        winners = losers = None

    return render(request, 'choices.html', {
        'term': term,
        'winners': winners,
        'losers': losers,
        'form': form,
        'version': version,
    })
dataset/ETHPy150Open djangome/djangome/djangome/views.py/redirect_to_term/swapped operands of `%`