def follow(self, user): from models.follow import Follow if self.id != user.id and self.is_following(user) == False and self.is_requesting(user) == False: follow = Follow(follower_id=self.id, followed_id=user.id) follow.save() else: return 0
def follow(username): idol_id = request.form.get('idol_id') f = Follow(fan=current_user.id, idol=idol_id) idol = User.get_by_id(idol_id) f.save() flash(f'You are now following {idol.username}', 'success') return redirect(url_for('users.show', username=idol.username))
def create_follow(fans_id): fan_id = fans_id idol_id = current_user.id follow = Follow(idol_id=idol_id, fan_id=fan_id) follow.save() request_delete = Requested.delete().where(Requested.idol_id == idol_id, Requested.fan_id == fan_id) request_delete.execute() return redirect(url_for('users.show', username=current_user.name))
def add(): u = current_user() if u: form = request.form print('ceuicec') f = Follow(form) f.fans = u f.save() else: message = '关注功能需要登录' return render_template('user_login.html', message=message)
def follow_route(request): """ Follow a card, unit, or set. """ # TODO-3 simplify this method. does some of this belong in the model? db_conn = request["db_conn"] current_user = get_current_user(request) if not current_user: return abort(401) follow_data = dict(**request["params"]) follow_data["user_id"] = current_user["id"] follow = Follow(follow_data) errors = follow.validate(db_conn) if errors: return 400, {"errors": errors, "ref": "4Qn9oWVWiGKvXSONQKHSy1T6"} follow, errors = follow.save(db_conn) if errors: return 400, {"errors": errors, "ref": "gKU6wgTItxpKyDs0eAlonCmi"} return 200, {"follow": follow.deliver(access="private")}
def fan(idol_id): identity = get_jwt_identity() fan = User.get(username=identity) idol = User.get_by_id(idol_id) if idol: if idol.is_private == True: follow = Follow(fan=fan, idol=idol, is_approve=False) if follow.save(): return jsonify({'message': 'success'}) else: return jsonify({'message': 'failed'}) else: follow = Follow(fan=fan, idol=idol, is_approve=True) if follow.save(): return jsonify({'message': 'success'}) else: return jsonify({'message': 'failed'}) else: return jsonify({'message': 'User Not Found'})
def follow(self, following): from models.follow import Follow if self.follow_status(following) == None: relationship = Follow(follower=self.id, following=following) if not following.private: relationship.is_approved = True return relationship.save() else: return 0
def follow_public(username): user = User.get_or_none(username=username) if user is not None: followship = Follow(followed_id=user.id, follower_id=current_user.id) if followship.save(): flash(f"You have successfully followed {user.username}!", 'success') return redirect(url_for('users.show', username=username)) else: flash("Follow failed!", 'danger') return render_template("users/profile.html")
def create(): idol_id = request.args.get('idol_id') f = {} f['fan_id'] = current_user.id f['idol_id'] = idol_id # status currently using default as defined in model follow = Follow(**f) if follow.save(): flash("You're now following this user", 'success') else: for error in follow.errors: flash(error, 'danger') return redirect(url_for('users.show', id=idol_id))
def follow(id): user = User.get_by_id(id) # new_follow_instance = Follow(follower_id=current_user.id, followed_user_id=user.id) # Need to swap new_follow_instance = Follow( follower_id=user.id, followed_user_id=current_user.id) # Need to swap if new_follow_instance.save(): flash("Follow request accepted successfully") return redirect(url_for('users.follow_request', username=current_user.name), code=307) else: flash("Something went wrong") return redirect(url_for('users.follow_request', username=current_user.name), code=307)
def follow_route(request): """ Follow a card, unit, or set. """ # TODO-3 simplify this method. does some of this belong in the model? current_user = get_current_user(request) if not current_user: return abort(401) follow_data = dict(**request['params']) follow_data['user_id'] = current_user['id'] follow = Follow(follow_data) errors = follow.validate() if errors: return 400, { 'errors': errors, 'ref': '4Qn9oWVWiGKvXSONQKHSy1T6' } # Ensure the entity exists TODO-3 should this be a model validation? if follow['entity']['kind'] == 'topic': entity = Topic.get(id=follow['entity']['id']) else: entity = get_latest_accepted(follow['entity']['kind'], follow['entity']['id']) if not entity: return abort(404) # Ensure we don't already follow TODO-3 should this be a model validation? prev = Follow.list(user_id=current_user['id'], entity_id=follow_data['entity']['id']) if prev: return abort(409) follow, errors = follow.save() if errors: return 400, { 'errors': errors, 'ref': 'gKU6wgTItxpKyDs0eAlonCmi', } return 200, {'follow': follow.deliver(access='private')}
def follow(username): user = User.get_or_none(username=username) pending = False if user is not None: if user.security == False: followship = Follow(followed_id=user.id, follower_id=current_user.id) if followship.save(): flash(f"You have successfully followed {user.username}!", 'success') return redirect(url_for('users.show', username=username)) else: flash("Follow failed!", 'danger') return render_template("users/profile.html") else: message = Mail( from_email='*****@*****.**', to_emails=user.email, subject=f"Follow request from {current_user.username}", html_content=render_template("users/follow_request.html", user=user, timestamp=timestamp)) try: sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY')) response = sg.send(message) print(response.status_code) print(response.body) print(response.headers) except Exception as e: print(str(e)) flash(f"Follow request sent to {user.username}!", 'primary') pending = True # return redirect(url_for('users.show', username = user.username, pending = pending)) return render_template('users/profile.html', user=user, pending=pending) else: flash('User not exist!', 'danger') return render_template('users/new.html')
def follow_route(request): """ Follow a card, unit, or set. """ # TODO-3 simplify this method. does some of this belong in the model? current_user = get_current_user(request) if not current_user: return abort(401) follow_data = dict(**request['params']) follow_data['user_id'] = current_user['id'] follow = Follow(follow_data) errors = follow.validate() if errors: return 400, {'errors': errors, 'ref': '4Qn9oWVWiGKvXSONQKHSy1T6'} # Ensure the entity exists TODO-3 should this be a model validation? if follow['entity']['kind'] == 'topic': entity = Topic.get(id=follow['entity']['id']) else: entity = get_latest_accepted(follow['entity']['kind'], follow['entity']['id']) if not entity: return abort(404) # Ensure we don't already follow TODO-3 should this be a model validation? prev = Follow.list(user_id=current_user['id'], entity_id=follow_data['entity']['id']) if prev: return abort(409) follow, errors = follow.save() if errors: return 400, { 'errors': errors, 'ref': 'gKU6wgTItxpKyDs0eAlonCmi', } return 200, {'follow': follow.deliver(access='private')}
def make_new_follow(follower_id, followed_id, the_secret): """ Make a new follower Return: if not valid user_id or no user found: error code: 8 if already exist: error code: 6 if success: return success code 200 else unknown error (code : 0) """ if request.method == 'POST': if the_secret != my_secret: unauto_dict = {} unauto_dict["error"] = "unauthorised request" unauto_dict["error_code"] = "1" return make_response(jsonify(unauto_dict), 401) response_dict = {} response_dict["error"] = "invalid parameter" response_dict["usage"] = "new_follow/<follower_id>/<followed_id>" response_dict["error_code"] = "8" try: uuid_obj = UUID(follower_id, version=4) uuid_obj = UUID(followed_id, version=4) except ValueError: return make_response(jsonify(response_dict), 202) user_1 = storage.get(User, follower_id) user_2 = storage.get(User, followed_id) if not user_1 or not user_2: return make_response(jsonify(response_dict), 202) if storage.get_by_two(Follow, follower_id, followed_id) is not None: al_exist = {} al_exist["error"] = "operation already exist" al_exist["usage"] = "new_follow/<follower_id>/<followed_id>" al_exist["error_code"] = "6" return make_response(jsonify(al_exist), 202) new_follow = Follow() new_follow.follower_id = follower_id new_follow.user_id = followed_id new_follow.follow_code = 1 new_follow.creation_date = datetime.utcnow() new_follow.save() new_notif = Notification() new_notif.reciver_user_id = followed_id new_notif.maker_user_id = follower_id new_notif.type = "follow" new_notif.follow_id = str(new_follow.id) new_notif.creation_date = datetime.utcnow() new_notif.save() succ = {} succ["status"] = "ok" return make_response(jsonify(succ), 200) unknown_dict = {} unknown_dict["error"] = "unknown error" unknown_dict["error_code"] = "0" return make_response(jsonify(unknown_dict), 404)