Example #1
0
def get_compare():
    if request.method == "GET":
        compareid = request.args.get("compareid")
        compare = {}
        compare_info = {}
        comparelist = []
        com = Compare.get_compare(g.db, int(compareid))
        compare["compareid"] = com.id
        compare["description"] = com.description
        compare["date"] = get_timestamp(com.create_time)
        compare["studentid"] = com.user_id
        for row in CompareInfo.get_compare_info(g.db, compareid):
            compare_info["universityid"] = row.university_id
            compare_info["major_id"] = row.major_id
            compare_info["supportnum"] = row.supportnum
            for university in University.get_university_info(g.db, university_id=row.university_id):
                compare_info["universityname"] = university.name
                compare_info["logo"] = get_university_logo(university.name)
            for major in Major.get_major_info(g.db,
                                              university_id=compare_info[
                                                  "universityid"],
                                              major_id=compare_info[
                                                  "major_id"]):
                compare_info["majorname"] = major.name
            compare_info["offernum"] = Offer.get_offer_num(g.db, row.university_id)
            comparelist.append(compare_info)

            compare_info = {}
        compare["comparelist"] = comparelist
        compare["status"] = "success"
        return json.dumps(compare)
Example #2
0
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)
Example #3
0
def mobile_set_offer():
    if request.method == "POST":
        data = request.form
        university_id = data.get("university_id", int)
        offer_major_id = data.get("major_id", int)
        offer_major_name = data.get("majorname")
        user_type = data.get("user_type", int)

        grade = data.get("grade")
        phone = data.get("phone")
        check_num = data.get("check_num")

        user_check = User.get_checknum(g.db, phone)
        if user_check is None:
            return json.dumps({"status": "user_not_exit"})
        print user_check
        print data, check_num
        if check_num == "":
            print("adfasdf")
        else:
            type(check_num),

        if check_num != "":
            if str(user_check.checknum) == check_num:
                User.set_mobile_user_grade(g.db, phone, grade)
                user = User.get_user_info_by_phone(g.db, phone)
            else:
                return json.dumps({"status": "check_num_error"})

        id_major = None
        offer_status = 1
        if offer_major_id is None:
            print offer_major_id, "123123"
        if offer_major_id == "":
            print "fasdfasd"
        print offer_major_name
        if offer_major_name and offer_major_id == "":
            print
            major_key = Major.get_major_exit(g.db, offer_major_name)
            print major_key
            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=university_id,
                                       major_type=user.type,
                                       faculty_id=school1_id,
                                       major_user_type=major_user_type)

        if id_major:
            major_id_info = Major.get_major_info_by_id_scalar(g.db, id_major)
            offer_major_id = id_major
        else:
            major_id_info = Major.get_major_info_by_id_scalar(
                g.db, offer_major_id)

        school1_id = 0
        school2_id = 0
        school3_id = 0
        if major_id_info:
            school1_id = major_id_info.faculty_id
            school2_id = major_id_info.School2_ID
            school3_id = major_id_info.School3_ID
        offer_num = Offer.get_offer_num(g.db, 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, university_id).short_name,
            user_type, num_wechat)
        print offer_major_id
        Offer.del_same_offer(g.db,
                             university_id=university_id,
                             major_id=offer_major_id,
                             user_id=user_check.id)

        Offer.set_offer_mobile(g.db,
                               user_id=user_check.id,
                               university_id=university_id,
                               major_id=offer_major_id,
                               school1_id=school1_id,
                               school2_id=school2_id,
                               school3_id=school3_id,
                               user_type=user_type,
                               grade=grade,
                               wechat=wechat,
                               offer_type="AD",
                               offer_status=offer_status)
        offer_list = list()
        checkList = list()
        university_name = None
        twodim = None
        for last_offer in Offer.get_mobile_user_last_offer(
                g.db, user_check.id):
            print last_offer
            try:
                university_name = University.get_university_from_id(
                    g.db, last_offer[1])
                twodim = last_offer[2]
            except IndexError:
                university_name = None

        offer_dict = dict()
        if university_name:
            offer_dict["universityname"] = university_name.chiname
            offer_dict["logo"] = get_university_logo(university_name.name)
            offer_dict["twodim"] = twodim

            offer_list.append(offer_dict)

        return json.dumps({
            "status":
            "success",
            "offerlist":
            offer_list,
            "description":
            User.get_user_info(g.db, user_check.id).description
        })
Example #4
0
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)