예제 #1
0
def govote(request):
    if request.method == 'GET' and request.is_ajax():
        pollitemid = request.GET.get('pollitemid')
        pollid = request.GET.get('pollid')
        bypass = False
        if models.VoteCheck.objects.filter(userid=request.user.id,
                                           pollid=pollid,
                                           vote_date=date.today()):
            bypass = True
        else:
            vote_rec = models.VoteCheck(userid=request.user.id,
                                        pollid=pollid,
                                        vote_date=date.today())
            vote_rec.save()
        try:
            pollitem = models.PollItem.objects.get(id=pollitemid)
            if not bypass:
                pollitem.vote = pollitem.vote + 1
                pollitem.save()
            votes = pollitem.vote
        except:
            votes = 0
    else:
        votes = 0
    return HttpResponse(votes)
예제 #2
0
def govote(request):
    if request.method == 'GET' and request.is_ajax():
        pollitemid = request.GET.get('pollitemid')
        pollid = request.GET.get('pollid')
        bypass = False
        if models.VoteCheck.objects.filter(userid=request.user.id,
                                           pollid=pollid,
                                           vote_date=datetime.date.today()):
            bypass = True
            messages.add_message(request, messages.WARNING, '你已經投過票了')
        else:
            vote_rec = models.VoteCheck(userid=request.user.id,
                                        pollid=pollid,
                                        vote_date=datetime.date.today())
            vote_rec.save()
        try:
            pollitem = models.PollItem.objects.get(id=pollitemid)
            if not bypass:  # bypass == False
                pollitem.vote = pollitem.vote + 1
                pollitem.save()
                messages.add_message(request, messages.SUCCESS, '投票完成')
            votes = pollitem.vote
        except Exception as e:
            messages.add_message(request, messages.WARNING, e)
            votes = 0
    else:
        votes = 0

    return HttpResponse(votes)
예제 #3
0
파일: views.py 프로젝트: nicoplus/mvote
def vote(request, pollid, pollitemid):
    if models.VoteCheck.objects.filter(userid = request.user.id, pollid = pollid, vote_date = date.today()):
        messages.add_message(request, messages.WARNING, 'Vote once in a day.')
        return redirect(poll, pollid)
    else:
        vote_rec = models.VoteCheck(userid = request.user.id, pollid = pollid, vote_date = date.today())
        vote_rec.save()
    try:
        pollitem = models.PollItem.objects.get(id=pollitemid)
    except:
        pollitem = None
    if pollitem:
        pollitem.vote += 1
        pollitem.save()

    return redirect(poll, pollid)
예제 #4
0
def vote(request, pollid, pollitemid):
    if models.VoteCheck.objects.filter(userid=request.user.id,
                                       pollid=pollid,
                                       vote_date=datetime.date.today()):
        return redirect('/poll/{}'.format(pollid))
    else:
        voteCheck = models.VoteCheck(userid=request.user.id,
                                     pollid=pollid,
                                     vote_date=datetime.date.today())
        voteCheck.save()
    try:
        pollitem = models.PollItem.objects.get(id=pollitemid)
    except:
        pollitem = None
    if pollitem is not None:
        pollitem.vote = pollitem.vote + 1
        pollitem.save()
    return redirect('/poll/{}'.format(pollid))
예제 #5
0
def vote(request, pollid, pollitemid):
    target_url = '/poll/' + pollid
    if models.VoteCheck.objects.filter(userid=request.user.id,
                                       pollid=pollid,
                                       vote_date=date.today()):
        return redirect(target_url)
    else:
        vote_rec = models.VoteCheck(userid=request.user.id,
                                    pollid=pollid,
                                    vote_date=date.today())
        vote_rec.save()
    try:
        pollitem = models.PollItem.objects.get(id=pollitemid)
    except:
        pollitem = None
    if pollitem is not None:
        pollitem.vote = pollitem.vote + 1
        pollitem.save()
    return redirect(target_url)
예제 #6
0
def vote(request, pollid, pollitemid):
    target_url = '/poll/' + str(pollid)
    if models.VoteCheck.objects.filter(userid=request.user.id,
                                       pollid=pollid,
                                       vote_date=datetime.date.today()):
        return redirect(target_url)
        messages.add_message(request, messages.WARNING, '你已經投過票了')
    else:
        vote_rec = models.VoteCheck(userid=request.user.id,
                                    pollid=pollid,
                                    vote_date=datetime.date.today())
        vote_rec.save()
    try:
        pollitem = models.PollItem.objects.get(id=pollitemid)
    except Exception as e:
        pollitem = None
        messages.add_message(request, messages.WARNING, e)
    if pollitem is not None:
        pollitem.vote = pollitem.vote + 1
        pollitem.save()
        messages.add_message(request, messages.SUCCESS, '投票完成')

    return redirect(target_url)