Exemple #1
0
def register_second():
    if request.method == "POST":
        data = request.form

        email = data["email"]
        password = set_password_salt(data["password"])
        phone = data.get("phonenum")
        username = data.get("username")
        university_id = data.get("universityid")
        gpa = data["gpa"]
        user_type = data.get("type")
        if int(user_type) == 0:
            senior_dict = {'1': u"文科", '2': u"理科", '3': u"其他"}
            senior = SeniorHighSchool.get_senior_high(g.db, university_id)
            university_name = senior.name

            major_name = senior_dict.get(data.get("majorid"))
        else:
            university = UniversityChina.get_university_china_info(
                g.db, university_id)
            university_name = university.name
            major_id = int(data.get("majorid"))

            major_name = MajorChina.get_major_china(g.db, major_id).major_name

        create_time = time()
        active = 1
        if User.get_mobile_user_phone(g.db, phone):
            active = 2
        User.register_second(g.db, email, password, phone, username,
                             university_name, major_name, gpa, user_type,
                             create_time, active)
        user = User.get_user_info_by_phone(g.db, phone)
        user_id = user.id
        session["user_id"] = user_id
        incomplete = "false"
        if user.mobile_user == 2:
            incomplete = "true"
        User.update_user_pic(
            g.db, user_id,
            """http://www.ufindoffer.com/images/unimg/head/%E6%97%A0%E6%80%A7%E5%88%AB/"""
            + str(randint(1, 17)) + """.jpg""")
        Offer.update_offer_status(g.db, user_id)

        return jsonify(status="success",
                       cookie=str(user_id),
                       incomplete=incomplete)
    return jsonify(status="false")
Exemple #2
0
def get_offers():
    page = int(request.args.get('page', 1))
    order = request.args.get('order', 'desc')

    offers = Offer.get_by_page(order, page)

    return response(offers_schema.dump(offers))
Exemple #3
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)
Exemple #4
0
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")
Exemple #5
0
def create_offer():
    json = request.get_json(force=True)
    error = params_offer_schema.validate(json)
    json['starts_at'] = datetime(2020, 1, 1, 10, 10,
                                 0)  ## todo convert date parameters
    json['ends_at'] = datetime(2021, 1, 1, 10, 10, 0)

    if error:
        print(error)
        return bad_request()

    offer = Offer.new(
        departament=json['departament'],
        description=json['description'],
        cost=json['cost'],
        tax=json['tax'],
        price=json['price'],
        quantity=json['quantity'],
        starts_at=json['starts_at'],
        ends_at=json['ends_at'],
        product_id=json['product_id'],
    )
    print(offer.save())
    if offer.save():
        return response(offer_schema.dump(offer))

    return bad_request()
Exemple #6
0
def offers():
    """ Offers """

    params = request.args

    user_id = params.get('logged_user_id')
    if not user_id:
        return jsonify({'success': False, 'msg': 'missing logged_user_id'})

    if request.method == 'GET':
        return jsonify(list_offers(user_id))

    elif request.method == 'POST':
        offer_id = params.get('offer_id')
        title = params.get('title')
        description = params.get('description')
        end_offer = params.get('endOffer')
        email = params.get('email')
        phone = params.get('phone')
        offer_type = params.get('offer_type')
        salary_aids = params.get('salary_aids')
        salary_total = params.get('salary_total')
        location = params.get('location')
        latitude = params.get('latitude')
        longitude = params.get('longitude')

        offer = Offer(offer_id, title, description, user_id, end_offer, email,
                      phone, offer_type, salary_aids, salary_total, location,
                      latitude, longitude)

        return jsonify(insert_offer(offer))

    return jsonify({'success': True})
Exemple #7
0
    def post(self):
        data = check_request_json(request)

        host_id = data.get('host_id')
        if host_id is None:
            missing_required_field('host_id')

        portions = data.get('portions')
        if portions is None:
            missing_required_field('portions')

        price = data.get('price')
        if price is None:
            missing_required_field('price')

        info = data.get('info')
        if info is None:
            missing_required_field('info')

        time_ready = data.get('time_ready')
        if time_ready is None:
            missing_required_field('time_ready')

        if ecv.testing:
            user = ecv.session.query(User).filter_by(id=host_id).first()
            offer = Offer(
                host=user,
                portions=portions,
                price=price,
                info=info,
                time_ready=datetime.datetime.fromtimestamp(time_ready))
            ecv.session.add(offer)
            ecv.session.commit()

            return offer.to_dict(), 201
        else:
            p = Publisher()
            result = p.addoffer(host_id=host_id,
                                portions=portions,
                                price=price,
                                info=info,
                                time_ready=time_ready)
            return result, 201
