def main_post_to_another_wall(business_name): # forms business_post_form = BusinessPostForm( CombinedMultiDict((request.files, request.form))) friendform = FriendForm() deleteposttextform = DeletePostTextForm() banuserdeleteform = QuickBanDelete() lockpostform = QuickLock() deletepostform = QuickDelete() muteuserform = QuickMute() subform = SubscribeForm() navlink = 2 thebiz = db.session.query(Business).filter( Business.business_name == business_name).first() seeifsubbedtobiz = BusinessFollowers.query.filter( BusinessFollowers.user_id == current_user.id, BusinessFollowers.business_id == thebiz.id).first() if seeifsubbedtobiz is None: seeifsubbed = 0 else: seeifsubbed = 1 if thebiz is None: flash('Business does not exist', category='warning') return redirect(url_for('index')) # get users posts biz_posts = db.session.query(CommonsPost) biz_posts = biz_posts.filter(thebiz.id == CommonsPost.business_id) biz_posts = biz_posts.filter(CommonsPost.user_id != thebiz.user_id) biz_posts = biz_posts.filter(CommonsPost.subcommon_id == 13) biz_posts = biz_posts.filter(CommonsPost.userhidden == 0) biz_posts = biz_posts.filter(CommonsPost.hidden == 0) biz_posts = biz_posts.filter(CommonsPost.muted == 0) biz_posts = biz_posts.order_by(CommonsPost.created.desc()) posts = biz_posts.limit(50) return render_template( 'business/main_other_wall.html', now=datetime.utcnow(), business_post_form=business_post_form, banuserdeleteform=banuserdeleteform, lockpostform=lockpostform, deletepostform=deletepostform, seeifsubbed=seeifsubbed, muteuserform=muteuserform, friendform=friendform, deleteposttextform=deleteposttextform, posts=posts, subform=subform, thebiz=thebiz, navlink=navlink, biz_posts=biz_posts, )
def main(user_name): # forms friendform = FriendForm() deleteposttextform = DeletePostTextForm() banuserdeleteform = QuickBanDelete() lockpostform = QuickLock() deletepostform = QuickDelete() muteuserform = QuickMute() navlink = 1 wall_post_form = MainPostForm( CombinedMultiDict((request.files, request.form))) if user_name == 'A_Bot': user_name = "answer.cash" theuser = db.session\ .query(User)\ .filter(User.user_name == user_name)\ .first() if theuser is None: flash('User does not exist', category='warning') return redirect( url_for('profile.main', user_name=current_user.user_name)) if current_user.is_authenticated: # see if blocked isuserblocked = db.session\ .query(BlockedUser)\ .filter(BlockedUser.user_id == theuser.id, BlockedUser.blocked_user == current_user.id)\ .first() if isuserblocked: flash('User does not exist', category='warning') return redirect(url_for('index')) usersubforums = db.session\ .query(Subscribed)\ .join(SubForums, (Subscribed.subcommon_id == SubForums.id))\ .filter(theuser.id == Subscribed.user_id)\ .filter(SubForums.room_deleted != 1)\ .filter(SubForums.room_suspended != 1)\ .filter(SubForums.room_banned != 1)\ .all() guestsubforums = None seeifmodding = db.session.query(Mods)\ .filter(Mods.user_id == theuser.id) seeifmod = seeifmodding.all() moddingcount = seeifmodding.count() seeifownering = db.session\ .query(SubForums)\ .filter(SubForums.creator_user_id == theuser.id)\ .filter(SubForums.room_deleted != 1) seeifowner = seeifownering.all() ownercount = seeifownering.count() # get followers get_followers = db.session\ .query(User)\ .join(Followers, (User.id == Followers.followed_id))\ .filter(Followers.follower_id == theuser.id)\ .limit(9) # get users posts userposts = db.session\ .query(CommonsPost)\ .filter(theuser.id == CommonsPost.user_id)\ .filter(CommonsPost.hidden == 0)\ .filter(CommonsPost.muted == 0)\ .order_by(CommonsPost.created.desc()) posts = userposts.limit(50) postcount = userposts.count() follower_count = db.session\ .query(Followers)\ .filter(Followers.follower_id == theuser.id)\ .count() followed_count = db.session\ .query(Followers)\ .filter(Followers.followed_id == theuser.id)\ .count() expcount = db.session\ .query(ExpTable)\ .filter(ExpTable.user_id == theuser.id)\ .count() userexp = db.session\ .query(ExpTable)\ .filter(ExpTable.user_id == theuser.id)\ .order_by(ExpTable.id.desc())\ .limit(5) return render_template( 'users/profile/profile.html', seeifmod=seeifmod, postcount=postcount, moddingcount=moddingcount, ownercount=ownercount, usersubforums=usersubforums, guestsubforums=guestsubforums, seeifowner=seeifowner, wall_post_form=wall_post_form, banuserdeleteform=banuserdeleteform, lockpostform=lockpostform, deletepostform=deletepostform, muteuserform=muteuserform, friendform=friendform, deleteposttextform=deleteposttextform, posts=posts, theuser=theuser, user_name=user_name, navlink=navlink, get_followers=get_followers, follower_count=follower_count, followed_count=followed_count, expcount=expcount, userexp=userexp, )
def frontpage_home(): """ Returns index page and most exp posts :return: """ subform = SubscribeForm() banuserdeleteform = QuickBanDelete() lockpostform = QuickLock() deletepostform = QuickDelete() muteuserform = QuickMute() subid = 0 navlink = 1 currentbchprice = db.session.query(BchPrices).get(1) # get unread messages if current_user.is_authenticated: thenotes = db.session.query(Notifications) thenotes = thenotes.filter(Notifications.user_id == current_user.id) thenotes = thenotes.order_by(Notifications.timestamp.desc()) thenotescount = thenotes.filter(Notifications.read == 0) thenotescount = thenotescount.count() thenotes = thenotes.limit(25) else: thenotes = 0 thenotescount = 0 usersubforums = db.session.query(Subscribed) usersubforums = usersubforums.join( SubForums, (Subscribed.subcommon_id == SubForums.id)) usersubforums = usersubforums.filter(current_user.id == Subscribed.user_id) usersubforums = usersubforums.filter(SubForums.id != 1) usersubforums = usersubforums.filter(SubForums.room_deleted != 1) usersubforums = usersubforums.order_by((SubForums.id == 31).desc(), SubForums.subcommon_name) usersubforums = usersubforums.all() seeifmodding = db.session.query(Mods) seeifmodding = seeifmodding.filter(Mods.user_id == current_user.id) seeifmod = seeifmodding.all() moddingcount = seeifmodding.count() seeifownering = db.session.query(SubForums) seeifownering = seeifownering.filter( SubForums.creator_user_id == current_user.id) seeifownering = seeifownering.filter(SubForums.room_deleted != 1) seeifowner = seeifownering.all() ownercount = seeifownering.count() if current_user.is_authenticated: mainpostform = MainPostForm( CombinedMultiDict((request.files, request.form)), ) mainpostform.roomname.choices = [(str(row.subscriber.id), str(row.subscriber.subcommon_name)) for row in usersubforums] else: mainpostform = None if current_user.is_authenticated: if current_user.over_age is False: post_18 = 0 allpost = 0 else: allpost = 0 post_18 = 1 else: post_18 = 0 allpost = 0 if current_user.is_authenticated: recmsgs = db.session.query(Messages) recmsgs = recmsgs.filter(Messages.rec_user_id == current_user.id, Messages.read_rec == 1) recmsgs = recmsgs.count() sendmsgs = db.session.query(Messages) sendmsgs = sendmsgs.filter(Messages.sender_user_id == current_user.id, Messages.read_send == 1) sendmsgs = sendmsgs.count() themsgs = int(sendmsgs) + int(recmsgs) else: themsgs = 0 # list of subs user belongs too usersublist = [] for usersub in usersubforums: usersublist.append(usersub.subcommon_id) # query latest rooms new_rooms = db.session.query(SubForums) \ .filter(SubForums.id.notin_(usersublist), SubForums.room_deleted == 0, SubForums.room_suspended == 0, SubForums.room_banned == 0, SubForums.id != 1, SubForums.id != 14 ) \ .order_by(SubForums.created.desc()).limit(6) # query random rooms random_rooms = db.session.query(SubForums).filter( SubForums.id.notin_(usersublist), SubForums.room_deleted == 0, SubForums.room_suspended == 0, SubForums.room_banned == 0, SubForums.id != 1, SubForums.id != 14 ) \ .order_by(func.random()) \ .limit(6) page = request.args.get('page', 1, type=int) # POSTS sub queries where user is subbed to list # get posts by most exp posts = db.session.query(CommonsPost) posts = posts.filter(CommonsPost.subcommon_id.in_(usersublist)) posts = posts.filter(CommonsPost.subcommon_id != 1) posts = posts.filter(CommonsPost.hidden == 0) posts = posts.filter( or_(CommonsPost.age == post_18, CommonsPost.age == allpost)) posts = posts.order_by(CommonsPost.hotness_rating_now.desc(), CommonsPost.created.desc()) posts = posts.paginate(page, app.config['POSTS_PER_PAGE'], False) next_url = url_for('frontpage.frontpage_home', page=posts.next_num) \ if posts.has_next else None prev_url = url_for('frontpage.frontpage_home', page=posts.prev_num) \ if posts.has_prev else None return render_template( 'frontpage.html', now=datetime.utcnow(), # forms subform=subform, thenotescount=thenotescount, mainpostform=mainpostform, banuserdeleteform=banuserdeleteform, lockpostform=lockpostform, deletepostform=deletepostform, muteuserform=muteuserform, # general new_rooms=new_rooms, random_rooms=random_rooms, seeifmod=seeifmod, moddingcount=moddingcount, seeifowner=seeifowner, ownercount=ownercount, subid=subid, themsgs=themsgs, navlink=navlink, usersubforums=usersubforums, thenotes=thenotes, # pagination posts=posts.items, next_url=next_url, prev_url=prev_url, currentbchprice=currentbchprice, )
def frontpage_top(): """ Returns index page and most voted/commented posts :return: """ subform = SubscribeForm() banuserdeleteform = QuickBanDelete() lockpostform = QuickLock() deletepostform = QuickDelete() muteuserform = QuickMute() voteform = VoteForm() subid = 0 navlink = 5 currentbtcprice = db.session.query(BtcPrices).get(1) currentxmrprice = db.session.query(MoneroPrices).get(1) currentbchprice = db.session.query(BchPrices).get(1) currentltcprice = db.session.query(LtcPrices).get(1) # see if user leveled up and has a display to flash seeiflevelup = db.session.query(DisplayCoins).filter( DisplayCoins.user_id == current_user.id).all() if seeiflevelup is not None: for levelup in seeiflevelup: flash("You have leveled up to level: " + str(levelup.new_user_level), category='success') flash("Your have recieved 2 new coins", category='success') db.session.delete(levelup) db.session.commit() # Trending subforums trending = db.session.query(SubForums).order_by( SubForums.total_exp_subcommon.desc()).limit(10) # get unread messages if current_user.is_authenticated: thenotes = db.session.query(Notifications) thenotes = thenotes.filter(Notifications.user_id == current_user.id) thenotes = thenotes.order_by(Notifications.timestamp.desc()) thenotescount = thenotes.filter(Notifications.read == 0) thenotescount = thenotescount.count() thenotes = thenotes.limit(25) else: thenotes = 0 thenotescount = 0 recmsgs = db.session.query(Messages) recmsgs = recmsgs.filter(Messages.rec_user_id == current_user.id, Messages.read_rec == 1) recmsgs = recmsgs.count() sendmsgs = db.session.query(Messages) sendmsgs = sendmsgs.filter(Messages.sender_user_id == current_user.id, Messages.read_send == 1) sendmsgs = sendmsgs.count() themsgs = int(sendmsgs) + int(recmsgs) # getsubs user belongs too and add to list usersubforums = db.session.query(Subscribed) usersubforums = usersubforums.join( SubForums, (Subscribed.subcommon_id == SubForums.id)) usersubforums = usersubforums.filter(current_user.id == Subscribed.user_id) usersubforums = usersubforums.filter(SubForums.id != 1) usersubforums = usersubforums.filter(SubForums.room_deleted != 1) usersubforums = usersubforums.order_by((SubForums.id == 31).desc(), SubForums.subcommon_name) usersubforums = usersubforums.all() seeifmodding = db.session.query(Mods) seeifmodding = seeifmodding.filter(Mods.user_id == current_user.id) seeifmod = seeifmodding.all() moddingcount = seeifmodding.count() seeifownering = db.session.query(SubForums) seeifownering = seeifownering.filter( SubForums.creator_user_id == current_user.id) seeifownering = seeifownering.filter(SubForums.room_deleted != 1) seeifowner = seeifownering.all() ownercount = seeifownering.count() mainpostform = MainPostForm( CombinedMultiDict((request.files, request.form)), ) mainpostform.roomname.choices = [(str(row.subscriber.id), str(row.subscriber.subcommon_name)) for row in usersubforums] if current_user.over_age is False: post_18 = 0 allpost = 0 else: allpost = 0 post_18 = 1 userbusiness = db.session.query(Business) userbusiness = userbusiness.filter(Business.user_id == current_user.id) userbusinesses = userbusiness.all() userbusinessescount = userbusiness.count() bizfollowing = db.session.query(BusinessFollowers) bizfollowing = bizfollowing.join( Business, (BusinessFollowers.business_id == Business.id)) bizfollowing = bizfollowing.filter( current_user.id == BusinessFollowers.user_id) bizfollowing = bizfollowing.all() # list of subs user belongs too usersublist = [] for usersub in usersubforums: usersublist.append(usersub.subcommon_id) # query latest rooms new_rooms = db.session.query(SubForums) \ .filter(SubForums.id.notin_(usersublist), SubForums.room_deleted == 0, SubForums.room_suspended == 0, SubForums.room_banned == 0, SubForums.id != 1, SubForums.id != 14 ) \ .order_by(SubForums.created.desc()).limit(6) # query random rooms random_rooms = db.session.query(SubForums).filter( SubForums.id.notin_(usersublist), SubForums.room_deleted == 0, SubForums.room_suspended == 0, SubForums.room_banned == 0, SubForums.id != 1, SubForums.id != 14 ) \ .order_by(func.random()) \ .limit(6) # POSTS sub queries page = request.args.get('page', 1, type=int) posts = db.session.query(CommonsPost) posts = posts.filter(CommonsPost.subcommon_id.in_(usersublist)) posts = posts.filter(CommonsPost.subcommon_id != 1) posts = posts.filter(CommonsPost.hidden == 0) posts = posts.filter( or_(CommonsPost.age == post_18, CommonsPost.age == allpost)) posts = posts.order_by(CommonsPost.highest_exp_reached.desc()) posts = posts.paginate(page, app.config['POSTS_PER_PAGE'], False) next_url = url_for('frontpage.frontpage_mostactive', page=posts.next_num) \ if posts.has_next else None prev_url = url_for('frontpage.frontpage_mostactive', page=posts.prev_num) \ if posts.has_prev else None return render_template( 'frontpage.html', now=datetime.utcnow(), currentbtcprice=currentbtcprice, currentxmrprice=currentxmrprice, currentbchprice=currentbchprice, currentltcprice=currentltcprice, # forms mainpostform=mainpostform, voteform=voteform, banuserdeleteform=banuserdeleteform, lockpostform=lockpostform, deletepostform=deletepostform, muteuserform=muteuserform, subform=subform, themsgs=themsgs, usersubforums=usersubforums, userbusinesses=userbusinesses, userbusinessescount=userbusinessescount, bizfollowing=bizfollowing, # general new_rooms=new_rooms, thenotescount=thenotescount, random_rooms=random_rooms, seeifmod=seeifmod, moddingcount=moddingcount, seeifowner=seeifowner, ownercount=ownercount, thenotes=thenotes, subid=subid, navlink=navlink, # queries/pagination trending=trending, posts=posts.items, next_url=next_url, prev_url=prev_url, )
def index(): """ Returns index page and hottest posts :return: """ now = datetime.utcnow() navlink = 1 subform = SubscribeForm() banuserdeleteform = QuickBanDelete() lockpostform = QuickLock() deletepostform = QuickDelete() muteuserform = QuickMute() currentbchprice = BchPrices.query.get(1) # get unread messages if current_user.is_authenticated: therecmsgs = db.session\ .query(Messages)\ .filter(Messages.rec_user_id == current_user.id, Messages.read_rec == 1)\ .count() thesendmsgs = db.session\ .query(Messages)\ .filter(Messages.sender_user_id == current_user.id, Messages.read_send == 1)\ .count() themsgs = int(thesendmsgs) + int(therecmsgs) else: themsgs = 0 # get unread notifications if current_user.is_authenticated: thenotes = db.session\ .query(Notifications)\ .filter(Notifications.user_id == current_user.id)\ .order_by(Notifications.timestamp.desc()) thenotescount = thenotes.filter(Notifications.read == 0).count() thenotes.limit(25) else: thenotes = 0 thenotescount = 0 # get users daily missions if current_user.is_authenticated: if current_user.confirmed == 1: getuserdaily = db.session.query(UserDailyChallenge) \ .filter(UserDailyChallenge.user_id == current_user.id) \ .all() else: getuserdaily = db.session.query(DailyChallenge) \ .order_by(func.random()) \ .limit(2) else: getuserdaily = db.session.query(DailyChallenge) \ .order_by(func.random()) \ .limit(2) if current_user.is_authenticated: # get subs user belongs too usersubforums = db.session \ .query(Subscribed) \ .join(SubForums, (Subscribed.subcommon_id == SubForums.id)) \ .filter(current_user.id == Subscribed.user_id) \ .filter(SubForums.room_banned == 0, SubForums.room_deleted == 0, SubForums.room_suspended == 0 ) \ .order_by(SubForums.subcommon_name) \ .all() guestsubforums = None else: guestsubforums = db.session \ .query(SubForums) \ .filter(SubForums.age_required == 0) \ .filter(SubForums.type_of_subcommon == 0) \ .filter(SubForums.room_banned == 0, SubForums.room_deleted == 0, SubForums.room_suspended == 0, ) \ .order_by(SubForums.total_exp_subcommon.desc()) \ .limit(7) usersubforums = None if current_user.is_authenticated: # get subs user belongs too seeifmod = db.session\ .query(Mods)\ .filter(Mods.user_id == current_user.id) moddingcount = seeifmod.count() seeifmod = seeifmod.all() else: seeifmod = None moddingcount = None # POSTS sub quries page = request.args.get('page', 1, type=int) posts = db.session \ .query(CommonsPost) \ .filter(CommonsPost.hidden == 0) \ .order_by(CommonsPost.hotness_rating_now.desc(), CommonsPost.created.desc()) \ .paginate(page, app.config['POSTS_PER_PAGE'], False) next_url = url_for('index', page=posts.next_num) \ if posts.has_next else None prev_url = url_for('index', page=posts.prev_num) \ if posts.has_prev else None return render_template( 'index.html', now=now, # forms subform=subform, banuserdeleteform=banuserdeleteform, lockpostform=lockpostform, deletepostform=deletepostform, muteuserform=muteuserform, # general getuserdaily=getuserdaily, seeifmod=seeifmod, moddingcount=moddingcount, themsgs=themsgs, usersubforums=usersubforums, guestsubforums=guestsubforums, navlink=navlink, thenotes=thenotes, thenotescount=thenotescount, # pagination posts=posts.items, next_url=next_url, prev_url=prev_url, # coin prices currentbchprice=currentbchprice, )
def frontpage_mostactive(): """ Returns index page and most voted/commented posts :return: """ subform = SubscribeForm() banuserdeleteform = QuickBanDelete() lockpostform = QuickLock() deletepostform = QuickDelete() muteuserform = QuickMute() subid = 0 navlink = 3 currentbchprice = db.session.query(BchPrices).get(1) # Trending subforums trending = db.session.query(SubForums).order_by( SubForums.total_exp_subcommon.desc()).limit(10) # get unread messages if current_user.is_authenticated: thenotes = db.session.query(Notifications) thenotes = thenotes.filter(Notifications.user_id == current_user.id) thenotes = thenotes.order_by(Notifications.timestamp.desc()) thenotescount = thenotes.filter(Notifications.read == 0) thenotescount = thenotescount.count() thenotes = thenotes.limit(25) else: thenotes = 0 thenotescount = 0 recmsgs = db.session.query(Messages) recmsgs = recmsgs.filter(Messages.rec_user_id == current_user.id, Messages.read_rec == 1) recmsgs = recmsgs.count() sendmsgs = db.session.query(Messages) sendmsgs = sendmsgs.filter(Messages.sender_user_id == current_user.id, Messages.read_send == 1) sendmsgs = sendmsgs.count() themsgs = int(sendmsgs) + int(recmsgs) # get subs user belongs too and add to list usersubforums = db.session.query(Subscribed) usersubforums = usersubforums.join( SubForums, (Subscribed.subcommon_id == SubForums.id)) usersubforums = usersubforums.filter(current_user.id == Subscribed.user_id) usersubforums = usersubforums.filter(SubForums.id != 1) usersubforums = usersubforums.filter(SubForums.room_deleted != 1) usersubforums = usersubforums.order_by((SubForums.id == 31).desc(), SubForums.subcommon_name) usersubforums = usersubforums.all() seeifmodding = db.session.query(Mods) seeifmodding = seeifmodding.filter(Mods.user_id == current_user.id) seeifmod = seeifmodding.all() moddingcount = seeifmodding.count() mainpostform = MainPostForm( CombinedMultiDict((request.files, request.form)), ) mainpostform.roomname.choices = [(str(row.subscriber.id), str(row.subscriber.subcommon_name)) for row in usersubforums] if current_user.over_age is False: post_18 = 0 allpost = 0 else: allpost = 0 post_18 = 1 # list of subs user belongs too usersublist = [] for usersub in usersubforums: usersublist.append(usersub.subcommon_id) # POSTS sub queries page = request.args.get('page', 1, type=int) posts = db.session.query(CommonsPost) posts = posts.filter(CommonsPost.subcommon_id.in_(usersublist)) posts = posts.filter(CommonsPost.subcommon_id != 1) posts = posts.filter(CommonsPost.hidden == 0) posts = posts.filter( or_(CommonsPost.age == post_18, CommonsPost.age == allpost)) posts = posts.order_by(CommonsPost.comment_count.desc(), CommonsPost.created.desc()) posts = posts.paginate(page, app.config['POSTS_PER_PAGE'], False) next_url = url_for('frontpage.frontpage_mostactive', page=posts.next_num) \ if posts.has_next else None prev_url = url_for('frontpage.frontpage_mostactive', page=posts.prev_num) \ if posts.has_prev else None return render_template( 'frontpage.html', now=datetime.utcnow(), currentbchprice=currentbchprice, # forms mainpostform=mainpostform, banuserdeleteform=banuserdeleteform, lockpostform=lockpostform, deletepostform=deletepostform, muteuserform=muteuserform, subform=subform, # general thenotescount=thenotescount, seeifmod=seeifmod, moddingcount=moddingcount, thenotes=thenotes, subid=subid, themsgs=themsgs, navlink=navlink, usersubforums=usersubforums, # queries/pagination trending=trending, posts=posts.items, next_url=next_url, prev_url=prev_url, )
def followers_home(): """ Returns index page and most exp posts :return: """ try: subform = SubscribeForm() wall_post_form = MainPostForm(CombinedMultiDict((request.files, request.form))) banuserdeleteform = QuickBanDelete() lockpostform = QuickLock() deletepostform = QuickDelete() muteuserform = QuickMute() subid = 0 navlink = 3 currentbchprice = db.session\ .query(BchPrices)\ .get(1) thenotes = db.session\ .query(Notifications)\ .filter(Notifications.user_id == current_user.id)\ .order_by(Notifications.timestamp.desc()) thenotescount = thenotes.filter(Notifications.read == 0).count() thenotes = thenotes.limit(25) recmsgs = db.session\ .query(Messages)\ .filter(Messages.rec_user_id == current_user.id, Messages.read_rec == 1)\ .count() sendmsgs = db.session\ .query(Messages)\ .filter(Messages.sender_user_id == current_user.id, Messages.read_send == 1)\ .count() themsgs = int(sendmsgs) + int(recmsgs) usersubforums = db.session\ .query(Subscribed)\ .join(SubForums, (Subscribed.subcommon_id == SubForums.id))\ .filter(current_user.id == Subscribed.user_id)\ .filter(SubForums.room_banned == 0, SubForums.room_deleted == 0, SubForums.room_suspended == 0 )\ .order_by((SubForums.id == 31).desc(), SubForums.subcommon_name)\ .all() seeifmodding = db.session.query(Mods)\ .filter(Mods.user_id == current_user.id) seeifmod = seeifmodding.all() moddingcount = seeifmodding.count() seeifownering = db.session\ .query(SubForums)\ .filter(SubForums.creator_user_id == current_user.id)\ .filter(SubForums.room_deleted != 1) seeifowner = seeifownering.all() ownercount = seeifownering.count() # Most Recent Tippers recent_tippers_post = db.session.query(RecentTips) \ .order_by(RecentTips.created.desc()) \ .limit(3) # Trending subforums trending = db.session.query(SubForums) \ .order_by(SubForums.total_exp_subcommon.desc()) \ .limit(10) if current_user.over_age is False: post_18 = 0 allpost = 0 else: allpost = 0 post_18 = 1 # list of friends ids usersublist = [] usersubfriends = db.session\ .query(Followers) \ .filter(Followers.follower_id == current_user.id) \ .all() for userfriend in usersubfriends: usersublist.append(userfriend.followed_id) if current_user.is_authenticated: mainpostform = MainPostForm(CombinedMultiDict((request.files, request.form)), ) mainpostform.roomname.choices = \ [(str(row.subscriber.id), str(row.subscriber.subcommon_name)) for row in usersubforums] else: mainpostform = None # POSTS sub queries where user is subbed to list # get posts by most exp page = request.args.get('page', 1, type=int) posts = db.session\ .query(CommonsPost)\ .filter(CommonsPost.hidden == 0)\ .filter(CommonsPost.user_id.in_(usersublist))\ .filter(or_(CommonsPost.age == post_18, CommonsPost.age == allpost))\ .order_by(CommonsPost.hotness_rating_now.desc(), CommonsPost.created.desc())\ .paginate(page, POSTS_PER_PAGE, False) next_url = url_for('followers.followers_home', page=posts.next_num) \ if posts.has_next else None prev_url = url_for('followers.followers_home', page=posts.prev_num) \ if posts.has_prev else None except Exception as e: flash("There was an error") return redirect(url_for('index')) return render_template('followers.html', now=datetime.utcnow(), # forms subform=subform, mainpostform=mainpostform, wall_post_form=wall_post_form, banuserdeleteform=banuserdeleteform, lockpostform=lockpostform, deletepostform=deletepostform, muteuserform=muteuserform, # general seeifmod=seeifmod, moddingcount=moddingcount, seeifowner=seeifowner, ownercount=ownercount, thenotescount=thenotescount, subid=subid, navlink=navlink, themsgs=themsgs, usersubforums=usersubforums, # queries/pagination trending=trending, thenotes=thenotes, # stats recent_tippers_post=recent_tippers_post, # pagination posts=posts.items, next_url=next_url, prev_url=prev_url, currentbchprice=currentbchprice, )
def newest(): """ Returns index page and hottest posts :return: """ subform = SubscribeForm() banuserdeleteform = QuickBanDelete() lockpostform = QuickLock() deletepostform = QuickDelete() muteuserform = QuickMute() navlink = 2 currentbchprice = BchPrices.query.get(1) now = datetime.utcnow() # get unread notifications if current_user.is_authenticated: thenotes = db.session \ .query(Notifications) \ .filter(Notifications.user_id == current_user.id) \ .order_by(Notifications.timestamp.desc()) thenotescount = thenotes \ .filter(Notifications.read == 0) \ .count() thenotes = thenotes.limit(25) else: thenotes = 0 thenotescount = 0 # get subs user belongs too if current_user.is_authenticated: usersubforums = db.session \ .query(Subscribed) \ .join(SubForums, (Subscribed.subcommon_id == SubForums.id)) \ .filter(current_user.id == Subscribed.user_id) \ .filter(SubForums.room_banned == 0, SubForums.room_deleted == 0, SubForums.room_suspended == 0 ) \ .order_by((SubForums.id == 31).desc(), SubForums.subcommon_name) \ .all() guestsubforums = None else: guestsubforums = db.session \ .query(SubForums) \ .filter(SubForums.age_required == 0) \ .filter(SubForums.room_banned == 0, SubForums.room_deleted == 0, SubForums.room_suspended == 0 ) \ .filter(SubForums.type_of_subcommon == 0) \ .order_by(SubForums.total_exp_subcommon.desc()) \ .limit(20) usersubforums = None if current_user.is_authenticated: recmsgs = db.session\ .query(Messages)\ .filter(Messages.rec_user_id == current_user.id, Messages.read_rec == 1)\ .count() sendmsgs = db.session\ .query(Messages)\ .filter(Messages.sender_user_id == current_user.id, Messages.read_send == 1)\ .count() themsgs = int(sendmsgs) + int(recmsgs) else: themsgs = 0 if current_user.is_authenticated: if current_user.over_age is False: post_18 = 0 allpost = 0 else: allpost = 0 post_18 = 1 else: post_18 = 0 allpost = 0 # get users daily missions if current_user.is_authenticated: if current_user.confirmed == 1: getuserdaily = db.session \ .query(UserDailyChallenge) \ .filter(UserDailyChallenge.user_id == current_user.id) \ .all() else: getuserdaily = db.session \ .query(DailyChallenge) \ .order_by(func.random()) \ .limit(2) else: getuserdaily = db.session \ .query(DailyChallenge) \ .order_by(func.random()) \ .limit(2) # POSTS sub queries page = request.args.get('page', 1, type=int) posts = db.session\ .query(CommonsPost)\ .filter(or_(CommonsPost.age == post_18, CommonsPost.age == allpost))\ .filter(CommonsPost.hidden == 0)\ .order_by(CommonsPost.created.desc())\ .paginate(page, app.config['POSTS_PER_PAGE'], False) next_url = url_for('newest', page=posts.next_num) \ if posts.has_next else None prev_url = url_for('newest', page=posts.prev_num) \ if posts.has_prev else None return render_template( 'index.html', now=now, # forms subform=subform, banuserdeleteform=banuserdeleteform, lockpostform=lockpostform, deletepostform=deletepostform, muteuserform=muteuserform, # general thenotes=thenotes, currentbchprice=currentbchprice, getuserdaily=getuserdaily, thenotescount=thenotescount, themsgs=themsgs, usersubforums=usersubforums, guestsubforums=guestsubforums, navlink=navlink, # pagination posts=posts.items, next_url=next_url, prev_url=prev_url, )
def followers_newest(): """ Returns index page and newest posts :return: """ subform = SubscribeForm() wall_post_form = MainPostForm(CombinedMultiDict((request.files, request.form))) banuserdeleteform = QuickBanDelete() lockpostform = QuickLock() deletepostform = QuickDelete() muteuserform = QuickMute() subid = 0 navlink = 2 currentbchprice = db.session \ .query(BchPrices) \ .get(1) # Trending subfoums trending = db.session \ .query(SubForums) \ .order_by(SubForums.total_exp_subcommon.desc()) \ .limit(10) # get unread messages if current_user.is_authenticated: thenotes = db.session \ .query(Notifications) \ .filter(Notifications.user_id == current_user.id) \ .order_by(Notifications.timestamp.desc()) thenotescount = thenotes.filter(Notifications.read == 0).count() thenotes = thenotes.limit(25) else: thenotes = 0 thenotescount = 0 recmsgs = db.session \ .query(Messages) \ .filter(Messages.rec_user_id == current_user.id, Messages.read_rec == 1) \ .count() sendmsgs = db.session \ .query(Messages) \ .filter(Messages.sender_user_id == current_user.id, Messages.read_send == 1) \ .count() themsgs = int(sendmsgs) + int(recmsgs) seeifmodding = db.session.query(Mods) \ .filter(Mods.user_id == current_user.id) seeifmod = seeifmodding.all() moddingcount = seeifmodding.count() seeifownering = db.session \ .query(SubForums) \ .filter(SubForums.creator_user_id == current_user.id) \ .filter(SubForums.room_deleted != 1) seeifowner = seeifownering.all() ownercount = seeifownering.count() usersubforums = db.session \ .query(Subscribed) \ .join(SubForums, (Subscribed.subcommon_id == SubForums.id)) \ .filter(current_user.id == Subscribed.user_id) \ .filter(SubForums.room_banned == 0, SubForums.room_deleted == 0, SubForums.room_suspended == 0 ) \ .all() if current_user.is_authenticated: if current_user.over_age is False: post_18 = 0 allpost = 0 else: allpost = 0 post_18 = 1 else: post_18 = 0 allpost = 0 # list of friends ids usersublist = [] usersubfriends = db.session \ .query(Followers) \ .filter(Followers.follower_id == current_user.id) \ .all() for userfriend in usersubfriends: usersublist.append(userfriend.followed_id) # POSTS sub queries page = request.args.get('page', 1, type=int) posts = db.session \ .query(CommonsPost) \ .filter(CommonsPost.hidden == 0) \ .filter(or_(CommonsPost.age == post_18, CommonsPost.age == allpost)) \ .filter(CommonsPost.user_id.in_(usersublist)) \ .order_by(CommonsPost.created.desc()) \ .paginate(page,POSTS_PER_PAGE, False) next_url = url_for('followers.followers_newest', page=posts.next_num) \ if posts.has_next else None prev_url = url_for('followers.followers_newest', page=posts.prev_num) \ if posts.has_prev else None return render_template('followers.html', now=datetime.utcnow(), currentbchprice=currentbchprice, # form wall_post_form=wall_post_form, subform=subform, banuserdeleteform=banuserdeleteform, lockpostform=lockpostform, deletepostform=deletepostform, muteuserform=muteuserform, # general thenotescount=thenotescount, thenotes=thenotes, themsgs=themsgs, seeifmod=seeifmod, moddingcount=moddingcount, seeifowner=seeifowner, ownercount=ownercount, subid=subid, navlink=navlink, usersubforums=usersubforums, # queries/pagination trending=trending, posts=posts.items, next_url=next_url, prev_url=prev_url, )
def followers_top(): """ Returns index page and most voted/commented posts :return: """ subform = SubscribeForm() wall_post_form = MainPostForm(CombinedMultiDict((request.files, request.form))) banuserdeleteform = QuickBanDelete() lockpostform = QuickLock() deletepostform = QuickDelete() muteuserform = QuickMute() voteform = VoteForm() subid = 0 navlink = 5 currentbtcprice = db.session.query(BtcPrices).get(1) currentxmrprice = db.session.query(MoneroPrices).get(1) currentbchprice = db.session.query(BchPrices).get(1) currentltcprice = db.session.query(LtcPrices).get(1) # see if user leveled up and has a display to flash seeiflevelup = db.session.query(DisplayCoins).filter(DisplayCoins.user_id == current_user.id).all() if seeiflevelup is not None: for levelup in seeiflevelup: flash("You have leveled up to level: " + str(levelup.new_user_level), category='success') flash("Your have recieved 2 new coins", category='success') db.session.delete(levelup) db.session.commit() # Trending subforums trending = db.session.query(SubForums).order_by(SubForums.total_exp_subcommon.desc()).limit(10) # get unread messages if current_user.is_authenticated: thenotes = db.session.query(Notifications) thenotes = thenotes.filter(Notifications.user_id == current_user.id) thenotes = thenotes.order_by(Notifications.timestamp.desc()) thenotescount = thenotes.filter(Notifications.read == 0) thenotescount = thenotescount.count() thenotes = thenotes.limit(25) else: thenotes = 0 thenotescount = 0 recmsgs = db.session.query(Messages) recmsgs = recmsgs.filter(Messages.rec_user_id == current_user.id, Messages.read_rec == 1) recmsgs = recmsgs.count() sendmsgs = db.session.query(Messages) sendmsgs = sendmsgs.filter(Messages.sender_user_id == current_user.id, Messages.read_send == 1) sendmsgs = sendmsgs.count() themsgs = int(sendmsgs) + int(recmsgs) seeifmodding = db.session.query(Mods) seeifmodding = seeifmodding.filter(Mods.user_id == current_user.id) seeifmod = seeifmodding.all() moddingcount = seeifmodding.count() seeifownering = db.session.query(SubForums) seeifownering = seeifownering.filter(SubForums.creator_user_id == current_user.id) seeifownering = seeifownering.filter(SubForums.room_deleted != 1) seeifowner = seeifownering.all() ownercount = seeifownering.count() usersubforums = db.session.query(Subscribed) usersubforums = usersubforums.join(SubForums, (Subscribed.subcommon_id == SubForums.id)) usersubforums = usersubforums.filter(current_user.id == Subscribed.user_id) usersubforums = usersubforums.filter(SubForums.id != 1) usersubforums = usersubforums.filter(SubForums.room_banned == 0, SubForums.room_deleted == 0, SubForums.room_suspended == 0 ) usersubforums = usersubforums.all() if current_user.is_authenticated: if current_user.over_age is False: post_18 = 0 allpost = 0 else: allpost = 0 post_18 = 1 else: post_18 = 0 allpost = 0 # list of friends ids usersublist = [] usersubfriends = Followers.query.filter(Followers.follower_id == current_user.id).all() for userfriend in usersubfriends: usersublist.append(userfriend.followed_id) # POSTS sub queries page = request.args.get('page', 1, type=int) posts = db.session.query(CommonsPost) posts = posts.filter(CommonsPost.hidden == 0) posts = posts.filter(or_(CommonsPost.age == post_18, CommonsPost.age == allpost)) posts = posts.filter(CommonsPost.user_id.in_(usersublist)) posts = posts.order_by(CommonsPost.highest_exp_reached.desc()) posts = posts.paginate(page, POSTS_PER_PAGE, False) next_url = url_for('followers.followers_mostactive', page=posts.next_num) \ if posts.has_next else None prev_url = url_for('followers.followers_mostactive', page=posts.prev_num) \ if posts.has_prev else None return render_template('followers.html', now=datetime.utcnow(), currentbtcprice=currentbtcprice, currentxmrprice=currentxmrprice, currentbchprice=currentbchprice, currentltcprice=currentltcprice, # forms subform=subform, wall_post_form=wall_post_form, voteform=voteform, banuserdeleteform=banuserdeleteform, lockpostform=lockpostform, deletepostform=deletepostform, muteuserform=muteuserform, # general seeifmod=seeifmod, moddingcount=moddingcount, seeifowner=seeifowner, ownercount=ownercount, thenotes=thenotes, thenotescount=thenotescount, subid=subid, themsgs=themsgs, navlink=navlink, usersubforums=usersubforums, # queries/pagination trending=trending, posts=posts.items, next_url=next_url, prev_url=prev_url, )
def followers_home(): """ Returns index page and most exp posts :return: """ try: subform = SubscribeForm() wall_post_form = MainPostForm(CombinedMultiDict((request.files, request.form))) banuserdeleteform = QuickBanDelete() lockpostform = QuickLock() deletepostform = QuickDelete() muteuserform = QuickMute() voteform = VoteForm() subpostcommentform = CreateCommentQuickForm() subid = 0 navlink = 3 currentbtcprice = db.session.query(BtcPrices).get(1) currentxmrprice = db.session.query(MoneroPrices).get(1) currentbchprice = db.session.query(BchPrices).get(1) currentltcprice = db.session.query(LtcPrices).get(1) thenotes = db.session.query(Notifications) thenotes = thenotes.filter(Notifications.user_id == current_user.id) thenotes = thenotes.order_by(Notifications.timestamp.desc()) thenotescount = thenotes.filter(Notifications.read == 0) thenotescount = thenotescount.count() thenotes = thenotes.limit(25) recmsgs = db.session.query(Messages) recmsgs = recmsgs.filter(Messages.rec_user_id == current_user.id, Messages.read_rec == 1) recmsgs = recmsgs.count() sendmsgs = db.session.query(Messages) sendmsgs = sendmsgs.filter(Messages.sender_user_id == current_user.id, Messages.read_send == 1) sendmsgs = sendmsgs.count() themsgs = int(sendmsgs) + int(recmsgs) usersubforums = db.session.query(Subscribed) usersubforums = usersubforums.join(SubForums, (Subscribed.subcommon_id == SubForums.id)) usersubforums = usersubforums.filter(current_user.id == Subscribed.user_id) usersubforums = usersubforums.filter(SubForums.id != 1) usersubforums = usersubforums.filter(SubForums.room_banned == 0, SubForums.room_deleted == 0, SubForums.room_suspended == 0 ) usersubforums = usersubforums.order_by((SubForums.id == 31).desc(), SubForums.subcommon_name) usersubforums = usersubforums.all() seeifmodding = db.session.query(Mods) seeifmodding = seeifmodding.filter(Mods.user_id == current_user.id) seeifmod = seeifmodding.all() moddingcount = seeifmodding.count() seeifownering = db.session.query(SubForums) seeifownering = seeifownering.filter(SubForums.creator_user_id == current_user.id) seeifownering = seeifownering.filter(SubForums.room_deleted != 1) seeifowner = seeifownering.all() ownercount = seeifownering.count() # see if user leveled up and has a display to flash seeiflevelup = db.session.query(DisplayCoins).filter(DisplayCoins.user_id == current_user.id).all() if seeiflevelup is not None: for levelup in seeiflevelup: flash("You have leveled up to level: " + str(levelup.new_user_level), category='success') flash("Your have recieved 2 new coins", category='success') db.session.delete(levelup) db.session.commit() # stats for sidebar # all time top tippers for posts top_tippers_alltime_post_btc = db.session.query(BtcPostTips) \ .order_by(BtcPostTips.amount_usd.desc()) \ .limit(3) # top tippers this week seven_days_ago = datetime.today() - timedelta(days=7) top_tippers_pastweek_post_btc = db.session.query(BtcPostTips) \ .filter(BtcPostTips.created >= seven_days_ago) \ .order_by(BtcPostTips.amount_usd.desc()) \ .limit(3) # Most Recent Tippers recent_tippers_post = db.session.query(RecentTips) \ .order_by(RecentTips.created.desc()) \ .limit(3) # Trending subforums trending = db.session.query(SubForums) \ .order_by(SubForums.total_exp_subcommon.desc()) \ .limit(10) if current_user.over_age is False: post_18 = 0 allpost = 0 else: allpost = 0 post_18 = 1 # list of friends ids usersublist = [] usersubfriends = db.session.query(Followers)\ .filter(Followers.follower_id == current_user.id)\ .all() for userfriend in usersubfriends: usersublist.append(userfriend.followed_id) if current_user.is_authenticated: mainpostform = MainPostForm(CombinedMultiDict((request.files, request.form)), ) mainpostform.roomname.choices = \ [(str(row.subscriber.id), str(row.subscriber.subcommon_name)) for row in usersubforums] else: mainpostform = None # POSTS sub queries where user is subbed to list # get posts by most exp page = request.args.get('page', 1, type=int) posts = db.session.query(CommonsPost) posts = posts.filter(CommonsPost.hidden == 0) posts = posts.filter(CommonsPost.user_id.in_(usersublist)) posts = posts.filter(or_(CommonsPost.age == post_18, CommonsPost.age == allpost)) posts = posts.order_by(CommonsPost.hotness_rating_now.desc(), CommonsPost.created.desc()) posts = posts.paginate(page, POSTS_PER_PAGE, False) next_url = url_for('followers.followers_home', page=posts.next_num) \ if posts.has_next else None prev_url = url_for('followers.followers_home', page=posts.prev_num) \ if posts.has_prev else None except Exception as e: flash("There was an error") return redirect(url_for('index')) return render_template('followers.html', now=datetime.utcnow(), # forms subform=subform, subpostcommentform=subpostcommentform, mainpostform=mainpostform, voteform=voteform, wall_post_form=wall_post_form, banuserdeleteform=banuserdeleteform, lockpostform=lockpostform, deletepostform=deletepostform, muteuserform=muteuserform, # general seeifmod=seeifmod, moddingcount=moddingcount, seeifowner=seeifowner, ownercount=ownercount, thenotescount=thenotescount, subid=subid, navlink=navlink, themsgs=themsgs, usersubforums=usersubforums, # queries/pagination trending=trending, thenotes=thenotes, # stats top_tippers_alltime_post_btc=top_tippers_alltime_post_btc, top_tippers_pastweek_post_btc=top_tippers_pastweek_post_btc, recent_tippers_post=recent_tippers_post, # pagination posts=posts.items, next_url=next_url, prev_url=prev_url, currentbtcprice=currentbtcprice, currentxmrprice=currentxmrprice, currentbchprice=currentbchprice, currentltcprice=currentltcprice, )
def sub(subname): # forms reportform = ReportForm() subform = SubscribeForm() banuserdeleteform = QuickBanDelete() lockpostform = QuickLock() deletepostform = QuickDelete() muteuserform = QuickMute() nsfwform = NSFWForm() navlink = 1 currentbchprice = db.session.query(BchPrices).get(1) # get the sub thesub = db.session \ .query(SubForums) \ .filter(func.lower(SubForums.subcommon_name) == subname.lower()) \ .first() if thesub is None: flash("Sub Doesnt Exist.", category="danger") return redirect(url_for('index')) if thesub.room_banned == 1: return redirect(url_for('subforum.sub_banned', subname=subname)) if thesub.room_suspended == 1: return redirect(url_for('subforum.sub_suspended', subname=subname)) if thesub.room_deleted == 1: return redirect(url_for('subforum.sub_deleted', subname=subname)) # get the stats substats = db.session \ .query(SubForumStats) \ .filter(SubForumStats.subcommon_name == subname.lower()) \ .first() # get sub customization subcustom_stuff = db.session \ .query(SubForumCustom) \ .filter(SubForumCustom.subcommon_id == thesub.id) \ .first() # get sub info box subinfobox = db.session \ .query(SubForumCustomInfoOne) \ .filter(func.lower(SubForumCustomInfoOne.subcommon_name) == subname.lower()) \ .first() subname = thesub.subcommon_name subid = int(thesub.id) mods = db.session \ .query(Mods) \ .filter(Mods.subcommon_id == subid) \ .all() if subcustom_stuff is None: subcustom_setup = None else: subcustom_setup = 1 # get unread messages if current_user.is_authenticated: thenotes = db.session \ .query(Notifications) \ .filter(Notifications.user_id == current_user.id) \ .order_by(Notifications.timestamp.desc()) \ .filter(Notifications.read == 0) thenotescount = thenotes.count() thenotes = thenotes.limit(25) else: thenotes = 0 thenotescount = 0 # see if user banned if current_user.is_authenticated: seeifbanned = db.session \ .query(Banned) \ .filter(current_user.id == Banned.user_id) \ .filter(Banned.subcommon_id == subid) \ .first() # if user on banned list turn him away if seeifbanned is not None: return redirect(url_for('banned', subname=subname)) # see if current user is a mod if current_user.is_authenticated: seeifmod = db.session \ .query(Mods) \ .filter(Mods.subcommon_id == subid) \ .filter(Mods.user_id == current_user.id) \ .first() if seeifmod is None: useramod = 0 else: useramod = 1 else: useramod = 0 # SIDEBAR if current_user.is_authenticated: # see if user is subscribed seeifsubbed = db.session.query(Subscribed) seeifsubbed = seeifsubbed.filter(current_user.id == Subscribed.user_id) seeifsubbed = seeifsubbed.filter(Subscribed.subcommon_id == subid) seeifsubbed = seeifsubbed.first() if seeifsubbed is None: seeifsubbed = 0 else: seeifsubbed = 1 # get users saved subcommons saved_subcommons = db.session.query(Subscribed) \ .filter(Subscribed.user_id == current_user.id) \ .all() # get users created subcommons created_subcommons = db.session.query(SubForums) \ .filter(SubForums.creator_user_id == current_user.id) \ .all() else: # if user isnt subscribed to anything seeifsubbed = None saved_subcommons = None created_subcommons = None if current_user.is_authenticated: usersubforums = db.session \ .query(Subscribed) \ .join(SubForums, (Subscribed.subcommon_id == SubForums.id)) \ .filter(current_user.id == Subscribed.user_id) \ .filter(SubForums.room_banned == 0, SubForums.room_deleted == 0, SubForums.room_suspended == 0 ) \ .order_by((SubForums.id == 31).desc(), SubForums.subcommon_name) \ .all() guestsubforums = None else: guestsubforums = db.session \ .query(SubForums) \ .filter(SubForums.age_required == 0) \ .filter(SubForums.type_of_subcommon == 0) \ .filter(SubForums.room_banned == 0, SubForums.room_deleted == 0, SubForums.room_suspended == 0 ) \ .order_by(SubForums.total_exp_subcommon.desc()) \ .limit(20) usersubforums = None # if sub is private and user is a mod/owner if useramod: reportedposts = db.session \ .query(ReportedPosts) \ .filter(ReportedPosts.subcommon_name == subname) \ .count() reportedcomments = db.session \ .query(ReportedComments) \ .filter(ReportedComments.subcommon_name == subname) \ .count() else: reportedposts = 0 reportedcomments = 0 if current_user.is_authenticated: mainpostform = MainPostForm( CombinedMultiDict((request.files, request.form)), ) mainpostform.roomname.choices = \ [(str(row.subscriber.id), str(row.subscriber.subcommon_name)) for row in usersubforums] else: mainpostform = None # Get Stickies stickypostfrommods = db.session \ .query(CommonsPost) \ .filter(CommonsPost.subcommon_name == subname) \ .filter(CommonsPost.sticky == 1) \ .filter(CommonsPost.hidden == 0) \ .limit(2) # see if user is over age if current_user.is_authenticated: if current_user.over_age is False: post_18 = 0 allpost = 0 else: allpost = 0 post_18 = 1 else: post_18 = 0 allpost = 0 # POST QUERIES page = request.args.get('page', 1, type=int) posts = db.session \ .query(CommonsPost) \ .filter(CommonsPost.subcommon_name == subname) \ .filter(CommonsPost.hidden == 0) \ .filter(or_(CommonsPost.age == post_18, CommonsPost.age == allpost)) \ .filter(CommonsPost.sticky == 0) \ .order_by(CommonsPost.created.desc(), CommonsPost.hotness_rating_now.desc(), ) \ .paginate(page, app.config['POSTS_PER_PAGE'], False) next_url = url_for('subforum.sub', subname=subname, page=posts.next_num) \ if posts.has_next else None prev_url = url_for('subforum.sub', subname=subname, page=posts.prev_num) \ if posts.has_prev else None return render_template( 'subforums/sub.html', now=datetime.utcnow(), mainpostform=mainpostform, nsfwform=nsfwform, subname=subname, thenotescount=thenotescount, subform=subform, subinfobox=subinfobox, subcustom_stuff=subcustom_stuff, subcustom_setup=subcustom_setup, stickypostfrommods=stickypostfrommods, navlink=navlink, reportform=reportform, banuserdeleteform=banuserdeleteform, thesub=thesub, subid=subid, substats=substats, usersubforums=usersubforums, guestsubforums=guestsubforums, thenotes=thenotes, saved_subcommons=saved_subcommons, created_subcommons=created_subcommons, seeifsubbed=seeifsubbed, mods=mods, useramod=useramod, lockpostform=lockpostform, deletepostform=deletepostform, muteuserform=muteuserform, reportedposts=reportedposts, reportedcomments=reportedcomments, posts=posts.items, next_url=next_url, prev_url=prev_url, currentbchprice=currentbchprice, )
def profile_other_posts_all(user_name): # forms friendform = FriendForm() voteform = VoteForm() deleteposttextform = DeletePostTextForm() banuserdeleteform = QuickBanDelete() lockpostform = QuickLock() deletepostform = QuickDelete() muteuserform = QuickMute() navlink = 2 wall_post_form = MainPostForm( CombinedMultiDict((request.files, request.form))) subpostcommentform = CreateCommentQuickForm() theuser = db.session.query(User).filter( User.user_name == user_name).first() if theuser is None: flash('User does not exist', category='warning') return redirect( url_for('profile.main', user_name=current_user.user_name)) # see if blocked if current_user.is_authenticated: isuserblocked = BlockedUser.query\ .filter(BlockedUser.user_id == theuser.id, BlockedUser.blocked_user == current_user.id)\ .first() if isuserblocked: flash('User does not exist', category='warning') return redirect(url_for('index')) useraddresses = SavedAddresses.query.filter( SavedAddresses.user_id == theuser.id).first() usersubforums = db.session.query(Subscribed) usersubforums = usersubforums.join( SubForums, (Subscribed.subcommon_id == SubForums.id)) usersubforums = usersubforums.filter(theuser.id == Subscribed.user_id) usersubforums = usersubforums.filter(SubForums.id != 1) usersubforums = usersubforums.filter(SubForums.age_required == 0) usersubforums = usersubforums.filter(SubForums.room_deleted != 1) usersubforums = usersubforums.filter(SubForums.room_suspended != 1) usersubforums = usersubforums.filter(SubForums.room_banned != 1) usersubforums = usersubforums.all() seeifmodding = db.session.query(Mods) seeifmodding = seeifmodding.filter(Mods.user_id == theuser.id) seeifmod = seeifmodding.all() moddingcount = seeifmodding.count() seeifownering = db.session.query(SubForums) seeifownering = seeifownering.filter( SubForums.creator_user_id == theuser.id) seeifownering = seeifownering.filter(SubForums.room_deleted != 1) seeifowner = seeifownering.all() ownercount = seeifownering.count() # get followers get_followers = db.session.query(User) get_followers = get_followers.join(Followers, (User.id == Followers.followed_id)) get_followers = get_followers.filter(Followers.follower_id == theuser.id) get_followers = get_followers.limit(9) # get users posts userposts = db.session.query(CommonsPost) userposts = userposts.filter(CommonsPost.subcommon_id == 1) userposts = userposts.filter(CommonsPost.user_name == theuser.user_name) userposts = userposts.filter(CommonsPost.poster_user_id != theuser.id) userposts = userposts.filter(CommonsPost.hidden == 0) userposts = userposts.order_by(CommonsPost.created.desc()) posts = userposts.limit(50) postcount = userposts.count() expcount = db.session.query(ExpTable).filter( ExpTable.user_id == theuser.id).count() userexp = db.session.query(ExpTable).filter( ExpTable.user_id == theuser.id).order_by(ExpTable.id.desc()).limit(5) return render_template( 'users/profile/profile_other.html', useraddresses=useraddresses, wall_post_form=wall_post_form, postcount=postcount, voteform=voteform, subpostcommentform=subpostcommentform, usersubforums=usersubforums, seeifmod=seeifmod, ownercount=ownercount, seeifowner=seeifowner, moddingcount=moddingcount, banuserdeleteform=banuserdeleteform, lockpostform=lockpostform, deletepostform=deletepostform, muteuserform=muteuserform, friendform=friendform, deleteposttextform=deleteposttextform, posts=posts, navlink=navlink, theuser=theuser, user_name=user_name, get_followers=get_followers, expcount=expcount, userexp=userexp, )