def plan_profile(request): if os.environ.get("TEST", None): request.session["userId"] = request.GET["userId"] if not "userId" in request.session: data = {"error": {"title": u"未绑定", "content": u"请先到公众号绑定手环"}} return HttpResponse(json.dumps(data), content_type="application/json") if not "userId" in request.GET: data = {"error": {"title": u"出错啦", "content": u"这个页面找不到啦!"}} return HttpResponse(json.dumps(data), content_type="application/json") try: data = {} userId = data["userId"] = request.session["userId"] user = User.objects.get(openId=userId) data["href"] = "%s/plan/redirect/profile" % wechat_tools.domain id = request.GET["id"] plan = Plan.objects.get(id=id) data["image"] = plan.image data["title"] = plan.name data["startTime"] = basic_tools.IntToDate(plan.startTime) data["endTime"] = basic_tools.IntToDate(plan.endTime) data["description"] = plan.description data["goods"] = plan.goods data["id"] = plan.id if not plan.goal == 0: data["goal"] = plan.goal data["progress_value"] = tools.getProgress(plan, user) tags = plan.plan_ptag_plans.all() data["tags"] = [] for tag in tags: data["tags"].append(tag.name) if Good.objects.filter(user=user, type=1, target=plan.id).count() > 0: data["isGood"] = 1 tmp = plan.members.filter(openId=userId).count() if tmp > 0: data["isFollow"] = 1 if plan.finished == 1: data["isFinished"] = 1 except: data = {"error": {"title": u"出错啦", "content": u"页面找不到啦!"}} return HttpResponse(json.dumps(data), content_type="application/json")
def plan_profile(request): if os.environ.get("TEST", None): request.session["userId"] = request.GET["userId"] if not "userId" in request.session: data = {"error":{"title":u"未绑定","content":u"请先到公众号绑定手环"}} return HttpResponse(json.dumps(data), content_type="application/json") if not "userId" in request.GET: data = {"error":{"title":u"出错啦","content":u"这个页面找不到啦!"}} return HttpResponse(json.dumps(data), content_type="application/json") try: data = {} userId = data["userId"] = request.session["userId"] user = User.objects.get(openId=userId) data["href"] = "%s/plan/redirect/profile" % wechat_tools.domain id = request.GET["id"] plan = Plan.objects.get(id=id) data["image"] = plan.image data["title"] = plan.name data["startTime"] = basic_tools.IntToDate(plan.startTime) data["endTime"] = basic_tools.IntToDate(plan.endTime) data["description"] = plan.description data["goods"] = plan.goods data["id"] = plan.id if not plan.goal == 0: data["goal"] = plan.goal data["progress_value"] = tools.getProgress(plan, user) tags = plan.plan_ptag_plans.all() data["tags"] = [] for tag in tags: data["tags"].append(tag.name) if Good.objects.filter(user=user,type=1,target=plan.id).count() > 0: data["isGood"] = 1 tmp = plan.members.filter(openId=userId).count() if tmp > 0: data["isFollow"] = 1 if plan.finished == 1: data["isFinished"] = 1 except: data = {"error":{"title":u"出错啦","content":u"页面找不到啦!"}} return HttpResponse(json.dumps(data), content_type="application/json")
def match_check(request): if os.environ.get("TEST", None): request.session["userId"] = request.GET["userId"] if not "userId" in request.session: data = {"error":{"title":u"未绑定","content":u"请先到公众号绑定手环"}} return HttpResponse(json.dumps(data), content_type="application/json") if not "userId" in request.GET: data = {"error":{"title":u"出错啦","content":u"这个页面找不到啦!"}} return HttpResponse(json.dumps(data), content_type="application/json") try: data = {} userId = data["userId"] = request.session["userId"] user = User.objects.get(openId=userId) data["href"] = "%s/match/redirect/profile" % wechat_tools.domain data["data_list"] = [] matchs = user.user_match_members.order_by("-endTime").filter(finished=0).all()[:20] for match in matchs: item = {} item["user_image"] = match.creator.image item["user_name"] = match.creator.name item["userId"] = match.id item["createTime"] = basic_tools.getCreateTime(match.createTime) item["startTime"] = basic_tools.IntToDate(match.startTime) item["endTime"] = basic_tools.IntToDate(match.endTime) item["title"] = match.title item["description"] = match.description item["image"] = match.image item["step"] = tools.getProgress(match, user) item["tags"] = [] tags = match.match_mtag_matchs.all() for tag in tags: item["tags"].append(tag.name) item["isFollow"] = 1 item["follow"] = match.user_members.all().count() data["data_list"].append(item) except: data = {"error":{"title":u"出错啦","content":u"页面找不到啦!"}} return HttpResponse(json.dumps(data), content_type="application/json")
def match_profile(request): if os.environ.get("TEST", None): request.session["userId"] = request.GET["userId"] if not "userId" in request.session: data = {"error":{"title":u"未绑定","content":u"请先到公众号绑定手环"}} return HttpResponse(json.dumps(data), content_type="application/json") if not "userId" in request.GET: data = {"error":{"title":u"出错啦","content":u"这个页面找不到啦!"}} return HttpResponse(json.dumps(data), content_type="application/json") try: data = {} userId = data["userId"] = request.session["userId"] user = User.objects.get(openId=userId) data["href"] = "%s/match/redirect/profile" % wechat_tools.domain id = request.GET["id"] match = Match.objects.get(id=id) data["id"] = match.id data["title"] = match.title data["description"] = match.description data["image"] = match.image data["startTime"] = basic_tools.IntToDate(match.startTime) data["endTime"] = basic_tools.IntToDate(match.endTime) if match.finished == 1: data["isFinished"] = 1 if basic_tools.getNow() > match.startTime: data["isStarted"] = 1 data["tags"] = [] tags = match.match_mtag_matchs.all() for tag in tags: data["tags"].append(tag.name) tmp = match.user_members.filter(openId=userId).count() if tmp > 0: data["isFollow"] = 1 data["step"] = tools.getProgress(match, user) data["data_list"] = [] teams = match.members.all() for team in teams: item = {} item["num"] = 0 item["name"] = team.name item["members"] = [] steps = 0 members = team.members.all() item["ld"] = members.count() num = 0 for member in members: step = tools.getSingleProgress(match, member) steps += step item["members"].append({ "image":member.image, "name":member.name, "step":step, "num":num }) num += 1 item["step"] = steps data["data_list"].append(item) data["data_list"] = sorted(data["data_list"], key=lambda item : item["step"], reverse=True) ld = len(data["data_list"]) for i in xrange(ld): data["data_list"][i]["num"] = i+1 except: data = {"error":{"title":u"出错啦","content":u"页面找不到啦!"}} return HttpResponse(json.dumps(data), content_type="application/json")