def create_friend(user, team): result = {"error_code":0, "msg":"ok"} if not team: return {"error_code":20501, "msg":"team not exist"} f_1 = Friend.select().where(Friend.user == user, Friend.team == team, Friend.ftype=="f").first() if f_1: if f_1.status != "normal": f_1.status = "normal" f_1.save() else: f_1 = Friend() f_1.user = user f_1.team = team f_1.ftype = "f" f_1.save() f_2 = Friend.select().where(Friend.user == user, Friend.team == team, Friend.ftype=="c").first() if f_2: if f_2.status != "normal": f_2.status = "normal" f_2.save() else: f_2 = Friend() f_2.user = user f_2.team = team f_2.ftype = "c" f_2.save() return result
def create_friend(user, team): result = {"error_code": 0, "msg": "ok"} if not team: return {"error_code": 20501, "msg": "team not exist"} f_1 = Friend.select().where(Friend.user == user, Friend.team == team, Friend.ftype == "f").first() if f_1: if f_1.status != "normal": f_1.status = "normal" f_1.save() else: f_1 = Friend() f_1.user = user f_1.team = team f_1.ftype = "f" f_1.save() f_2 = Friend.select().where(Friend.user == user, Friend.team == team, Friend.ftype == "c").first() if f_2: if f_2.status != "normal": f_2.status = "normal" f_2.save() else: f_2 = Friend() f_2.user = user f_2.team = team f_2.ftype = "c" f_2.save() return result
def new_friend(): current_user = User.get_by_id(get_jwt_identity()) approve_user = User.get_by_id(request.form.get("id")) friend = Friend(user1_id=current_user.id, user2_id=approve_user.id) if friend.save(): delete = FriendRequest.delete().where( FriendRequest.sender_id == approve_user.id, FriendRequest.recipient_id == current_user.id) delete.execute() return jsonify({ "successful": True, "message": "Friend request has been accepted!" }) else: return jsonify({"error": "Something went wrong!"})