def follow(self, idol): from models.fan_idol import FanIdol if self.follow_status(idol) == None: new_relationship = FanIdol(fan=self.id, idol=idol.id) if idol.is_private == False: new_relationship.is_approved = True return new_relationship.save() else: return 0
def follow(self, idol): from models.fan_idol import FanIdol # check whether current user follow idol before # relationship = FanIdol.get_or_none(fan=self.id, idol=idol.id) if self.follow_status(idol) == None: new_rel = FanIdol(fan=self.id, idol=idol.id) if idol.is_private == False: # public idol new_rel.is_approved = True return new_rel.save() else: return 0
def follow(self,idol): #check existing relationship in fanidol table from models.fan_idol import FanIdol # relationship = FanIdol.get_or_none(fan=self.id, idol = idol.id) if self.follow_status(idol) == None: new_rel = FanIdol(fan=self.id, idol = idol.id) if idol.is_private == False: #public idol new_rel.is_approved = True return new_rel.save() else: return 0
def create(idol_id): #people to follow you in instagram from db idol = User.get_or_none( User.id == idol_id) #this will take bring me the rows from db new_follower = FanIdol(fan_id=current_user.id, idol_id=idol.id) #new follower is creating me the fan_id and idol_id from me in db new_follower.save() #this will help us save flash(f"You are now following {idol.name}") return redirect(url_for('users.show', id=idol.id))
def create(idol_id): idol = User.get_or_none( User.id == idol_id) #this is to get everything from row from database new_follower = FanIdol( #this is to create a new follower which takes in fan_id and idol_id (refer back to db) fan_id=current_user.id, idol_id=idol.id) new_follower.save() flash(f"You are now following {idol.name}") return redirect( url_for('users.show', username=idol.username) ) #this need to refer back to users.show parameter, because it pass in username then here have to pass it into here
def fans(self): # return a list of fan user instances that only approved from models.fan_idol import FanIdol fans_id = FanIdol.select(FanIdol.fan).where( FanIdol.idol == self.id, FanIdol.is_approved == True) fans = User.select().where(User.id.in_(fans_id)) return fans
def idols(self): # return a list of idol user instances that only approved from models.fan_idol import FanIdol idols_id = FanIdol.select(FanIdol.idol).where( FanIdol.fan == self.id, FanIdol.is_approved == True) idols = User.select().where(User.id.in_(idols_id)) return idols
def unfollow(id): unfollow_user = FanIdol.delete().where(FanIdol.fan_id == current_user.id and FanIdol.idol_id == id) unfollow_user.execute() user = User.get_by_id(id) flash(f'You are no longer following {user.username}.', 'danger') return redirect(url_for('users.show', username=user.username))
def image_feed(self): from models.fan_idol import FanIdol from models.image import Image approved_idols_id = FanIdol.select(FanIdol.idol).where( FanIdol.fan == self.id, FanIdol.is_approved == True) return Image.select().where( Image.user.in_(approved_idols_id)).order_by( Image.created_at.desc())
def unfollow(idol_id): idol = User.get_or_none(User.id == idol_id) relationship = FanIdol.get(FanIdol.idol == idol.id, FanIdol.fan == current_user.id) relationship.delete_instance() flash(f"Unfollowed {idol.name}") return redirect(url_for('users.show', id=idol.id))
def show(username): if not current_user.is_authenticated: flash("You are not logged in", "info") return redirect(url_for('sessions.new')) else: user = User.get(User.username == username) approved = FanIdol.get_or_none(FanIdol.fan == current_user.id, FanIdol.idol == user.id, FanIdol.approved == True) return render_template('users/show.html', user=user, approved=approved)
def image_feed(self): from models.fan_idol import FanIdol from models.image import Image approved_idols_id = FanIdol.select(FanIdol.idol).where( FanIdol.fan == self.id, FanIdol.is_approved == True) idols_with_me = [x.idol for x in approved_idols_id ] # return a list of idols' id idols_with_me.append(self.id) # add your own id return Image.select().where(Image.user.in_(idols_with_me)).order_by( Image.created_at.desc())
def unfollow(idol_id): idol = User.get_or_none(User.id == idol_id) relationship = FanIdol.get(FanIdol.idol == idol.id, FanIdol.fan == current_user.id) #this will help me wrap and get FanIdol (where, select your FanIdol.idol (from db) is equal to idol.id (from this funtion), select your FanIdol.fan (from db) comapre with current_user.id (from function)) #this line 2 conditions need to be wrap it relationship.delete_instance( ) # (using previous variable) delete using delete_instance() then save flash(f"You are now unfollow {idol.name}") return redirect(url_for('users.show', username=idol.username))
def user_unfollow(id): user = User.get_by_id(id) idol = FanIdol.get(FanIdol.idol == user.id, FanIdol.fan == current_user.id) if current_user.unfollow(user): if idol.is_approved: flash ("Successfully unfollowed","success") return redirect(url_for("users.show",username = user.username)) else : flash ("Request cancelled","success") return redirect(url_for("users.show",username = user.username)) else : flash ("Something went wrong. Try again.", "danger") return redirect(url_for("users.show",username = user.username))
def idols(self): from models.fan_idol import FanIdol idols_id = FanIdol.select(FanIdol.idol).where( FanIdol.fan == self.id, FanIdol.is_approved == True) idols = User.select().where(User.id.in_(idols_id)) return idols
def follow(id): fan_idol = FanIdol(fan_id=current_user.id, idol_id=id) fan_idol.save() user = User.get_by_id(id) flash('Thank you for following.', 'success') return redirect(url_for('users.show', username=user.username))
def show(username): user = User.get(User.username == username) images = Image.select(Image, User).join(User).where(Image.user_id == user.id) idol = FanIdol.get_or_none(FanIdol.idol == user.id, FanIdol.fan == current_user.id) return render_template('users/show.html',name=user.name, user = user, images = images, idol = idol)
def approve(self, fan): from models.fan_idol import FanIdol relationship = FanIdol.get_or_none(idol = self.id, fan=fan.id) relationship.is_approved = True return relationship.save()
def fan_requests(self): from models.fan_idol import FanIdol fans_id = FanIdol.select(FanIdol.fan).where(FanIdol.idol== self.id, FanIdol.is_approved==False) return User.select().where(User.id.in_(fans_id))
def follow_status(self,idol): from models.fan_idol import FanIdol return FanIdol.get_or_none(fan=self.id,idol=idol.id)
def unfollow(self,idol): from models.fan_idol import FanIdol return FanIdol.delete().where(FanIdol.idol == idol.id, FanIdol.fan == self.id).execute()
def fans(self): from models.fan_idol import FanIdol fans_id = FanIdol.select(FanIdol.fan).where( FanIdol.idol == self.id, FanIdol.is_approved == True) fans = User.select().where(User.id.in_(fans_id)) return fans
def idol_requests(self): from models.fan_idol import FanIdol idols_id = FanIdol.select(FanIdol.idol).where( FanIdol.fan == self.id, FanIdol.is_approved == False) return User.select().where(User.id.in_(idols_id)).order_by( User.created_at.desc())