def get_user_info(): if request.method == "GET": student_id = request.args.get("studentid") student_info = {} row = User.get_user_info(g.db, student_id) if row is None: return jsonify(status="false") student_info["prevuniversity"] = row.prevuniversity student_info["name"] = row.username student_info["prevmajor"] = row.prevmajor if row.GPA != 0: student_info["GPA"] = row.GPA if row.TOEFL != 0: student_info["TOEFL"] = row.TOEFL if row.IELTS != 0: student_info["IELTS"] = row.IELTS if row.GMAT != 0: student_info["GMAT"] = row.GMAT if row.SAT != 0: student_info["SAT"] = row.SAT if row.GRE != 0: student_info["GRE"] = row.GRE student_info["pic"] = row.pic student_info["grade"] = row.grade universityname = list() for row in Offer.get_offer_student_info(g.db, student_id): universityname.append( University.get_university_from_id(g.db, row.university_id).name) student_info["universityname"] = universityname student_info["status"] = "success" return json.dumps(student_info) return jsonify(status="false")
def get_user_detail_info(): if request.method == "GET": student_id = request.args.get("studentid", 0, int) student_info = dict() offers = list() login_user_id = session.get("user_id") user_info = User.get_user_info(g.db, student_id) if login_user_id is None: login_user_id = -1 for row in Offer.get_offer_student_info(g.db, student_id): offer_info = dict() for row_un in University.get_university_info( g.db, str(row.university_id)): offer_info["universityname"] = row_un.name offer_info["universityid"] = row_un.id offer_info["logo"] = get_university_logo(row_un.name) offer_info["twodimcode"] = row.wechat for row_ma in Major.get_major_info_by_id(g.db, row.major_id): offer_info["majorname"] = row_ma.name offer_info["grade"] = row.grade offer_info["offertype"] = row.offer_type if row.scholarship is not None: offer_info["scholarship"] = \ str(row.scholarship) + row.scholarship_type # offer_info["scholarship"] = None offers.append(offer_info) student_info["offers"] = offers compares = [] compares_info = {} for row_co in Compare.get_compare_user_id(g.db, student_id): compares_info["compareid"] = row_co.id compareslist = list() compares_un = {} for row_ci in CompareInfo.get_compare_info(g.db, row_co.id): for row_un in University.get_university_info( g.db, row_ci.university_id): compares_un["universityname"] = row_un.name compares_un["universityid"] = row_un.id compares_un["logo"] = row_un.schoollogo for row_ma in CompareInfo.get_compare_info( g.db, row_ci.major_id): compares_un["majorname"] = row_ma.name compares_un["supportnum"] = row_ci.supportnum compares_un["offernum"] = Offer.get_offer_num( g.db, row_ci.university_id) compareslist.append(compares_un) compares_un = {} compares_info["comparelist"] = compareslist compares.append(compares_info) student_info["compares"] = compares user = User.get_user_info(g.db, student_id) student_info["fannum"] = UserFollow.get_follow_count_user( g.db, student_id) if user is None: student_info["description"] = "" student_info["bginf"] = "" else: student_info["description"] = user.description student_info["bginf"] = user.bginf if int(login_user_id) == int(student_id): student_info["self"] = "true" student_info["phone"] = user.phone student_info["email"] = user.email else: student_info["self"] = "false" student_info["phone"] = "" student_info["email"] = "" message = list() for row_meg in Message.get_message_user(g.db, student_id): message_dict = dict() message_dict["messageid"] = row_meg.id user_id = row_meg.user_id user = User.get_user_info(g.db, user_id) if user is None: message.append(message_dict) else: message_dict["pic"] = user.pic message_dict["name"] = user.username message_dict["studentid"] = user_id message_dict["content"] = row_meg.message message_dict["time"] = get_timestamp(row_meg.create_time) message.append(message_dict) student_info["messages"] = message u"""这个位置的关注状态逻辑有点奇葩,以后要多注意""" follow_status = UserFollow.get_follow_to_user(g.db, login_user_id, student_id) if follow_status is not None: student_info["followed"] = "true" else: student_info["followed"] = "false" follows_list = list() for row_follow in UserFollow.get_follow_id(g.db, student_id): follows = dict() follow_user_id = row_follow.follow_user_id user = User.get_user_info(g.db, follow_user_id) if user is None: follows_list.append(follows) else: follows["name"] = user.username follows["pic"] = user.pic follows["studentid"] = follow_user_id follows_list.append(follows) student_info["follows"] = follows_list student_info["status"] = "success" score = Score.get_user_score(g.db, student_id) coupons = dict() print user_info.account, user.active, if user_info.active == 1 and (user_info.account != 0 and user_info.account is not None): coupons["code"] = user_info.coupon coupons["account"] = user_info.account student_info["coupons"] = coupons elif user_info.active == 2 and (user_info.account != 0 and user_info.account is not None): coupons["code"] = None coupons["account"] = user_info.account student_info["coupons"] = coupons elif user_info.active == 1 and (user_info.account != 0 and user_info.account is not None ) and user_info.coupon is None: coupons["code"] = "not_coupons" coupons["account"] = user_info.account student_info["coupons"] = coupons if score is None: return jsonify(student_info) sub_list = list() for row in Stasub.get_sub(g.db, student_id): sub = dict() sub["id"] = row.id sub["grade"] = row.grade sub_list.append(sub) GREmore = dict() GREmore["sub"] = sub_list GREmore["V"] = score.GRE_v GREmore["Q"] = score.GRE_q GREmore["AW"] = score.GRE_aw GREmore["total"] = user_info.GRE if GREmore.get("total") not in (0, None): student_info["GREmore"] = GREmore IELTSmore = dict() IELTSmore["R"] = score.IELTS_r IELTSmore["L"] = score.IELTS_l IELTSmore["S"] = score.IELTS_s IELTSmore["W"] = score.IELTS_w IELTSmore["total"] = user_info.IELTS if IELTSmore.get("total") not in (0, None): student_info["IELTSmore"] = IELTSmore TOEFLmore = dict() TOEFLmore["R"] = score.TOEFL_r TOEFLmore["L"] = score.TOEFL_l TOEFLmore["S"] = score.TOEFL_s TOEFLmore["W"] = score.TOEFL_w TOEFLmore["total"] = user_info.TOEFL if TOEFLmore.get("total") not in (0, None): student_info["TOEFLmore"] = TOEFLmore SATmore = dict() SATmore["CR"] = score.SAT_cr SATmore["W"] = score.SAT_w SATmore["M"] = score.SAT_m SATmore["total"] = user_info.SAT if SATmore.get("total") not in (0, None): student_info["SATmore"] = SATmore GMATmore = dict() GMATmore["V"] = score.GMAT_v GMATmore["Q"] = score.GMAT_q GMATmore["AW"] = score.GMAT_aw GMATmore["IR"] = score.GMAT_ir GMATmore["total"] = user_info.GMAT if GMATmore.get("V") not in (0, None): student_info["GMATmore"] = GMATmore return json.dumps(student_info)
def set_offer(): if request.method == "POST": data = request.form user_id = session["user_id"] user = User.get_user_info(g.db, user_id) user_type = None if user: user_type = user.type num = 0 user = User.get_user_info(g.db, user_id) while True: offer_major_id = data.get("offers[" + str(num) + "][majorid]") offer_grade = data.get("offers[" + str(num) + "][grade]", "Bachelor") offer_university_id = data.get("offers[" + str(num) + "][universityid]") offer_major_name = data.get("offers[" + str(num) + "][major_name]") offer_type = data.get("offers[" + str(num) + "][offertype]") scholarship_type = data.get("offers[" + str(num) + "][scholarship][type]") scholarship_money = data.get("offers[" + str(num) + "][scholarship][money]") if offer_university_id is None: break num += 1 if num == 6: break id_major = None offer_status = 1 if offer_major_name and offer_major_id is None: major_key = Major.get_major_exit(g.db, offer_major_name) school1_id = 7 main_major = "NotMatched" major_user_type = 2 offer_status = 2 if major_key: major_info = Major.get_major_info_by_mame( g.db, offer_major_name) if major_info: school1_id = major_info.faculty_id major_user_type = 1 main_major = major_info.main_major offer_status = 1 id_major = Major.add_major(g.db, name=offer_major_name, main_major=main_major, university_id=offer_university_id, major_type=user.type, faculty_id=school1_id, major_user_type=major_user_type) User.update_user_grade(g.db, user_id=user_id, grade=offer_grade) Offer.del_same_offer(g.db, university_id=offer_university_id, major_id=offer_major_id, user_id=user_id) if id_major: major_id = Major.get_major_info_by_id_scalar(g.db, id_major) offer_major_id = id_major else: major_id = Major.get_major_info_by_id_scalar( g.db, offer_major_id) school1_id = 0 school2_id = 0 school3_id = 0 if major_id: school1_id = major_id.faculty_id school2_id = major_id.School2_ID school3_id = major_id.School3_ID offer_num = Offer.get_offer_num(g.db, offer_university_id, user_type) num_wechat = 1 if offer_num: if offer_num < 100: num_wechat = 1 elif 100 <= offer_num < 200: num_wechat = 2 elif 200 <= offer_num < 300: num_wechat = 3 wechat = set_university_offer_wechat( University.get_university_from_id( g.db, int(offer_university_id)).short_name, user_type, num_wechat) Offer.set_offer(g.db, user_id=user_id, university_id=offer_university_id, major_id=offer_major_id, school1_id=school1_id, school2_id=school2_id, school3_id=school3_id, user_type=user_type, result=1, wechat=wechat, offer_type=offer_type, grade=offer_grade, scholarship=scholarship_money, scholarship_type=scholarship_type, offer_status=offer_status) un = University.get_university_from_id(g.db, offer_university_id) if un: state_id = un.state_id state_offer_0 = 0 state_offer_1 = 0 state_offer = 0 for row_un in University.get_state_university(g.db, state_id): offer_0 = Offer.get_offer_num(g.db, row_un.id, 0) offer_1 = Offer.get_offer_num(g.db, row_un.id, 1) offer = Offer.get_offer_num(g.db, row_un.id) state_offer_0 += offer_0 state_offer_1 += offer_1 state_offer += offer State.set_offer_num(g.db, state_id, state_offer, state_offer_0, state_offer_1) # 大学分数的计算 offer_GPA = 0 offer_GPA_0 = 0 offer_GPA_1 = 0 offer_TOEFL = 0 offer_IELTS = 0 offer_num = 0 GPA_0_num = 0 GPA_1_num = 0 offer_user_list = list() for offer_user in Offer.get_user_id_from_university( g.db, offer_university_id): of_user = User.get_not_mobile_user(g.db, offer_user.user_id) if of_user is not None and of_user.id not in offer_user_list: if of_user.GPA is not None: offer_GPA += of_user.GPA if of_user.TOEFL is not None: offer_TOEFL += of_user.TOEFL if of_user.IELTS is not None: offer_IELTS += of_user.IELTS if of_user: try: if of_user.type == 0: offer_GPA_0 += of_user.GPA GPA_0_num += 1 else: offer_GPA_1 += of_user.GPA GPA_1_num += 1 except TypeError: print "123" offer_num += 1 offer_user_list.append(of_user.id) if offer_num == 0 or GPA_0_num == 0 or GPA_1_num == 0: offer_num == 1 GPA_0_num == 1 GPA_1_num == 1 try: GPA = offer_GPA / float(offer_num) except ZeroDivisionError: GPA = 0 try: GPA_0 = offer_GPA_0 / float(GPA_0_num) except ZeroDivisionError: GPA_0 = 0 try: GPA_1 = offer_GPA_1 / float(GPA_1_num) except ZeroDivisionError: GPA_1 = 0 try: TOEFL = offer_TOEFL / float(offer_num) except ZeroDivisionError: TOEFL = 0 try: IELTS = offer_IELTS / float(offer_num) except ZeroDivisionError: IELTS = 0 GPA = float("%0.2f" % GPA) GPA_0 = float("%0.2f" % GPA_0) GPA_1 = float("%0.2f" % GPA_1) TOEFL == float("%0.2f" % TOEFL) IELTS = float("%0.2f" % IELTS) University.set_GPA_TOEFL_IELTS(g.db, offer_university_id, GPA, GPA_0, GPA_1, TOEFL, IELTS) offer_list = list() checkList = list() for row_user in Offer.get_offer_student_info(g.db, user_id): offer_dict = dict() offer_dict["universityid"] = row_user.university_id university_name = University.get_university_from_id( g.db, row_user.university_id) if university_name: offer_dict["universityname"] = university_name.chiname offer_dict["twodim"] = row_user.wechat if row_user.university_id not in checkList: offer_list.append(offer_dict) checkList.append(row_user.university_id) return jsonify(status="success", offerlist=offer_list, description=User.get_user_info(g.db, user_id).description)