def create(idol_id): idol = User.get_or_none(User.id == idol_id) if not idol: flash('No user found with this i!', 'warning') return redirect(url_for('home')) # if not current_user.is_authenticated: # ...we don't need this code, because it's handled by dcorator @login_required # flash('Please, login to continue', 'warning') # return redirect(url_for('sessions.new')) new_follow = FollowerFollowing(fan_id=current_user.id, idol_id=idol.id) if not idol.is_private: new_follow.approved = True for i in current_user.idols: if i.idol_id == idol.id: flash('You already follow that dude!', 'warning') return redirect(url_for('users.show', username=idol.username)) if not new_follow.save(): flash('Unable to follow this user!', 'danger') return redirect(url_for('users.show', username=idol.username)) if new_follow.is_approved: flash(f'You are now following {idol.username}', 'success') return redirect(url_for('users.show', username=idol.username)) flash('Follow request sent! Please, wait for pproval', 'success') return redirect(url_for('users.show', username=idol.username))
def create(idol_id): # use get_or_none in case there is no user id idol = User.get_or_none(User.id == idol_id) if not idol: flash('No user found with this id!') return redirect(url_for('home')) new_follow = FollowerFollowing(fan_id=current_user.id, idol_id=idol.id) # check if user is private or not. If user.private is False, then Follower.Following = True if not idol.is_private: new_follow.approved = True # assuming EVERYONE you are trying to follow is private if not new_follow.save(): flash('Unable to follow this user!') return redirect(url_for('users.show', username=idol.username)) # using hybrid property to change FollowerFollowing.approved to True if new_follow.is_approved: flash(f'You are now following {idol.username}') return redirect(url_for('users.show', username=idol.username)) flash('Follow request sent! Please wait for approval!') return redirect(url_for('users.show', username=idol.username))
def create(idol_id): idol = User.get_or_none(User.id == idol_id) fan = current_user.id follow = FollowerFollowing(fan=fan, idol=idol.id) if not follow.save(): flash("Can't follow this user, try again", 'warning') return redirect(url_for('users.show', username=idol.name)) flash('You followed this user', 'success') return redirect(url_for('users.show', username=idol.name))
def delete(idol_id): follow = FollowerFollowing.get_or_none( (FollowerFollowing.idol_id == idol_id) and (FollowerFollowing.fan_id == current_user.id)) if follow.delete_instance(): flash(f'You have unfollowed {follow.idol.username}') return redirect(url_for('users.show', username=follow.idol.username))
def edit(fan): fans = User.get_or_none(User.name == fan) approve = FollowerFollowing.get_or_none( (FollowerFollowing.idol_id == current_user.id) & (FollowerFollowing.fan_id == fans.id)) approve.request = True approve.save() return redirect( url_for('followerfollowing.new', username=current_user.name))
def is_following(self, idol): from models.followerfollowing import FollowerFollowing return FollowerFollowing.get_or_none( (FollowerFollowing.idol_id == idol.id) & (FollowerFollowing.fan_id == self.id)) # class Images(BaseModel): # user = pw.ForeignKeyField(User, backref='images') # URL = pw.CharField(null=False) # caption = pw.CharField(null=True, default=None) # likes = pw.IntegerField(default=0) # donation = pw.IntegerField(default=0)
def delete(idol_id): idol = User.get_or_none(User.id == idol_id) unfollow = FollowerFollowing.get_or_none( (FollowerFollowing.idol_id == idol_id) & (FollowerFollowing.fan_id == current_user.id)) if not unfollow.delete_instance(): flash(f'Unable to unfollow {idol.username}', 'warning') return redirect(url_for('users.show', username=idol.username)) flash(f'You unfollowed {idol.username}', 'warning') return redirect(url_for('users.show', username=idol.username))
def delete(idol_id): idol = User.get_or_none(User.id == idol_id) unfollow = FollowerFollowing.get_or_none( (FollowerFollowing.idol_id == idol.id) & (FollowerFollowing.fan_id == current_user.id)) if not unfollow: flash("You can't do dis", 'warning') return redirect(url_for('users.show', username=idol.name)) if not unfollow.delete_instance(): flash("Can't unfollow this user, try again", 'warning') return redirect(url_for('users.show', username=idol.name)) flash('You unfollowed this user', 'success') return redirect(url_for('users.show', username=idol.name))
def new(username): idol = User.get_or_none(User.name == username) requests = FollowerFollowing.select().where( FollowerFollowing.idol_id == idol) return render_template('/followerfollowing/new.html', requests=requests)
def show(username): from models.followerfollowing import FollowerFollowing user = User.get_or_none(User.name == username) follower = FollowerFollowing.select().where((FollowerFollowing.request == True) & (FollowerFollowing.idol_id == user.id)) following = FollowerFollowing.select().where((FollowerFollowing.request == True) & (FollowerFollowing.fan_id == user.id)) return render_template('users/users.html', user=user, follower = follower, following = following)