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