def approve(fan_username): fan = User.get_or_none(User.username == fan_username) inputbutton = request.form.get("inputbutton") print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxdxx") print(inputbutton) if inputbutton == "approve": fanidol = FanIdol.get_or_none(FanIdol.fan == fan) fanidol.approved = True fanidol.save() else: print(fan.username) fanidol = FanIdol.get_or_none(FanIdol.fan == fan) print("XOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXOXO") fanidol.blocked = True fanidol.save() return redirect(url_for('users.blockeduser')) # current_user.approve(fan.id) # print("333333333333333333333333333333333333333333333333333333333333333333") return redirect( url_for('users.fan_requests', username=current_user.username))
def follow(self, idol): from models.fanidol import FanIdol if self.follow_status(idol) == None: relationship = FanIdol(idol=idol, fan=self.id) if not idol.is_private: relationship.is_approved = True return relationship.save() else: return 0
def follow(self, idol): from models.fanidol import FanIdol # if relationship/row exists, return false if FanIdol.get_or_none(FanIdol.fan == self.id, FanIdol.idol == idol.id): return False else: if idol.is_private: FanIdol.create(fan=self.id, idol=idol.id, is_approved=False) else: FanIdol.create(fan=self.id, idol=idol.id, is_approved=True) return True
def follow(id): for fanidolrow in current_user.idol: print(type(fanidolrow.idol)) print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print(type(fanidolrow.idol_id)) print(type(current_user)) print(User) fanidol = FanIdol(fan=current_user.id, idol=id) fanidol.save() return "LALALA"
def show(username): user = User.get_or_none(User.username == username) if user: followed = FanIdol.get_or_none(FanIdol.fan==current_user.id,FanIdol.idol==user.id) approved = FanIdol.get_or_none(FanIdol.fan==current_user.id,FanIdol.idol==user.id,FanIdol.approved==True) images = Image.select().where(Image.user==user.id,Image.gallery==True).order_by(Image.created_at.desc()).limit(6) profile_images = Image.select().where(Image.user==user.id,Image.gallery==False).order_by(Image.created_at.desc()).limit(6) ttl_images = Image.select().where(Image.user==user.id) ttlfans = len(user.fans) ttlidols = len(user.idols) ttl = len(ttl_images) followers = FanIdol.select().where(FanIdol.idol==current_user.id ,FanIdol.approved==False) idols = FanIdol.select().where(FanIdol.fan==current_user.id, FanIdol.approved==False) return render_template('users/show.html',followers=followers,idols=idols,followed=followed,approved=approved,user=user,images=images,profile_images=profile_images,ttl=ttl,ttlfans=ttlfans,ttlidols=ttlidols) return render_template('404.html'), 404
def approve(self, fan_id): from models.fanidol import FanIdol fanidol = FanIdol.get_or_none(FanIdol.idol == self.id, FanIdol.fan == int(fan_id)) fanidol.approved = True fanidol.save()
def pending_idols(self): from models.fanidol import FanIdol pending_idols = FanIdol.select(FanIdol.idol).where( FanIdol.fan == self.id, FanIdol.approved == False) return User.select().where(User.id.in_(pending_idols))
def fan_requests(self): from models.fanidol import FanIdol fan_requests = FanIdol.select(FanIdol.fan).where( FanIdol.idol == self.id, FanIdol.approved == False, FanIdol.blocked == False) return User.select().where(User.id.in_(fan_requests))
def my_idols(self): from models.fanidol import FanIdol idols = FanIdol.select(FanIdol.idol).where(FanIdol.fan == self.id, FanIdol.approved == True) return User.select().where(User.id.in_(idols)).order_by( User.username.asc())
def unfollow(self, idol_id): from models.fanidol import FanIdol fanidol = FanIdol.get_or_none(FanIdol.idol_id == int(idol_id), FanIdol.fan == self.id) fanidol.delete_instance()
def follow(self,idol): from models.fanidol import FanIdol # check if has relationship in database if self.follow_status(idol)==None: return FanIdol(fan=self.id,idol=idol.id).save() else: return 0
def blocked(self): from models.fanidol import FanIdol fanidol = FanIdol.select(FanIdol.fan).where(FanIdol.idol == self.id, FanIdol.blocked == True) return User.select().where(User.id.in_(fanidol))
def my_fans(self): from models.fanidol import FanIdol fans = FanIdol.select(FanIdol.fan).where(FanIdol.idol == self.id, FanIdol.approved == True, FanIdol.blocked == False) return User.select().where(User.id.in_(fans)).order_by( User.username.asc())
def fans(self): from models.fanidol import FanIdol fans = FanIdol.select().where(FanIdol.idol == self.id, FanIdol.is_approved == True) fans_list = [] for fan in fans: fans_list.append(fan.fan) return fans_list
def index(): if current_user.is_authenticated: idols = FanIdol.select(FanIdol.idol).where( FanIdol.fan == current_user.id, FanIdol.approved == True) images = Image.select().where((Image.user.in_(idols)) | ( Image.user == current_user.id)).order_by(Image.created_at.desc()) return render_template('home.html', images=images) else: return render_template('sessions/new.html')
def approved(id): fan = User.get_by_id(id) follower = FanIdol.update(approved=True).where(FanIdol.fan==id,FanIdol.idol==current_user.id) if follower.execute(): flash(f'{fan.username} now is your follower.','primary') return redirect(url_for('users.show',username=current_user.username)) else: flash(f'Failed to approve request,try again later.','danger') return redirect(url_for('users.show',username=current_user.username))
def idols(self): from models.fanidol import FanIdol # get a list of idols idols = FanIdol.select().where(FanIdol.fan == self.id, FanIdol.is_approved == True) idols_list = [] for idol in idols: idols_list.append(idol.idol) return idols_list
def unblock(fan_username): fan = User.get_or_none(User.username == fan_username) fanidolrow = FanIdol.get_or_none(FanIdol.idol == current_user.id, FanIdol.fan == fan.id) fanidolrow.blocked = False fanidolrow.save() return redirect(url_for('users.blockeduser'))
def unfollow(id): idol = User.get_by_id(id) fan_status = FanIdol.get(FanIdol.fan==current_user.id,FanIdol.idol==id) if idol.private == True: if fan_status.approved == True: fan = FanIdol.delete().where(FanIdol.fan==current_user.id,FanIdol.idol==idol.id) fan.execute() flash(f"Successfully unfollowed {idol.username}.","primary") return redirect(url_for('index')) else: fan = FanIdol.delete().where(FanIdol.fan==current_user.id,FanIdol.idol==idol.id) fan.execute() flash(f"Successfully cancelled your follow request of {idol.username}.","primary") return redirect(url_for('users.show',username=current_user.username)) elif idol.private == False: fan = FanIdol.delete().where(FanIdol.fan==current_user.id,FanIdol.idol==idol.id) fan.execute() flash(f"Successfully unfollowed {idol.username}.","primary") return redirect(url_for('index')) else: flash(f"Failed to unfollow {idol.username}. Try again later.","danger") return redirect(url_for('index'))
def follow(self, idol_id): from models.fanidol import FanIdol idol = User.get_by_id(int(idol_id)) if idol.is_private == "False": fanidol = FanIdol(fan=self.id, idol=idol_id, approved=True) else: fanidol = FanIdol(fan=self.id, idol=idol_id) fanidol.save()
def follow(id): idol = User.get_by_id(id) if idol.private == True: fan = FanIdol(fan=current_user.id,idol=idol.id,approved=False) if fan.save(): flash(f"Request is sent to {idol.username}. Please wait for approval.","primary") return redirect(url_for('index')) else: flash(f"Unable to send request to {idol.username}. Please try again later.","danger") return redirect(url_for('index')) else: fan = FanIdol(fan=current_user.id,idol=idol.id,approved=True) if fan.save(): flash(f"Successfully followed {idol.username}.","primary") return redirect(url_for('index')) else: flash(f"Failed to follow {idol.username}.","danger") return redirect(url_for('index'))
def unfollow(self, idol): from models.fanidol import FanIdol FanIdol.delete().where(self.id == FanIdol.fan and idol == FanIdol.idol).execute() return True
def followings(self): from models.fanidol import FanIdol # to get all idols idols = FanIdol.select(FanIdol.idol).where(FanIdol.fan==self.id,FanIdol.approved==True) return User.select().where(User.id.in_(idols))
def followers(self): from models.fanidol import FanIdol # to get all fans fans = FanIdol.select(FanIdol.fan).where(FanIdol.idol==self.id,FanIdol.approved==True) return User.select().where(User.id.in_(fans))
def get_request(self): from models.fanidol import FanIdol return FanIdol.select().where(FanIdol.idol==self.id,FanIdol.approved==False)
def follow_status(self,idol): from models.fanidol import FanIdol # check following status : # if already follow => return that row, # else return None(mean not follow this idol before) return FanIdol.get_or_none(FanIdol.fan==self.id,FanIdol.idol==idol.id)
def approve_request(self,fan): from models.fanidol import FanIdol return FanIdol.update(approved=True).where(FanIdol.fan==fan.id,FanIdol.idol==self.id).execute()
def unfollow(self,idol): from models.fanidol import FanIdol return FanIdol.delete().where(FanIdol.fan==self.id,FanIdol.idol==idol.id).execute()
def idol_requests(self): from models.fanidol import FanIdol idols = FanIdol.select(FanIdol.idol).where( FanIdol.fan == self.id, FanIdol.is_approved == False) return User.select().where(User.id.in_(idols))
def follow_status(self, idol): from models.fanidol import FanIdol return FanIdol.get_or_none(FanIdol.fan == self.id, FanIdol.idol == idol.id)