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()
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})
def wipeDailyLimits(): users = User.objects.all() for user in users: cache.delete(daily_count_key("dares", user)) cache.delete(daily_count_key("proofs", user)) cache.delete("comments" + str(user.id))