예제 #1
0
def check_votes(request, bar_id):
    try:
        bar = Bar.objects.get(id=bar_id)
    except Bar.DoesNotExist:
        return json_response({'success': False,
            'errors': ['no_bar']})

    # first check to see if a new bar has been created
    new_bar_check = Bar.objects.latest('date_created')
    if bar.id != new_bar_check.id:
        return json_response({'success': False,
            'new_bar': True, 'bar_id': new_bar_check.id})

    return json_response({'success': True,
        'faith_count': bar.faith_count(),
        'no_faith_count': bar.no_faith_count()})
예제 #2
0
def vote(request, bar_id):
    try:
        bar = Bar.objects.get(id=bar_id)
    except Bar.DoesNotExist:
        raise Http404

    vote = request.GET.get('is', None)

    if not vote:
        raise Http404

    ip_address = request.META['REMOTE_ADDR']
    if vote == 'faith':
        bar.has_faith(ip_address)
    if vote == 'faithless':
        bar.no_faith(ip_address)

    if request.is_ajax():
        return json_response({'success': True})
    return HttpResponseRedirect(reverse('faith:track'))