Exemple #8
0
    def post(self):
        args = CreateOffer.parser.parse_args()
        offer = Offer(user_email=args.get('user_email'),
                      quantity=args.get('quantity'),
                      requestId=args.get('requestId'),
                      price=args.get('price'),
                      willing_to_transport=args.get('willing_to_transport'),
                      image=args.get('image'))
        session.add(offer)
        session.commit()

        return {'response': 'success'}
Exemple #9
0
def get_offer_student():
    if request.method == "GET":
        user_id = session.get("user_id")
        user = User.get_user_info(g.db, user_id)
        user_type = -1
        if user:
            user_type = user.type

        university_id, major_id = map(request.args.get,
                                      ("universityid", "majorid"))
        student_list = []
        for row in Offer.get_offer_student(g.db, university_id, major_id,
                                           user_type):
            student_list.append(row.user_id)
        return jsonify(studentlist=student_list, status="success")
Exemple #10
0
def main():
    current_page = args.page_number
    try:
        print("Processing page {}...".format(current_page))
        result = make_request(args, current_page)

        if 'error' in result:
            exit()

        res = result['response']['search']['offers']['entities']
        # res = list(filter(lambda r: r['building'].get('buildingId'), res))
        for e in convert(res):
            session.merge(Author(*e['author']))
            if e['site']:
                session.merge(Site(*e['site']))
            if e['building']:
                session.merge(Building(*e['building']))
                nbid = None
            else:
                nb = session.merge(NewBuilding(*e['new_building']))
                session.commit(
                )  # todo it's working now only for new buildings autoinc IDs
                nbid = nb.id
            o = (nbid, ) + e['offer']
            session.merge(Offer(*o))
            # session.merge(Photo(*e['photo']))
        # for ent in res:
        #     session.merge(Offer(
        #         ent['offerId'],
        #         ent['active'],
        #         ent['area']['value'],
        #         ent['building'].get('houseId')
        #     ))

        session.commit()
        current_page += 1
        print("Waiting {0} seconds".format(args.delay))
        time.sleep(args.delay)
    except Exception as e:
        print(e)
        print("Unknown exception, waiting 60 seconds.")
        time.sleep(60)
    except KeyboardInterrupt:
        print("Finishing...")
        exit()
    print("Done")
Exemple #11
0
def offer(db, user_host):
    o = Offer(
        host_id=user_host.id,
        portions=5,
        price=10.50,  # price is per portion
        info='this is a test description',
        time_ready=datetime.datetime.utcnow() + datetime.timedelta(hours=10),
        time_created=datetime.datetime.utcnow())

    db.session.add(o)
    db.session.commit()

    yield o

    if inspect(o).persistent:
        db.session.delete(o)
        db.session.commit()
Exemple #12
0
	def add_offer(self, offer):
		host_id = offer["host_id"]
		portions = offer["portions"]
		price = offer["price"]
		info = offer["info"]
		time_ready = offer["time_ready"]
		time_ready = datetime.strptime(time_ready, '%Y-%m-%d %H:%M:%S.%f')
	
		session=self.DBSession
		user=session.query(User).filter(User.id==host_id).first()
		if not user:
			return "User does not exist"
		try:
			self.sync.create_obj(Offer(host=user, portions=portions, price=price, info=info, time_ready=time_ready))
			print (" > "+user.username+" offered a meal with "+str(portions)+" for EUR "
				+str(price)+" per portion. It will be ready at "+str(time_ready)+". \""+info+"\"")
			return "SUCCESS"
		except IntegrityError:
			print (" > Failed to add offer made by "+user.username)
			return "FAILURE"
Exemple #13
0
    def post(self, article_id):

        article = Article.query.filter_by(id=article_id).first()

        try:
            expected_value = int(request.form['new_price'])
            if expected_value < article.minimal_price:
                raise ValueError
        except ValueError:
            flash("Price lower than expected")
            return redirect(url_for('article', article_id=article_id))
        except Exception:
            flash("Invalid price")
            return redirect(url_for('article', article_id=article_id))

        us = User.query.filter_by(username=session.get('username')).first()
        new_offer = Offer(article_id=article.id,
                          user_id=us.id,
                          price=request.form['new_price'])
        db.session.add(new_offer)
        db.session.commit()
        return redirect(url_for('article', article_id=article_id))
Exemple #14
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)
Exemple #15
0
 def test_get_total_offer_2(self):
     cart = self._create_cart()
     offer = Offer(UserGroup.GOLD, datetime.now(),
                   datetime.now() + timedelta(days=1), 'black', 3000, 50)
     total = cart.get_total(offer)
     self.assertEqual(total, Decimal('2847'))
