コード例 #1
0
ファイル: views.py プロジェクト: serkanh/Yupeat
def vote(request):
    
    user = getUser(request)
    prev_votes = ''
    if user:
        up = user.get_profile()
        prev_votes = VoteHistory.objects.filter(userprofile=up)
    
    logged_in = False
    if user:
        logged_in = True
        
    if request.POST:
        form = VoteForm(request.POST)
        
        if request.user.is_authenticated():
            if form.is_valid():
                """Does URL exist?"""
                c_url = form.cleaned_data['url']
                v = Vote.objects.filter(url=c_url)
                if v:
                    vote = v[0]
                    """check for multiple submissions of the same url"""
                    vh = VoteHistory.objects.filter(vote=vote, userprofile=up)
                    if len(vh) == 0:
                        vote.count += 1
                        vote.save()
                else:
                    vote = form.save()
                    vote.count=1
                    vote.featured=False
                    vote.created_on=datetime.now()
                    vote.contributor = up
                    vote.save()
                    
                    sendVoteAdminEmail(vote, up)
                    
                    vh = VoteHistory(vote=vote,userprofile=up)
                    vh.save()
    else:
        form = VoteForm()
    
    pv_array = []
    for pv in prev_votes:
        pv_array.append(pv.vote.id)
         
    vote = Vote.objects.filter(featured=False).order_by('-count')
    
    data = {'form':form, 'logged_in':logged_in, 'user':user, 'vote':vote, 'prev_votes':pv_array}
    template = "home/vote.html"
    
    return render_to_response(template, data,context_instance=RequestContext(request))
コード例 #2
0
ファイル: views.py プロジェクト: serkanh/Yupeat
def ajax_vote(request):
    user = getUser(request)
    up = user.get_profile()
    
    vv = request.POST.get('vote_val')
    
    varray = vv.split('-')
    vote_id = varray[1]
    
    vote = Vote.objects.get(id=vote_id)
    
    vh = VoteHistory.objects.filter(vote=vote, userprofile=up)
    if len(vh) == 0:
        vote.count += 1
        vote.save()
        
        vh = VoteHistory(vote=vote,userprofile=up)
        vh.save()
        
    return HttpResponse('', status=200)