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 on_success(self, data): event_type = "untracked" if data.get('direct_message'): event_type = "Direct Message" dm = DirectMessage(data) self.on_direct_message(dm) elif data.get('event') and data['event'] == 'follow': event_type = "Follow" follow = Follow(data) self.on_follow(follow) elif data.get('text'): event_type = "Status" status = Status(data) # ignore RTs for now if status.type is 'retweet': event_type = "{0} -- Retweet".format(event_type) else: # if it's a reply, handle as such # otherwise, for now, do nothing. if status.reply_to_user(): event_type = "{0} -- Reply".format(event_type) self.on_reply(status) print "{0} data received. Type: {1}".format(self.__class__.__name__, event_type) print data
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 follow(self, user): follow = Follow.query.filter_by(followed_id=user.id, follower_id=self.id).first() if follow: follow.update(enable=True) else: follow = Follow(follower_id=self.id, followed_id=user.id) db.session.add(follow) db.session.commit()
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 follow_user(self, identifier, active): current_user = self.current_user user = self._get_user(identifier) row_follow = Follow(user_id=current_user.user_id, follow_id=user.user_id, active=active) db_session.merge(row_follow) db_session.commit() return self._get_user(identifier)
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 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_user(user=None): """ Follow or unfollow """ payload = request.get_json() uuid = payload["id"] existing_follow = Follow.query.filter(Follow.follower_id == user['id'], Follow.user_id == uuid).first() if existing_follow: existing_follow.active = False if existing_follow.active else True else: db.session.add( Follow(follower_id=user['id'], user_id=uuid, active=True)) db.session.commit() return "success"
def post(self, user_id): user = users.get_current_user() o_user = User.get_by_id(int(user_id)) u_email = user.email() o_email = o_user.email follow_user = self.request.get("follow") if follow_user == "follow": follow = Follow(user_id=u_email, following_id=o_email) follow.put() return self.redirect('/other/' + str(user_id)) else: following = Follow.query(Follow.user_id == u_email, Follow.following_id == o_email).get() following.key.delete() return self.redirect('/other/' + str(user_id))
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 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)