コード例 #1
0
ファイル: views.py プロジェクト: codelucas/darehut.com
def postProof(request, dareID, post_fb = False):
    proof_form = None
    dare = get_object_or_404(Dare, id=int(dareID))
    bad_link_msg = None

    if request.user.is_authenticated():
        if request.user.get_profile().is_banned:
            return render_with_context(request, 'banned.html')

        if request.method == 'POST':
            proof_form = ProofForm(request.POST)
            if proof_form.is_valid() and confirmValidUrl(request.POST['proofLink']):
		        daily_post_count = cache.get(daily_count_key("proofs", request.user))
                if daily_post_count >= 5:
                    return render_with_context(request, "overlimit.html", {'type' : 'proofs', 'amount' : 5})
                elif daily_post_count is None:
                    daily_post_count  = 1
                elif daily_post_count < 5:
                    daily_post_count += 1
                cache.set(daily_count_key("proofs", request.user), daily_post_count , 86400)

                proof = proof_form.save()
                computeProofData() # Uncomment this and the code in tasks if we want one time computations
                if not post_fb:
                    return HttpResponseRedirect('../..' + proof.dare.get_absolute_url())
                else:
                    can_post = False
                    if proof.is_friendly(proof, request.user.get_profile().friends()):
                        can_post = True
                    return render_with_context(request, 'post_fb.html', {'proof' : proof, 'type' :
                        'proof', 'can_post' : can_post})
            elif not confirmValidUrl(request.POST['proofLink']):
                bad_link_msg = "The link which you enter must directed towards a Youtube video or an online image!"
        else:
            proof_form = ProofForm()
コード例 #2
0
ファイル: views.py プロジェクト: codelucas/darehut.com
def home(request, filterBy = 'all', sortBy = 'popularity'):
    dares = cache.get(listing_sort_key(filterBy, sortBy))
    if dares is None or sortBy == "newest":
        dares = Dare.objects.with_rankings(filterBy, sortBy, request)
        dares = dares[:500]

    if filterBy == "friends":
        timeout = 3600 # 1 hour
    else:
        timeout = 150  # 2.5 minutes

    # If a first time user has not clicked the friends button, send a notify var
    computeCommentHotness()
    computeDareHotness()
    wipeDailyLimits()
    computeProofData()

    cache.set(listing_sort_key(filterBy, sortBy), dares, timeout)

    clicked_friends = "False"

    if filterBy == "friends":
        clicked_friends = "True"

    pageDares = handlePaginate(request, dares)["pageDares"]
    rankBoost = handlePaginate(request, dares)["rankBoost"]
    featured_dare = handleFeaturedDare(request)

    return render_with_context(request, 'home.html', {"filterBy" : filterBy,
        "sortBy" : sortBy, "pageDares" : pageDares, "rankBoost" : rankBoost,
        "featured_dare" : featured_dare, "clicked_friends" : clicked_friends})