def poll_vote(request, poll_id):

    poll_ct = ContentType.objects.get_for_model(Poll)
    poll = get_cached_object_or_404(poll_ct, pk=poll_id)

    url = get_next_url(request)

    # activity check
    if not poll.is_active():
        return HttpResponseRedirect(url)

    # vote check
    if poll_check_vote(request, poll) != polls_settings.USER_NOT_YET_VOTED:
        return HttpResponseRedirect(url)

    form = QuestionForm(poll.question)(request.POST)

    # invalid input
    if not form.is_valid():
        # no choice selected error - via session
        sess_nv = request.session.get(polls_settings.POLL_NO_CHOICE_COOKIE_NAME, [])
        sess_nv.append(poll.id)
        request.session[polls_settings.POLL_NO_CHOICE_COOKIE_NAME] = sess_nv
        return HttpResponseRedirect(url)

    # vote save
    kwa = {}
    if request.user.is_authenticated():
        kwa['user'] = request.user
    kwa['ip_address'] = request.META['REMOTE_ADDR']
    poll.vote(form.cleaned_data['choice'], **kwa)

    # just voted info session update
    sess_jv = request.session.get(polls_settings.POLL_JUST_VOTED_COOKIE_NAME, [])
    sess_jv.append(poll.id)
    request.session[polls_settings.POLL_JUST_VOTED_COOKIE_NAME] = sess_jv

    response = HttpResponseRedirect(url)

    # authenticated user vote - session update
    if request.user.is_authenticated():
        sess = request.session.get(polls_settings.POLL_COOKIE_NAME, [])
        sess.append(poll.id)
        request.session[polls_settings.POLL_COOKIE_NAME] = sess
    # annonymous user vote - cookies update
    else:
        cook = request.COOKIES.get(polls_settings.POLL_COOKIE_NAME, '').split(',')
        if len(cook) > polls_settings.POLL_MAX_COOKIE_LENGTH:
            cook = cook[1:]
        cook.append(str(poll.id))
        expires = datetime.strftime(datetime.utcnow() + \
            timedelta(seconds=polls_settings.POLL_MAX_COOKIE_AGE),
            "%a, %d-%b-%Y %H:%M:%S GMT")
        response.set_cookie(
            polls_settings.POLL_COOKIE_NAME,
            value=','.join(cook),
            max_age=polls_settings.POLL_MAX_COOKIE_AGE,
            expires=expires,
            path='/',
            domain=Site.objects.get_current().domain,
            secure=None
        )

    return response