def post(): post_body = request.form["post_body"] is_anonymous = request.form.get("is_anonymous", None) == "on" allow_guesses = request.form.get("allow_guesses", None) == "on" user = current_user if type(user.is_authenticated) == bool or not user.is_authenticated(): is_anonymous = True allow_guesses = False poster = tagged = None if not is_anonymous or allow_guesses: poster = user.sid m = re.search(r"@([^_\W]+)", post_body) if m: tagged = m.group(1) tags = re.findall(r"#([^_\W]+)", post_body) tag_s = "" if tags else None for tag in tags: tag_s += "%s|" % tag guesses = NUMBER_GUESSES if allow_guesses else 0 p = Post(post_body, approved=False, is_anonymous=is_anonymous, poster=poster, allow_guesses=allow_guesses, tags=tag_s) p.save() #like = Like(pid=p.pid, like_count=0) #like.save(g.conn) gs = GuessSetting(p.pid, tagged=tagged, num_guesses=guesses, remaining=guesses) if tagged is not None: print tagged, p.pid send_mail("*****@*****.**" % tagged, "Looks like someone admirers you! Checkout what they said at admirers.cloudapp.net/search/id/%s" % p.pid) gs.save() return redirect("/")
def guess(): print("Guessing!") print(request.json) pid = int(request.json.get("pid")) guess = request.json.get("guess", None) post = Post.select([Equal("pid", pid)], [("pid", GuessSetting, "pid"), ("poster", User, "sid")])[0] gs = GuessSetting.select([Equal("gsid", post.gsid)], [])[0] user = current_user if not post.allow_guesses or not user.uni == post.tagged or gs.remaining < 1: flash(u'Guessing not permitted') return redirect("/") gs.remaining -= 1 if guess is not None and guess == post.uni: gs.matched = True send_guessed_mail(post.email, user.uni) send_guesser_mail(user.email, guess) flash(u"You've found a match! You should go ahead and message them!") print "MATCH!!!!! LOVE IS IN THE AIR" else: flash(u"Guess '%s' not matched :(" % guess) gs.save() return redirect("/")