def following(self): from models.follows import Follows return [ x.idol for x in Follows.select().where((Follows.fan_id == self.id) & (Follows.is_approved == True)) ]
def follower_request(self): from models.follows import Follows return [ x.fan for x in Follows.select().where((Follows.idol_id == self.id) & (Follows.is_approved == False)) ]
def unfollow(id): i = Follows.delete().where((Follows.idol_id == id) & (current_user.id == Follows.fan_id)) private_container = render_template('private-container.html') followers = Follows.select().where(Follows.idol_id == id).count() user = User.get_by_id(id) if i.execute(): if user.status == "Public": return jsonify({ 'success': True, 'followers': int(followers) - 1, 'status': True }) else: return jsonify({ 'success': True, 'followers': int(followers) - 1, 'status': False, 'private_container': private_container })
def post(self, token_data, data): if not Courses.query.filter_by(id=data['id']).first(): abort(403, "Invalid Parametres (No such course)") elif Follows.query.filter_by(userid=token_data['id'], courseid=data['id']).first(): abort(403, "Invalid Parametres (Already following this course)") following = Follows(userid=token_data['id'], courseid=data['id']) db.session.add(following) db.session.commit() return jsonify({"message": "Success"})
def follow(id): idol = User.get_by_id(id) if idol.status == "Public": i = Follows(idol_id=id, fan_id=current_user.id, is_approved=True) else: i = Follows(idol_id=id, fan_id=current_user.id, is_approved=False) message = Mail(from_email='*****@*****.**', to_emails=idol.email, subject='Following Request Notification', html_content='@' + current_user.username + ' wants to follow you.') 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)) followers = Follows.select().where(Follows.idol_id == id).count() if i.save(): if i.is_approved == False: return jsonify({ 'success': True, 'pending': True, }) elif i.is_approved == True: return jsonify({ 'success': True, 'pending': False, 'username': idol.username, 'followers': int(followers) + 1 })
def follow(username): # Get the user that the current_user wants to follow idol = User.get_or_none(User.username == username) # If the user does not exist if not idol: flash("This user does not exist") return redirect(url_for('home')) # Check that the current_user is not already following the user check_follow = Follows.get_or_none( (Follows.idol_id == idol.id) & (Follows.fan_id == current_user.id)) if check_follow: flash('You are already following this user.') return redirect(url_for('show', username=idol.username)) # Follow the user new_follow = Follows( idol=idol.id, fan=current_user.id, is_approved=True) new_follow.save() if new_follow.save(): return redirect(url_for('show', username=idol.username))
def reject_requests(id): rejected = Follows.delete().where((Follows.fan_id == id) & (Follows.idol_id == current_user.id)) if rejected.execute(): return redirect(url_for('following.follower_request'))
def approve_requests(id): approved = Follows.update( is_approved=True).where((Follows.fan_id == id) & (Follows.idol_id == current_user.id)) if approved.execute(): return redirect(url_for('following.follower_request'))