Exemple #16
0
def get_major_from_university_faculty():
    u"""投票根据学校和学院返回专业信息"""
    if request.method == "GET":
        user = User.get_user_info(g.db, user_id=session.get("user_id"))
        university_id, faculty_id, major_id = map(
            request.args.get, ("universityid", "facultyid", "majorid"))

        user_type = None
        if user:
            user_type = user.type

        major_list = list()
        if faculty_id is None and major_id is None:
            for row in Major.get_major_info_university(g.db, university_id):
                students = list()
                major_info = dict()
                print row.name
                major_info["majorid"] = row.id
                major_info["name"] = row.name
                major_info["offernum"] = Offer.get_offer_num_from_major(
                    g.db, university_id, row.id)
                major_info["offervote"] = None
                #offervote = dict()
                for row_major in Offer.get_user_id_from_major(
                        g.db, row.id, user_type):
                    student_info = dict()
                    user = User.get_not_mobile_user(g.db, row_major.user_id)
                    if user:
                        student_info["studentid"] = user.id
                        student_info["studentimg"] = user.pic
                        student_info["name"] = user.username
                        student_info["GPA"] = user.GPA
                        student_info["prevuniversity"] = user.prevuniversity

                        students.append(student_info)
                        major_info["students"] = students
                if major_info.get("students") is not None:
                    major_list.append(major_info)
            return jsonify(status="success", majorlist=major_list)
        elif major_id is None:
            faculty_list = faculty_id.split(",")
            for faculty_id in faculty_list:
                for row in Major.get_major_info(connection=g.db,
                                                university_id=university_id,
                                                faculty_id=faculty_id):

                    students = list()
                    major_info = {}
                    major_info["majorid"] = row.id
                    major_info["name"] = row.name
                    major_info["offernum"] = Offer.get_offer_num_from_major(
                        g.db, university_id, row.id)
                    major_info["offervote"] = None
                    for row_major in Offer.get_user_id_from_major(
                            g.db, row.id, user_type):
                        student_info = dict()
                        user = User.get_not_mobile_user(
                            g.db, row_major.user_id)
                        if user:
                            student_info["studentid"] = user.id
                            student_info["name"] = user.username
                            student_info["studentimg"] = user.pic
                            student_info["GPA"] = user.GPA
                            student_info[
                                "prevuniversity"] = user.prevuniversity
                            students.append(student_info)
                            major_info["students"] = students
                    if major_info.get("students") is not None:
                        major_list.append(major_info)
            return jsonify(status="success", majorlist=major_list)
        elif major_id is not None:
            students = list()
            for row in Major.get_major_info(g.db,
                                            university_id=university_id,
                                            major_id=major_id):
                major_info = dict()
                major_info["majorid"] = row.id
                major_info["name"] = row.name

                major_info["offernum"] = Offer.get_offer_num_from_major(
                    g.db, university_id, row.id)
                major_info["offervote"] = None
                for row_major in Offer.get_user_id_from_major(
                        g.db, row.id, user_type):
                    student_info = dict()
                    user = User.get_not_mobile_user(g.db, row_major.user_id)
                    if user:
                        student_info["studentid"] = user.id
                        student_info["name"] = user.username
                        student_info["studentimg"] = user.pic
                        student_info["GPA"] = user.GPA
                        student_info["prevuniversity"] = user.prevuniversity
                        students.append(student_info)
                        major_info["students"] = students

                if major_info.get("students") is not None:
                    major_list.append(major_info)
            return jsonify(status="success", majorlist=major_list)
