Exemplo n.º 1
0
def postDare(request, post_fb = False):
    dareform = None # If the user isn't authenticated, the form won't even show.
    finished_dare = None # Exists after we saved the form, and are proceding to FB

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

        if request.method == 'POST':
            dareform = DareForm(request, request.POST)
            if dareform.is_valid():
                daily_post_count = cache.get(daily_count_key("dares", request.user))
                if daily_post_count >= 5:
                   return render_with_context(request, "overlimit.html", {'type' : 'dares', '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("dares", request.user), daily_post_count , 86400)

                finished_dare = dareform.save()
                finished_dare.post_init()
                if not post_fb:
                    return HttpResponseRedirect('..' + finished_dare.get_absolute_url())
                else:
                    return render_with_context(request, 'post_fb.html', {'dare' : finished_dare,
                        'type' : 'dare'})
        else:
            dareform = DareForm(request)
    return render_with_context(request, 'postdare.html', {'dareform' : dareform})
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
def allProofs(request, dareID):
    dare = get_object_or_404(Dare, id=int(dareID))
    allProofs = Proof.objects.filter(dare = dare.id).order_by('-id')
    for proof in allProofs:
        if proof.yt_string:
            # If it's an image proof, its length will be 0, so we skip
            if proof.yt_string.__len__() <= 2:
                proof.title = "Image proof for: " + proof.dare.title[0:30] + "..."
            else:
                information = proof.yt_string.split('%^&*(')
                proof.title = information[0]
                proof.view_count = information[1]
                proof.comment_count = information[2]
                proof.likes = information[3]
                proof.dislikes = information[4]
                proof.favorite_count = information[5]
                proof.description = information[6]
        else:
            proof.title = "Proof data currently loading..."

    paginator = Paginator(allProofs, 25)
    pageNumber = request.GET.get('page')
    try: paginatedPage = paginator.page(pageNumber)
    except PageNotAnInteger: pageNumber = 1
    except EmptyPage: pageNumber = paginator.num_pages

    allProofs = paginator.page(pageNumber)
    return render_with_context(request, 'allproofs.html', {"dare" : dare, "allProofs"
         : allProofs})
Exemplo n.º 4
0
def darePerm(request, dareID, commentCount = 100):
    dare = get_object_or_404(Dare, id=int(dareID))
    proofs = dare.proof_set.order_by('-id')

    type = ContentType.objects.get_for_model(dare)
    comments = cache.get(comment_key(type, dare.id))
    if comments is None or request.GET.get('c'): # Whenever a comment is posted, a c HTML get comes gets sent
        comments = ThreadedComment.objects.getListFor(type, dare.id)
        cache.set(comment_key(type, dare.id), comments, 300)
    nodes = [node.get_descendants(include_self=True) for node in comments[:commentCount]]

    for proof in proofs:
        if proof.yt_string:
            # If it's an image proof, its length will be 0, so we skip
            if proof.yt_string.__len__() <= 2:
                proof.title = "Image proof for: " + proof.dare.title[0:30] + "..."
            else:
                information = proof.yt_string.split('%^&*(')
                proof.title = information[0]
                proof.view_count = information[1]
                proof.comment_count = information[2]
                proof.likes = information[3]
                proof.dislikes = information[4]
                proof.favorite_count = information[5]
                proof.description = information[6]
        else:
            proof.title = "Proof data currently loading..."

    missingComments = "False"
    nextBatch = int(commentCount) + 100
    if comments.count() > int(commentCount):
        missingComments = "True"
    return render_with_context(request, 'darepermlink.html', {'dare' : dare, 'proofs' : proofs,
        'comments' : nodes, 'missingComments' : missingComments, 'nextBatch' : nextBatch})
Exemplo n.º 5
0
                    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()

    return render_with_context(request, 'postproof.html', {'proofform' : proof_form,
        'dare' : dare, 'bad_link_msg' : bad_link_msg})

def deleteProof(request, dareID, proofID):
    dare = Dare.objects.get(id = dareID)
    proof = Proof.objects.get(id = proofID)
    proof.delete()
    return HttpResponseRedirect(dare.get_absolute_url())
Exemplo n.º 6
0
def custom_500(request):
    return render_with_context(request, "500.html")
Exemplo n.º 7
0
def custom_404(request):
    return render_with_context(request, "404.html")