def predict(req): pid = req.GET.get("pid") mid = req.GET.get("mid") m1 = req.GET.get("m1") m2 = req.GET.get("m2") if not pid or not mid or not m1 or not m2: return render(req, "msg.html", {"msg":"invalid params"}) m1 = string.atoi(m1) m2 = string.atoi(m2) if m1 < 0 or m2 < 0: return render(req, "msg.html", {"msg":"Mark cannot be negative!"}) peer = Peer.objects.get(id=pid) if not peer: return render(req, "msg.html", {"msg":"Invalid peer"}) match = TeamMatch.objects.get(id=mid) if not match: return render(req, "msg.html", {"msg":"Invalid match"}) signed_uid, name = get_signed_uid(req) if signed_uid != "admin" and timezone.now() >= match.begin: return render(req, "msg.html", {"msg":"Game is over or timeout"}) pmatch_list = PeerMatch.objects.filter(peer=peer, match=match) if pmatch_list: pmatch = pmatch_list[0] pmatch.mark_a = m1 pmatch.mark_b = m2 else: pmatch = PeerMatch(peer=peer, match=match, mark_a=m1, mark_b=m2) pmatch.save() return render(req, "msg.html", {"msg":"Update OK"})
def send_report(req, style): context = get_context(req) if not context["signed_uid"]: return HttpResponse("Please signin at first", status=404) final_list = FinalMatch.objects.all() match_list = [] mark_list = get_marks() pinfo_list = get_marks(False) for match in TeamMatch.objects.all(): tmp_list = [] for pinfo in pinfo_list: pmatch_list = PeerMatch.objects.filter(peer=pinfo["peer"], match=match) if not pmatch_list or context["nowtime"] < match.end: pmatch = PeerMatch(peer=pinfo["peer"], match=match, mark_a=-1, mark_b=-1) else: pmatch = pmatch_list[0] if pmatch.mark_a >= 0 and pmatch.mark_b >= 0: win1 = (pmatch.mark_a > pmatch.mark_b) and (pmatch.match.mark_a > pmatch.match.mark_b) win2 = (pmatch.mark_a == pmatch.mark_b) and (pmatch.match.mark_a == pmatch.match.mark_b) win3 = (pmatch.mark_a < pmatch.mark_b) and (pmatch.match.mark_a < pmatch.match.mark_b) else: win1, win2, win3 = False, False, False if win1 or win2 or win3: if (pmatch.mark_a == pmatch.match.mark_a) and (pmatch.mark_b == pmatch.match.mark_b): pmatch.predict = "hit" else: pmatch.predict = "true" else: pmatch.predict = "false" tmp_list.append(pmatch) match_list.append({"match": match, "pmatch_list": tmp_list}) match_list = sorted(match_list, key=lambda x:x["match"].name, reverse=True) context.update({"pinfo_list": pinfo_list, "match_list": match_list, "mark_list": mark_list, "final_list": final_list}) subject = "The World Cup 2014" response = render(req, "report.html", context) message = response.content if style == "mail" and context["signed_uid"] == "admin": print "[*] sending report by email ...." if send_email_default(subject, message): return HttpResponse("Send mail Successfully!") else: return HttpResponse("Send mail Failed!!") return response