Exemple #17
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)
Exemple #18
0
def update_user_info():
    U"""用户更新资料"""
    if request.method == "POST":
        user_id = session.get("user_id")
        phone = request.form.get("phonenum")
        username = request.form.get("engname")
        email = request.form.get("email")
        pic = request.form.get("pic")
        print request.form
        phone = request.form.get("phonenum")
        check_num = request.form.get("checknum")
        user = User.get_user_info(g.db, user_id)
        if check_num or check_num == "":
            print user.checknum, check_num, checknum_timeout(
                user.checknum_time)
            if check_num == "":
                return jsonify(status="checknum_error")
            if user.checknum == int(check_num) and checknum_timeout(
                    user.checknum_time):
                User.update_user_phone(
                    g.db,
                    user.id,
                    phone,
                    user.phone_old,
                )
            else:
                return jsonify(status="checknum_error")
        if request.form.get("passwordold"):
            password = request.form.get("password")
            passwordold = request.form.get("passwordold")
            if not User.change_password_old(g.db, user_id,
                                            set_password_salt(password),
                                            set_password_salt(passwordold)):

                return jsonify(status="false")
        if pic is not None:
            User.update_user_pic(g.db, user_id, pic)

        Stasub.del_sub(g.db, user_id)
        if request.form.get("GRE[sub][0][id]"):
            num = 0
            while True:
                if request.form.get("GRE[sub][" + str(num) + "][id]"):
                    sub_id = request.form.get("GRE[sub][" + str(num) + "][id]",
                                              0, int)
                    grade = request.form.get(
                        "GRE[sub][" + str(num) + "][grade]", 0, int)
                    sub_type = 0
                    if sub_id > 10:
                        sub_type = 1
                    Stasub.set_sub(g.db,
                                   sub_id=sub_id,
                                   grade=grade,
                                   sub_type=sub_type,
                                   user_id=user_id)
                    num += 1
                else:
                    break

        # Stasub.del_sub(g.db,user_id)
        if request.form.get("SAT[sub][0][grade]"):
            num = 0
            while True:
                if request.form.get("SAT[sub][" + str(num) + "][id]"):
                    sub_id = request.form.get("SAT[sub][" + str(num) + "][id]",
                                              0, int)
                    grade = request.form.get(
                        "SAT[sub][" + str(num) + "][grade]", 0, int)
                    sub_type = 0
                    if sub_id > 10:
                        sub_type = 1
                    Stasub.set_sub(g.db,
                                   sub_id=sub_id,
                                   grade=grade,
                                   sub_type=sub_type,
                                   user_id=user_id)
                    num += 1
                else:
                    break

        prevmajor = request.form.get("majorid")
        prevuniversity = request.form.get("universityid")
        User.update_user_info(g.db,
                              user_id=user_id,
                              username=username,
                              email=email,
                              prevuniversity=prevuniversity,
                              prevmajor=prevmajor)
        if request.form.get("IELTS[R]") is not None:
            LELTSmoreR = request.form.get("IELTS[R]", float)
            LELTSmoreL = request.form.get("IELTS[L]", float)
            LELTSmoreS = request.form.get("IELTS[S]", float)
            LELTSmoreW = request.form.get("IELTS[W]", float)
            sub_TELTS = request.form.get("IELTS[total]", float)

            if request.form.get("GRE[V]") is not None:
                GREmoreV = request.form.get("GRE[V]", int)
                GREmoreQ = request.form.get("GRE[Q]", int)
                GREmoreAW = request.form.get("GRE[AW]", float)
                sub_GRE = request.form.get("GRE[total]", int)
                User.update_user_score(g.db,
                                       user_id,
                                       gre=sub_GRE,
                                       lelts=sub_TELTS)
                Score.set_user_info(connection=g.db,
                                    user_id=user_id,
                                    IELTS_r=LELTSmoreR,
                                    IELTS_l=LELTSmoreL,
                                    IELTS_s=LELTSmoreS,
                                    IELTS_w=LELTSmoreW,
                                    GRE_v=GREmoreV,
                                    GRE_q=GREmoreQ,
                                    GRE_aw=GREmoreAW)
            elif request.form.get("SAT[M]"):
                sat_m = request.form.get("SAT[M]", int)
                sat_cr = request.form.get("SAT[CR]", int)
                sat_w = request.form.get("SAT[W]", int)
                sub_sat = request.form.get("SAT[total]", int)
                User.update_user_score(g.db,
                                       user_id=user_id,
                                       lelts=sub_TELTS,
                                       sat=sub_sat)
                Score.set_user_info(connection=g.db,
                                    user_id=user_id,
                                    IELTS_r=LELTSmoreR,
                                    IELTS_l=LELTSmoreL,
                                    IELTS_s=LELTSmoreS,
                                    IELTS_w=LELTSmoreW,
                                    SAT_m=sat_m,
                                    SAT_w=sat_w,
                                    SAT_cr=sat_cr)

            else:
                GMATmoreV = request.form.get("GMAT[V]", int)
                GMATmoreQ = request.form.get("GMAT[Q]", int)
                GMATmoreAW = request.form.get("GMAT[AW]", float)
                GMATmoreIR = request.form.get("GMAT[IR]", int)
                sub_GMAT = request.form.get("GMAT[total]", int)
                User.update_user_score(g.db,
                                       user_id=user_id,
                                       lelts=sub_TELTS,
                                       GMAT=sub_GMAT)
                Score.set_user_info(connection=g.db,
                                    user_id=user_id,
                                    IELTS_r=LELTSmoreR,
                                    IELTS_l=LELTSmoreL,
                                    IELTS_s=LELTSmoreS,
                                    IELTS_w=LELTSmoreW,
                                    GMAT_v=GMATmoreV,
                                    GMAT_q=GMATmoreQ,
                                    GMAT_aw=GMATmoreAW,
                                    GMAT_ir=GMATmoreIR)

        elif request.form.get("TOEFL[R]") is not None:

            TOEFLmoreR = request.form.get("TOEFL[R]", int)
            TOEFLmoreL = request.form.get("TOEFL[L]", int)
            TOEFLmoreS = request.form.get("TOEFL[S]", int)
            TOEFLmoreW = request.form.get("TOEFL[W]", int)
            sub_TOEFL = request.form.get("TOEFL[total]", int)
            if request.form.get("GRE[V]") is not None:
                GREmoreV = request.form.get("GRE[V]", int)
                GREmoreQ = request.form.get("GRE[Q]", int)
                GREmoreAW = request.form.get("GRE[AW]", float)
                sub_GRE = request.form.get("GRE[total]", int)
                User.update_user_score(g.db,
                                       user_id=user_id,
                                       gre=sub_GRE,
                                       toefl=sub_TOEFL)
                Score.set_user_info(connection=g.db,
                                    user_id=user_id,
                                    TOEFL_r=TOEFLmoreR,
                                    TOEFL_l=TOEFLmoreL,
                                    TOEFL_s=TOEFLmoreS,
                                    TOEFL_w=TOEFLmoreW,
                                    GRE_v=GREmoreV,
                                    GRE_q=GREmoreQ,
                                    GRE_aw=GREmoreAW)
            elif request.form.get("SAT[M]"):
                sat_m = request.form.get("SAT[M]", 0, int)
                sat_cr = request.form.get("SAT[CR]", 0, int)
                sat_w = request.form.get("SAT[W]", 0, int)
                sub_sat = request.form.get("SAT[total]", 0, int)

                User.update_user_score(g.db,
                                       user_id=user_id,
                                       toefl=sub_TOEFL,
                                       sat=sub_sat)
                Score.set_user_info(connection=g.db,
                                    user_id=user_id,
                                    TOEFL_r=TOEFLmoreR,
                                    TOEFL_l=TOEFLmoreL,
                                    TOEFL_s=TOEFLmoreS,
                                    TOEFL_w=TOEFLmoreW,
                                    SAT_m=sat_m,
                                    SAT_w=sat_w,
                                    SAT_cr=sat_cr)
            else:
                GMATmoreV = request.form.get("GMAT[V]", int)
                GMATmoreQ = request.form.get("GMAT[Q]", int)
                GMATmoreAW = request.form.get("GMAT[AW]", float)
                GMATmoreIR = request.form.get("GMAT[IR]", int)
                sub_GMAT = request.form.get("GMAT[total]", int)

                User.update_user_score(g.db,
                                       user_id=user_id,
                                       toefl=sub_TOEFL,
                                       GMAT=sub_GMAT)
                Score.set_user_info(connection=g.db,
                                    user_id=user_id,
                                    TOEFL_r=TOEFLmoreR,
                                    TOEFL_l=TOEFLmoreL,
                                    TOEFL_s=TOEFLmoreS,
                                    TOEFL_w=TOEFLmoreW,
                                    GMAT_v=GMATmoreV,
                                    GMAT_q=GMATmoreQ,
                                    GMAT_aw=GMATmoreAW,
                                    GMAT_ir=GMATmoreIR)
        User.set_user_active(g.db, user_id)
        Offer.set_user_offer_result(g.db, user_id)
        return jsonify(status="success")
    return jsonify(status="false")
