def test_user_update(self): old_major = Major.objects().create(name="Test_Name", kd_org="Test_KD_ORG") user = User.objects().create(name="John", username="******", npm="12345678", batch="2020", major=old_major) user.name = "Smith" user.username = "******" user.npm = "0123" user.batch = "123" new_major = Major.objects().create(name="New_Major", kd_org="New_KD_ORG") user.major = new_major user.save() user.reload() assert user.name == "Smith" assert user.username == "wock" assert user.npm == "0123" assert user.batch == "123" assert user.major == new_major user.delete() new_major.delete() old_major.delete()
def search_major(): u"""专业搜索""" if request.method == "GET": major_list = [] major = {} user_id = session.get("user_id") user = User.get_user_info(g.db, user_id) major_type = None if user: major_type = user.type searchname, university_id = map(request.args.get, ("searchname", "universityid")) if university_id is None: for row in Major.search_maior(g.db, searchname): major["name"] = row.name major["chiname"] = row.chiname major["id"] = row.id major_list.append(major) major = {} return jsonify(namelist=major_list, status="success") else: for row in Major.search_maior(g.db, searchname, university_id, major_type): major["name"] = row.name major["chiname"] = row.chiname major["id"] = row.id major_list.append(major) major = {} return jsonify(namelist=major_list, status="success")
def process_sso_profile(sso_profile): period_name = app.config["ACTIVE_PERIOD"] user_npm = sso_profile["attributes"]["npm"] major_name = sso_profile["attributes"]["study_program"] major_kd_org = sso_profile["attributes"]["kd_org"] major = Major.objects(kd_org=major_kd_org).first() if major is None: major = Major(name=major_name, kd_org=major_kd_org) major.save() period_detail = Period.objects( major_id=major.id, name=period_name, is_detail=True).first() period_not_detail = Period.objects( major_id=major.id, name=period_name, is_detail=False).first() if period_detail is None: if period_not_detail is None: courses, is_detail = scrape_courses(major_kd_org, period_name) if not courses: result = { "err": True, "major_name": major_name } return result else: courses, is_detail = scrape_courses( major_kd_org, period_name, skip_not_detail=True) if courses: period = Period( major_id=major.id, name=period_name, courses=courses, is_detail=is_detail ) period.save() user = User.objects(npm=user_npm).first() if user is None: user = User( name=sso_profile["attributes"]["ldap_cn"], username=sso_profile["username"], npm=user_npm, batch=f"20{user_npm[:2]}", major=major, ) user.save() token = generate_token(user.id, user.major.id) result = { "user_id": str(user.id), "major_id": str(user.major.id), "token": token } return result
def process_sso_auth(cls, sso_profile) -> Tuple[dict, int]: user_name = sso_profile["username"] period_name = get_app_config("ACTIVE_PERIOD") user = User.objects(username=user_name).first() if user is None: full_name = sso_profile['attributes']['ldap_cn'] user = User(name=full_name, username=user_name) try: user_npm = sso_profile["attributes"]["npm"] major_name = sso_profile["attributes"]["study_program"] major_kd_org = sso_profile["attributes"]["kd_org"] except KeyError: completion_id = uuid.uuid4() user.completion_id = completion_id user.save() return { 'user_name': user_name, 'full_name': full_name, 'completion_id': str(completion_id) }, 201 user.npm = user_npm user.batch = f"20{user_npm[:2]}" major = Major.objects(kd_org=major_kd_org).first() if major is None: major = Major(name=major_name, kd_org=major_kd_org) major.save() user.major = major user.save() if user.completion_id is not None: return { 'user_name': user.username, 'full_name': user.name, 'completion_id': str(user.completion_id) }, 201 major = user.major period = Period.objects(major_id=major.id, name=period_name, is_detail=True).first() token = generate_token(user.id, user.major.id) result = { "user_id": str(user.id), "major_id": str(user.major.id), "token": token } if period is None: result = {**result, "err": True, "major_name": major.name} return result, 200
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)
def test_major_deletion(self): major = Major.objects().create(name="Test_Name", kd_org="Test_KD_ORG") assert len(Major.objects) == 1 assert major in Major.objects major.delete() assert len(Major.objects) == 0 assert major not in Major.objects
def generate_random_user_item(cls): return User( name=cls.get_random_string(255), username=cls.get_random_string(64), npm=cls.get_random_string(20), batch=cls.get_random_string(5), major=Major.objects().create( name=cls.get_random_string(256), kd_org=cls.get_random_string(16), ), )
def create_test_user(): major = Major.objects().create(name='Ilmu Komputer (Computer Science)', kd_org='01.00.12.01') user = User.objects().create( name='NAMA USER', username='******', npm='1701234567', batch='2017', major=major, ) token = generate_token(user.id, user.major.id) return user, token
def test_major_creation(self): major = Major.objects().create(name="Test_Name", kd_org="Test_KD_ORG") majors = Major.objects assert len(majors) == 1 assert major in majors fetched_major = majors().first() assert fetched_major.name == "Test_Name" assert fetched_major.kd_org == "Test_KD_ORG" major.delete()
def get_mobile_search_major(): """专业搜索""" if request.method == "GET": major_list = [] major = {} user_id = session.get("user_id") user = User.get_user_info(g.db, user_id) major_type = None if user: major_type = user.type searchname, university_id, grade = map( request.args.get, ("searchname", "universityid", "grade")) print request.args if university_id is None: for row in Major.search_maior(g.db, searchname): major["name"] = row.name major["chiname"] = row.chiname major["id"] = row.id major_list.append(major) major = {} major_json = {"namelist": major_list} major_json["status"] = "success" return json.dumps(major_json) else: if searchname is None: searchname = "" for row in Major.search_maior(g.db, searchname, university_id, grade): major["name"] = row.name major["chiname"] = row.chiname major["id"] = row.id major_list.append(major) major = {} major_json = {"namelist": major_list} major_json["status"] = "success" return json.dumps(major_json)
def test_user_fields_validation(self): major = Major.objects().create(name="Name", kd_org="KD_ORG") test_cases = [ { "name": "A" * 300, "username": "******", "npm": "123", "batch": "123", "major": major, }, { "name": "A" * 300, "username": "******" * 100, "npm": "123", "batch": "123", "major": major, }, { "name": "A" * 300, "username": "******" * 100, "npm": "A" * 30, "batch": "123", "major": major, }, { "name": "A" * 300, "username": "******" * 100, "npm": "A" * 30, "batch": "A" * 10, "major": major, }, { "name": "A" * 300, "username": "******" * 100, "npm": "A" * 30, "batch": "A" * 10, "major": 1, }, ] for case in test_cases: with pytest.raises(ValidationError): User( name=case["name"], username=case["username"], npm=case["npm"], batch=case["batch"], major=case["major"], ).validate()
def test_major_fields_with_invalid_values(self): field_values = [ {"name": "A" * 257, "kd_org": ""}, {"name": "A" * 257, "kd_org": "KD_ORG"}, {"name": "A" * 257, "kd_org": "B" * 17}, {"name": "A" * 257, "kd_org": "B" * 20}, {"name": "A" * 300, "kd_org": ""}, {"name": "A" * 300, "kd_org": "KD_ORG"}, {"name": "A" * 300, "kd_org": "B" * 17}, {"name": "A" * 300, "kd_org": "B" * 20}, ] for values in field_values: with pytest.raises(ValidationError): Major(name=values["name"], kd_org=values["kd_org"]).validate()
def process_auth_completion(cls, data: AuthCompletionData) -> dict: user = User.objects(completion_id=data.completion_id).first() period_name = get_app_config("ACTIVE_PERIOD") if user is None: raise UserNotFound() base_kd_org_data = get_app_config("BASE_KD_ORG") try: kd_org_data = base_kd_org_data[data.kd_org] except KeyError: raise KdOrgNotFound() major = Major.objects(kd_org=data.kd_org).first() if major is None: major = Major(name=kd_org_data["study_program"], kd_org=data.kd_org) major.save() user.npm = data.npm user.major = major user.completion_id = None user.batch = f"20{data.npm[:2]}" user.save() period = Period.objects(major_id=major.id, name=period_name, is_detail=True).first() token = generate_token(user.id, user.major.id) result = { "user_id": str(user.id), "major_id": str(major.id), "token": token } if period is None: result = {**result, "err": True, "major_name": major.name} return result
def test_user_deletion(self): user = User.objects().create( name="John", username="******", npm="12345678", batch="2020", major=Major.objects().create(name="Test_Name", kd_org="Test_KD_ORG"), ) assert len(User.objects) == 1 assert user in User.objects user.delete() assert len(User.objects) == 0 assert user not in User.objects
def test_user_creation(self): major = Major.objects().create(name="Test_Name", kd_org="Test_KD_ORG") User.objects().create(name="John", username="******", npm="12345678", batch="2020", major=major) users = User.objects assert len(users) == 1 fetched_user = users.first() assert fetched_user.name == "John" assert fetched_user.username == "wick" assert fetched_user.npm == "12345678" assert fetched_user.batch == "2020" assert fetched_user.major == major fetched_user.delete() major.delete()
def upload(profile): if request.method == "POST": if "file" not in request.files: flash("File error.") return redirect(url_for_custom("router_uploader.upload")) file_ = request.files["file"] if file_.filename == "": flash("File kosong.") return redirect(url_for_custom("router_uploader.upload")) if file_ and allowed_file(file_.filename): if not os.path.isdir(app.config["UPLOAD_FOLDER"]): os.mkdir(app.config["UPLOAD_FOLDER"]) html = file_.read() period, kd_org = get_period_and_kd_org(html) role = check_uploader(profile["npm"]) if (period == app.config["ACTIVE_PERIOD"]) and ( kd_org == profile["kd_org"] or role == "admin"): courses = create_courses(html, is_detail=True) if not courses: flash("Error, hubungi admin. Sertakan file ini.") return redirect(url_for_custom("router_uploader.upload")) major = Major.objects(kd_org=kd_org).first() if major is None: flash("Login susun jadwal beneran dulu ya.") return redirect(url_for_custom("router_uploader.upload")) instance = Period.objects(major_id=major.id, name=period, is_detail=True).first() if instance: instance.courses = courses else: instance = Period(major_id=major.id, name=period, courses=courses, is_detail=True) instance.save() timestamp = int(time.time()) filename = f"{kd_org}_{timestamp}_{secure_filename(file_.filename)}" file_.save(os.path.join(app.config["UPLOAD_FOLDER"], filename)) else: flash("Periode salah atau jurusan tidak sesuai.") return redirect(url_for_custom("router_uploader.upload")) flash("Berhasil..!!") return redirect(url_for_custom("router_uploader.upload")) flash("Gagal. File salah atau hubungi admin.") return redirect(url_for_custom("router_uploader.upload")) return render_template("upload.html", profile=profile)
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)
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)
def generate_random_major_item(cls): return Major( name=cls.get_random_string(256), kd_org=cls.get_random_string(16), )
def get_user_detail_info(): if request.method == "GET": student_id = request.args.get("studentid", 0, int) student_info = dict() offers = list() login_user_id = session.get("user_id") user_info = User.get_user_info(g.db, student_id) if login_user_id is None: login_user_id = -1 for row in Offer.get_offer_student_info(g.db, student_id): offer_info = dict() for row_un in University.get_university_info( g.db, str(row.university_id)): offer_info["universityname"] = row_un.name offer_info["universityid"] = row_un.id offer_info["logo"] = get_university_logo(row_un.name) offer_info["twodimcode"] = row.wechat for row_ma in Major.get_major_info_by_id(g.db, row.major_id): offer_info["majorname"] = row_ma.name offer_info["grade"] = row.grade offer_info["offertype"] = row.offer_type if row.scholarship is not None: offer_info["scholarship"] = \ str(row.scholarship) + row.scholarship_type # offer_info["scholarship"] = None offers.append(offer_info) student_info["offers"] = offers compares = [] compares_info = {} for row_co in Compare.get_compare_user_id(g.db, student_id): compares_info["compareid"] = row_co.id compareslist = list() compares_un = {} for row_ci in CompareInfo.get_compare_info(g.db, row_co.id): for row_un in University.get_university_info( g.db, row_ci.university_id): compares_un["universityname"] = row_un.name compares_un["universityid"] = row_un.id compares_un["logo"] = row_un.schoollogo for row_ma in CompareInfo.get_compare_info( g.db, row_ci.major_id): compares_un["majorname"] = row_ma.name compares_un["supportnum"] = row_ci.supportnum compares_un["offernum"] = Offer.get_offer_num( g.db, row_ci.university_id) compareslist.append(compares_un) compares_un = {} compares_info["comparelist"] = compareslist compares.append(compares_info) student_info["compares"] = compares user = User.get_user_info(g.db, student_id) student_info["fannum"] = UserFollow.get_follow_count_user( g.db, student_id) if user is None: student_info["description"] = "" student_info["bginf"] = "" else: student_info["description"] = user.description student_info["bginf"] = user.bginf if int(login_user_id) == int(student_id): student_info["self"] = "true" student_info["phone"] = user.phone student_info["email"] = user.email else: student_info["self"] = "false" student_info["phone"] = "" student_info["email"] = "" message = list() for row_meg in Message.get_message_user(g.db, student_id): message_dict = dict() message_dict["messageid"] = row_meg.id user_id = row_meg.user_id user = User.get_user_info(g.db, user_id) if user is None: message.append(message_dict) else: message_dict["pic"] = user.pic message_dict["name"] = user.username message_dict["studentid"] = user_id message_dict["content"] = row_meg.message message_dict["time"] = get_timestamp(row_meg.create_time) message.append(message_dict) student_info["messages"] = message u"""这个位置的关注状态逻辑有点奇葩,以后要多注意""" follow_status = UserFollow.get_follow_to_user(g.db, login_user_id, student_id) if follow_status is not None: student_info["followed"] = "true" else: student_info["followed"] = "false" follows_list = list() for row_follow in UserFollow.get_follow_id(g.db, student_id): follows = dict() follow_user_id = row_follow.follow_user_id user = User.get_user_info(g.db, follow_user_id) if user is None: follows_list.append(follows) else: follows["name"] = user.username follows["pic"] = user.pic follows["studentid"] = follow_user_id follows_list.append(follows) student_info["follows"] = follows_list student_info["status"] = "success" score = Score.get_user_score(g.db, student_id) coupons = dict() print user_info.account, user.active, if user_info.active == 1 and (user_info.account != 0 and user_info.account is not None): coupons["code"] = user_info.coupon coupons["account"] = user_info.account student_info["coupons"] = coupons elif user_info.active == 2 and (user_info.account != 0 and user_info.account is not None): coupons["code"] = None coupons["account"] = user_info.account student_info["coupons"] = coupons elif user_info.active == 1 and (user_info.account != 0 and user_info.account is not None ) and user_info.coupon is None: coupons["code"] = "not_coupons" coupons["account"] = user_info.account student_info["coupons"] = coupons if score is None: return jsonify(student_info) sub_list = list() for row in Stasub.get_sub(g.db, student_id): sub = dict() sub["id"] = row.id sub["grade"] = row.grade sub_list.append(sub) GREmore = dict() GREmore["sub"] = sub_list GREmore["V"] = score.GRE_v GREmore["Q"] = score.GRE_q GREmore["AW"] = score.GRE_aw GREmore["total"] = user_info.GRE if GREmore.get("total") not in (0, None): student_info["GREmore"] = GREmore IELTSmore = dict() IELTSmore["R"] = score.IELTS_r IELTSmore["L"] = score.IELTS_l IELTSmore["S"] = score.IELTS_s IELTSmore["W"] = score.IELTS_w IELTSmore["total"] = user_info.IELTS if IELTSmore.get("total") not in (0, None): student_info["IELTSmore"] = IELTSmore TOEFLmore = dict() TOEFLmore["R"] = score.TOEFL_r TOEFLmore["L"] = score.TOEFL_l TOEFLmore["S"] = score.TOEFL_s TOEFLmore["W"] = score.TOEFL_w TOEFLmore["total"] = user_info.TOEFL if TOEFLmore.get("total") not in (0, None): student_info["TOEFLmore"] = TOEFLmore SATmore = dict() SATmore["CR"] = score.SAT_cr SATmore["W"] = score.SAT_w SATmore["M"] = score.SAT_m SATmore["total"] = user_info.SAT if SATmore.get("total") not in (0, None): student_info["SATmore"] = SATmore GMATmore = dict() GMATmore["V"] = score.GMAT_v GMATmore["Q"] = score.GMAT_q GMATmore["AW"] = score.GMAT_aw GMATmore["IR"] = score.GMAT_ir GMATmore["total"] = user_info.GMAT if GMATmore.get("V") not in (0, None): student_info["GMATmore"] = GMATmore return json.dumps(student_info)
def 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")
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 })