Exemple #19
0
def get_user_in_university():
    if request.method == "POST":
        data = request.form
        #return jsonify(status="success")
        #data = json.loads(request.data)
        user_id = session.get("user_id")
        user = User.get_user_info(g.db, user_id)
        user_type = -1
        if user:
            user_type = user.type

        university_id = data.get("universityid")
        faculty_id = data.get("facultyid")
        major_id = data.get("majorid")
        GPA_to = data.get("GPA[to]", 0.0, float)
        GPA_form = data.get("GPA[from]", 1000, float)
        TOEFL_to = request.form.get("TOEFL[to]", 0.0, float)
        TOEFL_form = request.form.get("TOEFL[from]", 10000, float)

        IELTS_to = request.form.get("IELTS[to]", 0.0, float)
        IELTS_form = request.form.get("IELTS[from]", 10000, float)
        if TOEFL_to != 0.0 and TOEFL_form != 10000:
            IELTS_to = 0.0
            IELTS_form = 0.0
        elif IELTS_to != 0.0 and IELTS_form != 10000:
            TOEFL_to = 0.0
            TOEFL_form = 0.0

        GRE_to = request.form.get("GRE[to]", 0.0, float)
        GRE_form = request.form.get("GRE[from]", 10000, float)
        GMAT_to = request.form.get("GMAT[to]", 0.0, float)
        GMAT_form = request.form.get("GMAT[from]", 10000, float)
        if GRE_to != 0.0 and GRE_form != 10000:
            GMAT_to = 0.0
            GMAT_form = 0.0
        elif GMAT_to != 0.0 and GMAT_form != 10000:
            GRE_to = 0.0
            GRE_form = 0.0

        grade = request.form.get("grade")
        print grade
        page = data.get("page", 0, int)

        compares = {}
        compare_list = []
        page_list = []
        print faculty_id, major_id, university_id

        if faculty_id is not None:
            student_list = []
            if major_id is None:
                major_list = dict()
                info = list()
                for row_major in Major.get_major_from_faculty(
                        g.db, university_id, faculty_id):
                    student_list = list()
                    student = dict()
                    for row in Offer.get_user_id_from_university(
                            g.db, university_id, row_major.id, user_type,
                            grade):
                        user = User.get_not_mobile_user(g.db, row.user_id)
                        if user:
                            if get_compare_score(GPA_to,GPA_form,user.GPA) and \
                                get_compare_score(TOEFL_to,TOEFL_form,user.TOEFL) and \
                                get_compare_score(IELTS_to,IELTS_form,user.IELTS) and \
                                get_compare_score(GRE_to,GRE_form,user.GRE) and \
                                get_compare_score(GMAT_to,GMAT_form,user.GMAT):
                                if row.user_id not in student_list:
                                    student_list.append(row.user_id)
                    student["studentlist"] = student_list
                    student["majorid"] = row_major.id
                    student["majorname"] = row_major.name
                    user_page = len(student_list) / 15
                    student["more"] = ""
                    if user_page > page:
                        student["more"] = "true"
                        for row in range(user_page):
                            if row == page:
                                student["studentlist"] = student_list[page *
                                                                      16:]
                    if len(student.get("studentlist")) > 0:
                        info.append(student)

                major_list["majorlist"] = info
                major_list["status"] = "success"
                return json.dumps(major_list)
            elif major_id is not None:
                for row in Offer.get_user_id_from_university(
                        g.db, university_id, major_id, user_type, grade):
                    user = User.get_not_mobile_user(g.db, row.user_id)
                    if user:
                        if get_compare_score(GPA_to,GPA_form,user.GPA) and \
                                get_compare_score(TOEFL_to,TOEFL_form,user.TOEFL) and \
                                get_compare_score(IELTS_to,IELTS_form,user.IELTS) and \
                                get_compare_score(GRE_to,GRE_form,user.GRE) and \
                                get_compare_score(GMAT_to,GMAT_form,user.GMAT):

                            if row.user_id not in student_list:
                                student_list.append(row.user_id)
                        student = dict()
                        student["studentlist"] = list(set(student_list))
                        page = len(student_list) / 15
                        student["more"] = ""
                        if int(page) > 1:
                            student["more"] = "true"
                        student["status"] = "success"
                        return json.dumps(student)
        else:
            student_list = []
            for row in Offer.get_user_id_from_university(
                    g.db, university_id, major_id, user_type, grade):
                user = User.get_not_mobile_user(g.db, row.user_id)
                if user:

                    if get_compare_score(GPA_to,GPA_form,user.GPA) and \
                                get_compare_score(TOEFL_to,TOEFL_form,user.TOEFL) and \
                                get_compare_score(IELTS_to,IELTS_form,user.IELTS) and \
                                get_compare_score(GRE_to,GRE_form,user.GRE) and \
                                get_compare_score(GMAT_to,GMAT_form,user.GMAT):
                        if row.user_id not in student_list:
                            student_list.append(row.user_id)
            student = dict()

            user_page = len(student_list) / 16
            user_page_last = len(student_list) % 16
            student["more"] = ""
            if len(student_list) < 16:
                student["status"] = "success"
                student["studentlist"] = student_list
                return json.dumps(student)
            if user_page > page:
                for row in range(user_page):
                    if row == page:
                        student["studentlist"] = student_list[page *
                                                              16:(page + 1) *
                                                              16]
                        student["more"] = "true"
                        break

            elif user_page < page:
                student["studentlist"] = student_list[-user_page_last:]
            student["status"] = "success"
            return json.dumps(student)

        return jsonify(status="success")
Exemple #20
0
def get_index():
    if request.method == "GET":
        statelist = {}
        country = []
        state = {}
        local = {}
        data = {}
        user_type = None
        user = User.get_user_info(g.db, user_id=session.get("user_id"))
        if user:
            user_type = user.type

        for row in State.get_index(g.db, u"USA"):

            state["stateid"] = row.id
            state["name"] = row.name
            state["latitude"] = row.latitude
            state["longitude"] = row.longitude
            if user_type is None:
                state["offernum"] = row.offernum
            elif user_type == 0:
                state["offernum"] = row.offernum_0
            else:
                state["offernum"] = row.offernum_1

            country.append(state)
            state = {}
        local["USA"] = country
        country = []
        for row in State.get_index(g.db, u"UK"):
            state["stateid"] = row.id
            state["name"] = row.name
            state["latitude"] = row.latitude
            state["longitude"] = row.longitude
            if user_type is None:
                state["offernum"] = row.offernum
            elif user_type == 0:
                state["offernum"] = row.offernum_0
            else:
                state["offernum"] = row.offernum_1
            country.append(state)
            state = {}
        local["UK"] = country
        country = []
        for row in State.get_index(g.db, u"AUS"):

            state["stateid"] = row.id
            state["name"] = row.name
            state["latitude"] = row.latitude
            state["longitude"] = row.longitude
            if user_type is None:
                state["offernum"] = row.offernum
            elif user_type == 0:
                state["offernum"] = row.offernum_0
            else:
                state["offernum"] = row.offernum_1
            country.append(state)
            state = {}
        local["AUS"] = country
        statelist["USA"] = local["USA"]
        statelist["UK"] = local["UK"]
        statelist["AUS"] = local["AUS"]
        data["statelist"] = statelist
        data["offernum"] = Offer.get_site_offer_num(g.db, user_type) + 500
        data["status"] = "success"
        return json.dumps(data)
Exemple #21
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
        })
Exemple #22
0
def set_user_score():
    if request.method == "POST":
        user_id = session.get("user_id")
        if request.form.get("bginf") is not None:
            bginf = request.form.get("bginf")
            User.update_user_bginf(g.db, user_id, bginf)
        Stasub.del_sub(g.db, user_id)
        if request.form.get("GREmore[sub][0][id]"):
            num = 0

            while True:
                if request.form.get("GREmore[sub][" + str(num) + "][id]"):
                    sub_id = request.form.get(
                        "GREmore[sub][" + str(num) + "][id]", 0, int)
                    grade = request.form.get(
                        "GREmore[sub][" + str(num) + "][grade]", 0, int)

                    sub_type = 0
                    if sub_id > 10:
                        sub_type = 1
                    Stasub.set_sub(g.db,
                                   sub_id=sub_id,
                                   grade=grade,
                                   sub_type=sub_type,
                                   user_id=user_id)
                    num += 1
                else:
                    break

        if request.form.get("SATmore[sub][0][grade]"):
            num = 0

            while True:
                if request.form.get("SATmore[sub][" + str(num) + "][id]"):
                    sub_id = request.form.get(
                        "SATmore[sub][" + str(num) + "][id]", 0, int)
                    grade = request.form.get(
                        "SATmore[sub][" + str(num) + "][grade]", 0, int)
                    sub_type = 0
                    if sub_id > 10:
                        sub_type = 1
                    Stasub.set_sub(g.db,
                                   sub_id=sub_id,
                                   grade=grade,
                                   sub_type=sub_type,
                                   user_id=user_id)
                    num += 1
                else:
                    break

        if request.form.get("IELTSmore[R]") is not None:
            LELTSmoreR = request.form.get("IELTSmore[R]", float)
            LELTSmoreL = request.form.get("IELTSmore[L]", float)
            LELTSmoreS = request.form.get("IELTSmore[S]", float)
            LELTSmoreW = request.form.get("IELTSmore[W]", float)
            sub_TELTS = request.form.get("IELTSmore[total]", float)
            #sub_TELTS = get_TELTS(LELTSmoreS, LELTSmoreL, LELTSmoreR,
            #                      LELTSmoreW)
            if request.form.get("GREmore[V]") is not None:
                GREmoreV = request.form.get("GREmore[V]", int)
                GREmoreQ = request.form.get("GREmore[Q]", int)
                GREmoreAW = request.form.get("GREmore[AW]", float)
                sub_GRE = request.form.get("GREmore[total]", int)

                User.update_user_score(g.db,
                                       user_id,
                                       gre=sub_GRE,
                                       lelts=sub_TELTS)
                Score.set_user_info(connection=g.db,
                                    user_id=user_id,
                                    IELTS_r=LELTSmoreR,
                                    IELTS_l=LELTSmoreL,
                                    IELTS_s=LELTSmoreS,
                                    IELTS_w=LELTSmoreW,
                                    GRE_v=GREmoreV,
                                    GRE_q=GREmoreQ,
                                    GRE_aw=GREmoreAW)
            elif request.form.get("SATmore[M]") is not None:
                sat_m = request.form.get("SATmore[M]", int)
                sat_cr = request.form.get("SATmore[CR]", int)
                sat_w = request.form.get("SATmore[W]", int)
                sub_sat = request.form.get("SATmore[total]", int)
                #sub_sat = get_SAT(sat_cr,sat_w,sat_m)
                User.update_user_score(g.db,
                                       user_id=user_id,
                                       lelts=sub_TELTS,
                                       sat=sub_sat)
                Score.set_user_info(connection=g.db,
                                    user_id=user_id,
                                    IELTS_r=LELTSmoreR,
                                    IELTS_l=LELTSmoreL,
                                    IELTS_s=LELTSmoreS,
                                    IELTS_w=LELTSmoreW,
                                    SAT_m=sat_m,
                                    SAT_w=sat_w,
                                    SAT_cr=sat_cr)
            elif request.form.get("GMATmore[V]") is not None:
                GMATmoreV = request.form.get("GMATmore[V]", int)
                GMATmoreQ = request.form.get("GMATmore[Q]", int)
                GMATmoreAW = request.form.get("GMATmore[AW]", float)
                GMATmoreIR = request.form.get("GMATmore[IR]", int)
                sub_GMAT = request.form.get("GMATmore[total]", int)
                User.update_user_score(g.db,
                                       user_id=user_id,
                                       lelts=sub_TELTS,
                                       GMAT=sub_GMAT)
                Score.set_user_info(connection=g.db,
                                    user_id=user_id,
                                    IELTS_r=LELTSmoreR,
                                    IELTS_l=LELTSmoreL,
                                    IELTS_s=LELTSmoreS,
                                    IELTS_w=LELTSmoreW,
                                    GMAT_v=GMATmoreV,
                                    GMAT_q=GMATmoreQ,
                                    GMAT_aw=GMATmoreAW,
                                    GMAT_ir=GMATmoreIR)
        elif request.form.get("TOEFLmore[R]") is not None:
            TOEFLmoreR = request.form.get("TOEFLmore[R]", int)
            TOEFLmoreL = request.form.get("TOEFLmore[L]", int)
            TOEFLmoreS = request.form.get("TOEFLmore[S]", int)
            TOEFLmoreW = request.form.get("TOEFLmore[W]", int)
            sub_TOEFL = request.form.get("TOEFLmore[total]", int)
            #sub_TOEFL = get_Total(TOEFLmoreL, TOEFLmoreR, TOEFLmoreS,
            #                      TOEFLmoreW)
            if request.form.get("GREmore[V]") is not None:
                GREmoreV = request.form.get("GREmore[V]", int)
                GREmoreQ = request.form.get("GREmore[Q]", int)
                GREmoreAW = request.form.get("GREmore[AW]", float)
                sub_GRE = request.form.get("GREmore[total]", int)
                #sub_GRE = get_gre(GREmoreV, GREmoreQ)
                User.update_user_score(g.db,
                                       user_id=user_id,
                                       gre=sub_GRE,
                                       toefl=sub_TOEFL)
                Score.set_user_info(connection=g.db,
                                    user_id=user_id,
                                    TOEFL_r=TOEFLmoreR,
                                    TOEFL_l=TOEFLmoreL,
                                    TOEFL_s=TOEFLmoreS,
                                    TOEFL_w=TOEFLmoreW,
                                    GRE_v=GREmoreV,
                                    GRE_q=GREmoreQ,
                                    GRE_aw=GREmoreAW)
            elif request.form.get("SATmore[M]") is not None:
                sat_m = request.form.get("SATmore[M]", int)
                sat_cr = request.form.get("SATmore[CR]", int)
                sat_w = request.form.get("SATmore[W]", int)
                sub_sat = request.form.get("SATmore[total]", int)
                User.update_user_score(g.db,
                                       user_id=user_id,
                                       toefl=sub_TOEFL,
                                       sat=sub_sat)
                Score.set_user_info(connection=g.db,
                                    user_id=user_id,
                                    TOEFL_r=TOEFLmoreR,
                                    TOEFL_l=TOEFLmoreL,
                                    TOEFL_s=TOEFLmoreS,
                                    TOEFL_w=TOEFLmoreW,
                                    SAT_m=sat_m,
                                    SAT_w=sat_w,
                                    SAT_cr=sat_cr)
            else:
                GMATmoreV = request.form.get("GMATmore[V]", int)
                GMATmoreQ = request.form.get("GMATmore[Q]", int)
                GMATmoreAW = request.form.get("GMATmore[AW]", float)
                GMATmoreIR = request.form.get("GMATmore[IR]", int)
                sub_GMAT = request.form.get("GMATmore[total]", int)
                User.update_user_score(g.db,
                                       user_id=user_id,
                                       toefl=sub_TOEFL,
                                       GMAT=sub_GMAT)
                Score.set_user_info(connection=g.db,
                                    user_id=user_id,
                                    TOEFL_r=TOEFLmoreR,
                                    TOEFL_l=TOEFLmoreL,
                                    TOEFL_s=TOEFLmoreS,
                                    TOEFL_w=TOEFLmoreW,
                                    GMAT_v=GMATmoreV,
                                    GMAT_q=GMATmoreQ,
                                    GMAT_aw=GMATmoreAW,
                                    GMAT_ir=GMATmoreIR)
        User.set_user_active(g.db, user_id)

        Offer.set_user_offer_result(g.db, user_id)
        return jsonify(status="success")