def downvote_post(postid): """ downvote post """ # get the post by its id str_post_id = str(postid) if request.method == 'POST': getpost = db.session.query(CommonsPost).filter( CommonsPost.id == postid).first() getcurrentsub = db.session.query(SubForums) \ .filter(SubForums.id == getpost.subcommon_id) \ .first() subid = getcurrentsub.id subtype = getcurrentsub.type_of_subcommon # see if user already voted or not seeifvoted = db.session.query(PostUpvotes) \ .filter(PostUpvotes.user_id == current_user.id, PostUpvotes.post_id == postid) \ .first() seeifbanned = db.session.query(Banned) \ .filter(current_user.id == Banned.user_id, Banned.subcommon_id == subid) \ .first() # add to user stats post_owner_stats = db.session.query(UserStats) \ .filter(UserStats.user_id == getpost.user_id) \ .first() if subtype == 1: seeifuserinvited = db.session.query(PrivateMembers) \ .filter(current_user.id == PrivateMembers.user_id, PrivateMembers.subcommon_id == subid) \ .first() else: seeifuserinvited = 0 if getpost is None: return jsonify({ 'result': 'Post has been deleted or doesnt exist', 'thepostid': str_post_id, 'newnumber': 0 }) elif getpost.hidden == 1: return jsonify({ 'result': 'Post has been deleted', 'thepostid': str_post_id, 'newnumber': getpost.hotness_rating_now }) elif getpost.locked == 1: return jsonify({ 'result': 'Post has been locked.', 'thepostid': str_post_id, 'newnumber': getpost.hotness_rating_now }) elif getpost.user_id == current_user.id: return jsonify({ 'result': 'You cannot upvote your own posts.', 'thepostid': str_post_id, 'newnumber': getpost.hotness_rating_now }) elif seeifvoted is not None: return jsonify({ 'result': 'You already voted', 'thepostid': str_post_id, 'newnumber': getpost.hotness_rating_now }) # if user on banned list turn him away elif seeifbanned is not None: return jsonify({ 'result': 'You were banned from this room.', 'thepostid': str_post_id, 'newnumber': getpost.hotness_rating_now }) # if sub is private elif subtype == 1: # if user is not on the list turn him away if seeifuserinvited is None: return jsonify({ 'result': 'Room Is a private Community.', 'thepostid': str_post_id, 'newnumber': getpost.hotness_rating_now }) else: pass else: currentdownvotes = getpost.downvotes_on_post # add the vote to current votes newvotes_down = currentdownvotes - 1 # set post variable to this new post number getpost.downvotes_on_post = newvotes_down # subtract from downvotes getpostexp = getpost.upvotes_on_post + newvotes_down # set exp number to exp_commons getpost.total_exp_commons = getpostexp # current hotness rating currenthotness = getpost.hotness_rating_now newhotness = currenthotness - 1 getpost.hotness_rating_now = newhotness # add stats to voter exppoint(user_id=current_user.id, category=8) exppoint(user_id=getpost.user_id, category=4) # daily challnge if current_user.is_authenticated: daily_challenge(user_id=current_user.id, category=3) # add to user stats current_downvotes_posts = post_owner_stats.post_downvotes new_downvotes_posts = current_downvotes_posts + 1 post_owner_stats.post_downvotes = new_downvotes_posts # add user_id to vote create_new_vote = PostUpvotes(user_id=current_user.id, post_id=getpost.id, vote_up=0, vote_down=1) newvotenumber = getpost.highest_exp_reached - 1 # add and commit db.session.add(create_new_vote) db.session.add(getpost) db.session.add(post_owner_stats) db.session.commit() if seeifvoted is None: return jsonify({ 'result': 'Downvoted!', 'thepostid': str_post_id, 'newnumber': newvotenumber }) else: return jsonify({ 'result': 'You already voted', 'thepostid': str_post_id, 'newnumber': getpost.hotness_rating_now })
def downvote_comment(commentid): """ upvote post """ # get the post by its id if request.method == 'POST': # get the comment getcomment = db.session.query(Comments) \ .filter(Comments.id == commentid) \ .first() # get the post post = db.session.query(CommonsPost) \ .filter(CommonsPost.id == getcomment.commons_post_id) \ .first() # see if user voted seeifvoted = db.session.query(CommentsUpvotes) \ .filter(CommentsUpvotes.user_id == current_user.id, CommentsUpvotes.comment_id == getcomment.id) \ .first() # get the current sub getcurrentsub = db.session.query(SubForums) \ .filter(SubForums.subcommon_name == post.subcommon_name) \ .first() # get comment user stats comment_owner_stats = db.session.query(UserStats) \ .filter(UserStats.user_id == getcomment.user_id) \ .first() # see if banned or if private seeifbanned = db.session.query(Banned) \ .filter(current_user.id == Banned.user_id, Banned.subcommon_id == getcurrentsub.id) \ .first() # set easy variables subid = getcurrentsub.id subtype = getcurrentsub.type_of_subcommon str_comment_id = str(commentid) if post is None: return jsonify({ 'result': 'Post has been removed or not found.', 'thecommentid': str_comment_id, 'newnumber': None }) if getcomment is None: return jsonify({ 'result': 'Comment does not exist.', 'thecommentid': str_comment_id, 'newnumber': None }) if post.hidden == 1: return jsonify({ 'result': post.id, 'thecommentid': str_comment_id, 'newnumber': None }) if post.locked == 1: return jsonify({ 'result': 'Post has been locked.', 'thecommentid': str_comment_id, 'newnumber': None }) if getcomment.user_id == current_user.id: return jsonify({ 'result': 'You can not vote on your own comments.', 'thecommentid': str_comment_id, 'newnumber': None }) if seeifvoted is not None: return jsonify({ 'result': 'You have already voted.', 'thecommentid': str_comment_id, 'newnumber': None }) if getcurrentsub is None: return jsonify({ 'result': 'Room does not exist.', 'thecommentid': str_comment_id, 'newnumber': None }) # if user on banned list turn him away if seeifbanned is not None: return jsonify({ 'result': 'You are banned from this room.', 'thecommentid': str_comment_id, 'newnumber': None }) # if room is private if subtype == 1: seeifuserinvited = db.session.query(PrivateMembers).filter( current_user.id == PrivateMembers.user_id, PrivateMembers.subcommon_id == subid).first() # if user is not on the list turn him away if seeifuserinvited is None: return jsonify({ 'result': 'Room is a private community!', 'thecommentid': str_comment_id, 'newnumber': None }) currentdownvotes = getcomment.downvotes_on_comment # add the vote to current votes newvotes_down = currentdownvotes - 1 # set post variable to this new post number getcomment.downvotes_on_comment = newvotes_down # subtract from downvotes newvotes_up = getcomment.upvotes_on_comment getcommentexp = newvotes_up + newvotes_down # set exp number to exp_commons getcomment.total_exp_commons = getcommentexp # number used to show ajax response # It takes the current exp (upvotes - downvotes) then adds 1 # downvote comment newvotenumber = getcomment.total_exp_commons # # raise all in path for thread votes down # if getcomment.comment_parent_id is None: # # get comments of this comment and raise there thread downvotes for sorting purposes # getrelativecomments = db.session.query(Comments)\ # .filter(Comments.path.like(getcomment.path + '%')) # for comment in getrelativecomments: # comment.thread_downvotes = newvotes_down # db.session.add(comment) # # getcomment.thread_downvotes = newvotes_down # db.session.add(getcomment) # add to user stats current_downvotes_comment = comment_owner_stats.comment_downvotes new_downvotes_comment = current_downvotes_comment + 1 comment_owner_stats.comment_downvotes = new_downvotes_comment # daily challnge if current_user.is_authenticated: daily_challenge(user_id=current_user.id, category=4) # add exp points exppoint(user_id=current_user.id, category=8) exppoint(user_id=getcomment.user_id, category=4) # add user_id to vote so user doesnt double vote create_new_vote = CommentsUpvotes( user_id=current_user.id, comment_id=getcomment.id, ) db.session.add(comment_owner_stats) db.session.add(getcomment) db.session.add(create_new_vote) db.session.commit() if seeifvoted is not None: return jsonify({ 'result': 'You have already voted.', 'thecommentid': str_comment_id, 'newnumber': None }) else: return jsonify({ 'result': 'Downvoted!', 'thecommentid': str_comment_id, 'newnumber': newvotenumber })
def promotepost_xmr(subname, postid): """ Promotes a post # xmr """ if request.method == 'POST': form_xmr = CreatePromotePostXmr() now = datetime.utcnow() # get the sub, post, comment thesub = db.session.query(SubForums).filter( SubForums.subcommon_name == subname).first() post = db.session.query(CommonsPost).get(postid) # see if user has enough userwallet_xmr = db.session.query(MoneroWallet) userwallet_xmr = userwallet_xmr.filter( MoneroWallet.user_id == current_user.id) userwallet_xmr = userwallet_xmr.first() # get amount donated getcurrentprice_xmr = db.session.query(MoneroPrices).get(1) xmr_current_price_usd = getcurrentprice_xmr.price if post.shared_post != 0: idofpost = post.shared_post else: idofpost = post.id seeifpostpromotions = PostPromotions.query.\ filter(PostPromotions.post_id == idofpost)\ .first() if thesub is None: flash("Sub does not exist.", category="success") return redirect(url_for('index')) if post is None: flash("Post does not exist.", category="success") return redirect( url_for('subforum.sub', subname=thesub.subcommon_name)) if post.hidden == 1: flash("Post has been removed.", category="success") return redirect( url_for('subforum.sub', subname=thesub.subcommon_name)) # get user stats if form_xmr.validate_on_submit(): if form_xmr.submit.data: seeifcoin = re.compile(btcamount) doesitmatch = seeifcoin.match(form_xmr.custom_amount.data) if doesitmatch: xmr_amount_for_submission = Decimal( form_xmr.custom_amount.data) decimalform_of_amount = floating_decimals( xmr_amount_for_submission, 12) xmr_amount = decimalform_of_amount # get usd amount getcurrentprice = db.session.query(MoneroPrices).get(1) bt = (Decimal(getcurrentprice.price) * xmr_amount) formatteddollar = '{0:.2f}'.format(bt) usd_amount = formatteddollar else: flash( "Invalid Amount. Did you not enter the amount correctly?", category="danger") return redirect( url_for('promote.promotepost', subname=subname, postid=postid)) elif form_xmr.cent_xmr.data: xmr_amount = Decimal(0.01) / Decimal(xmr_current_price_usd) usd_amount = 0.01 elif form_xmr.quarter_xmr.data: xmr_amount = Decimal(0.25) / Decimal(xmr_current_price_usd) usd_amount = 0.25 elif form_xmr.dollar_xmr.data: xmr_amount = Decimal(1.00) / Decimal(xmr_current_price_usd) usd_amount = 1.00 elif form_xmr.five_dollar_xmr.data: xmr_amount = Decimal(5.00) / Decimal(xmr_current_price_usd) usd_amount = 5.00 elif form_xmr.ten_dollar_xmr.data: xmr_amount = Decimal(10.00) / Decimal(xmr_current_price_usd) usd_amount = 10.00 elif form_xmr.twentyfive_dollar_xmr.data: xmr_amount = Decimal(25.00) / Decimal(xmr_current_price_usd) usd_amount = 25.00 elif form_xmr.hundred_dollar_xmr.data: xmr_amount = Decimal(100.00) / Decimal(xmr_current_price_usd) usd_amount = 100.00 else: flash("Post Promotion Failure.", category="success") return redirect(url_for('index')) final_amount_xmr = (floating_decimals(xmr_amount, 12)) if Decimal(userwallet_xmr.currentbalance) >= Decimal(xmr_amount): if final_amount_xmr > 0: createnewpomotion = PostPromote( created=now, created_user_id=current_user.id, created_user_name=current_user.user_name, subcommon_id=thesub.id, subcommon_name=thesub.subcommon_name, post_id=idofpost, amount_bch=0, amount_btc=0, amount_xmr=final_amount_xmr, amount_usd=usd_amount) db.session.add(createnewpomotion) db.session.commit() changeuserxmrstats = db.session.query(UserStatsXMR)\ .filter_by(user_id=current_user.id)\ .first() # add stats to user who donated # coin current_amount_donated_to_posts = changeuserxmrstats.total_donated_to_postcomments_xmr newamount = (floating_decimals( current_amount_donated_to_posts + final_amount_xmr, 12)) changeuserxmrstats.total_donated_to_postcomments_xmr = newamount # usd current_amount_donated_to_posts_usd = changeuserxmrstats.total_donated_to_postcomments_usd newamount_usd = (floating_decimals( current_amount_donated_to_posts_usd + Decimal(usd_amount), 2)) changeuserxmrstats.total_donated_to_postcomments_usd = newamount_usd if seeifpostpromotions is None: addstatstopost = PostPromotions( post_id=idofpost, total_recieved_bch=0, total_recieved_bch_usd=0, total_recieved_btc=0, total_recieved_btc_usd=0, total_recieved_xmr=final_amount_xmr, total_recieved_xmr_usd=usd_amount, ) db.session.add(addstatstopost) else: # modify post to show it got xmr current_post_xmr_amount = seeifpostpromotions.total_recieved_xmr current_amount_xmr_usd_amount = seeifpostpromotions.total_recieved_xmr_usd newamount_for_post = (floating_decimals( current_post_xmr_amount + final_amount_xmr, 12)) newamount_for_post_usd = (floating_decimals( current_amount_xmr_usd_amount + Decimal(usd_amount), 2)) # set post to active and update post seeifpostpromotions.total_recieved_xmr = newamount_for_post seeifpostpromotions.total_recieved_xmr_usd = newamount_for_post_usd db.session.add(seeifpostpromotions) # create Wallet Transaction for both users sendcointosite_post_promotion_xmr( sender_id=current_user.id, amount=final_amount_xmr, postid=postid, room=subname) post.active = 1 post.last_active = now db.session.add(post) db.session.add(changeuserxmrstats) # daily challnge if current_user.is_authenticated: daily_challenge(user_id=current_user.id, category=6) # send notification you got a coin promotion add_new_notification( user_id=post.poster_user_id, subid=post.subcommon_id, subname=post.subcommon_name, postid=post.id, commentid=0, msg=62, ) db.session.commit() flash( "Successfully Promoted Post with Monero. In a few minutes the score will be updated.", category="success") return redirect( url_for('subforum.viewpost', subname=thesub.subcommon_name, postid=post.id)) else: flash("Invalid Amount.", category="danger") return redirect( url_for('promote.promotepost', subname=subname, postid=postid)) else: flash("Not enough coin in your wallet.", category="danger") return redirect( url_for('promote.promotepost', subname=subname, postid=postid)) else: flash("Invalid Amount.", category="danger") return redirect( url_for('promote.promotepost', subname=subname, postid=postid))
def create_tip_post_bch(subname, postid): """ Creates a bch tip for a post """ form_bch = CreateTipBCH() now = datetime.utcnow() # get the sub, post, comment thesub = db.session\ .query(SubForums)\ .filter(SubForums.subcommon_name == subname)\ .first() post = db.session\ .query(CommonsPost)\ .get(postid) if post.shared_post != 0: idofpost = post.shared_post else: idofpost = post.id if thesub is None: flash("Sub does not exist", category="success") return redirect((request.args.get('next', request.referrer))) if post is None: flash("The post has been removed or doesnt exist", category="success") return redirect((request.args.get('next', request.referrer))) if post.hidden == 1: flash("Post Has been deleted", category="success") return redirect((request.args.get('next', request.referrer))) # get user stats changeuserbchstats = db.session\ .query(UserStatsBCH)\ .filter_by(user_id=current_user.id)\ .first() # get poster stats changeposterbchstats = db.session\ .query(UserStatsBCH)\ .filter_by(user_id=post.content_user_id)\ .first() if request.method == 'POST': if form_bch.validate_on_submit(): # check to see if tipper != poster if post.content_user_id != current_user.id: # get amount donatred getcurrentprice = db.session\ .query(BchPrices)\ .get(1) bch_current_price_usd = getcurrentprice.price usercoinsamount = db.session\ .query(BchWallet)\ .filter(BchWallet.user_id == current_user.id)\ .first() if form_bch.submit.data: seeifcoin = re.compile(btcamount) doesitmatch = seeifcoin.match(form_bch.custom_amount.data) varidoftip = 0 variable_amount = True if doesitmatch: bch_amount_for_submission = Decimal( form_bch.custom_amount.data) decimalform_of_amount = floating_decimals( bch_amount_for_submission, 8) bch_amount = decimalform_of_amount # get usd amount bt = (Decimal(getcurrentprice.price) * bch_amount) formatteddollar = '{0:.2f}'.format(bt) usd_amount = formatteddollar else: flash( "Invalid coin amount. Did you enter the amount wrong?", category="danger") return redirect( url_for('tip.create_tip_post', subname=subname, postid=postid)) elif form_bch.cent.data: bch_amount = Decimal(0.01) / Decimal(bch_current_price_usd) usd_amount = 0.01 varidoftip = 0 variable_amount = True elif form_bch.quarter.data: bch_amount = Decimal(0.25) / Decimal(bch_current_price_usd) usd_amount = 0.25 varidoftip = 0 variable_amount = True elif form_bch.dollar.data: bch_amount = Decimal(1.00) / Decimal(bch_current_price_usd) usd_amount = 1.00 varidoftip = 0 variable_amount = True elif form_bch.five_dollar.data: bch_amount = Decimal(5.00) / Decimal(bch_current_price_usd) usd_amount = 5.00 varidoftip = 0 variable_amount = True elif form_bch.ten_dollar.data: bch_amount = Decimal(10.00) / Decimal( bch_current_price_usd) usd_amount = 10.00 varidoftip = 0 variable_amount = True elif form_bch.twentyfive_dollar.data: bch_amount = Decimal(25.00) / Decimal( bch_current_price_usd) usd_amount = 25.00 varidoftip = 0 variable_amount = True elif form_bch.hundred_dollar.data: bch_amount = Decimal(100.00) / Decimal( bch_current_price_usd) usd_amount = 100.00 varidoftip = 0 variable_amount = True elif form_bch.seven_zero.data: bch_amount = Decimal(0.00000001) usd_amount = 0.00 variable_amount = False varidoftip = 1 elif form_bch.six_zero.data: bch_amount = Decimal(0.00000010) usd_amount = 0.00 varidoftip = 2 variable_amount = False elif form_bch.five_zero.data: bch_amount = Decimal(0.00000100) usd_amount = 0.00 varidoftip = 3 variable_amount = False else: flash("Tip Failure.", category="success") return redirect( url_for('tip.create_tip_post', subname=subname, postid=postid)) final_amount = (floating_decimals(bch_amount, 8)) lowestdonation = 0.00000100 if final_amount >= lowestdonation: percent_to_subowner = 0.07 payout = 1 else: percent_to_subowner = 0 payout = 0 if Decimal(usercoinsamount.currentbalance) >= Decimal( final_amount): if variable_amount is True: # btc amount amount_to_subowner = Decimal(final_amount) * Decimal( percent_to_subowner) # get usd amount subownerbt = (Decimal(getcurrentprice.price) * amount_to_subowner) subownerformatteddollar = '{0:.2f}'.format(subownerbt) subowner_usd_amount = float(subownerformatteddollar) # Btc amount amount_to_poster = Decimal(final_amount) - Decimal( amount_to_subowner) # get usd amount posterbt = (Decimal(getcurrentprice.price) * bch_amount) posterformatteddollar = '{0:.2f}'.format(posterbt) poster_usd_amount = float(posterformatteddollar) else: if varidoftip == 1: # btc_amount = 0.00000001 poster_usd_amount = 0.00 amount_to_poster = Decimal(0.00000001) amount_to_subowner = Decimal(0) subowner_usd_amount = 0.00 elif varidoftip == 2: # btc_amount = 0.00000010 poster_usd_amount = 0.00 amount_to_poster = Decimal(0.00000009) amount_to_subowner = Decimal(0.00000001) subowner_usd_amount = 0.00 elif varidoftip == 3: # btc_amount = 0.00000100 poster_usd_amount = 0.00 amount_to_poster = Decimal(0.00000093) amount_to_subowner = Decimal(0.00000007) subowner_usd_amount = 0.00 else: poster_usd_amount = 0.00 amount_to_poster = Decimal(0.00000000) amount_to_subowner = Decimal(0) subowner_usd_amount = 0.00 if payout == 1: # subowner gets payout newpayout = PayoutSubOwner( created=now, subcommon_id=thesub.id, subcommon_name=thesub.subcommon_name, post_id=post.id, comment_id=0, sub_owner_user_id=thesub.creator_user_id, sub_owner_user_name=thesub.creator_user_name, tipper_user_id=current_user.id, tipper_user_name=current_user.user_name, currency_type=2, amount_bch=amount_to_subowner, amount_usd=subowner_usd_amount, ) db.session.add(newpayout) createnewtip = BchPostTips( created=now, created_user_id=current_user.id, created_user_name=current_user.user_name, recieved_user_id=post.content_user_id, recieved_user_name=post.content_user_name, subcommon_id=thesub.id, subcommon_name=thesub.subcommon_name, post_id=idofpost, amount_bch=amount_to_poster, amount_usd=poster_usd_amount, ) createrecenttip = RecentTips( created=now, created_user_id=current_user.id, created_user_name=current_user.user_name, recieved_user_id=post.content_user_id, recieved_user_name=post.content_user_name, subcommon_id=thesub.id, subcommon_name=thesub.subcommon_name, post_id=idofpost, comment_id=0, currency_type=2, amount_bch=amount_to_poster, amount_usd=poster_usd_amount, ) # add stats to user who donated current_amount_donated_to_comments = changeuserbchstats.total_donated_to_postcomments_bch newamount = (floating_decimals( current_amount_donated_to_comments + final_amount, 8)) changeuserbchstats.total_donated_to_postcomments_bch = newamount current_amount_donated_to_comments_usd = changeuserbchstats.total_donated_to_postcomments_usd newamount_usd = (floating_decimals( current_amount_donated_to_comments_usd + Decimal(usd_amount), 2)) changeuserbchstats.total_donated_to_postcomments_usd = newamount_usd # add stats to user who recieved coin current_amount_recieved_to_posts = changeposterbchstats.total_recievedfromposts_bch newamount_poster = (floating_decimals( current_amount_recieved_to_posts + amount_to_poster, 8)) changeposterbchstats.total_recievedfromposts_bch = newamount_poster current_amount_recieved_to_posts_usd = changeposterbchstats.total_recievedfromposts_usd newamount_poster_usd = (floating_decimals( current_amount_recieved_to_posts_usd + Decimal(poster_usd_amount), 2)) changeposterbchstats.total_recievedfromposts_usd = newamount_poster_usd seeifpostdonates = db.session\ .query(PostDonations)\ .filter(PostDonations.post_id == idofpost)\ .first() if seeifpostdonates is None: addstatstopost = PostDonations( post_id=idofpost, total_recieved_btc=0, total_recieved_btc_usd=0, total_recieved_bch=final_amount, total_recieved_bch_usd=usd_amount, ) db.session.add(addstatstopost) else: # modify comments to show it got btc current_post_bch_amount = seeifpostdonates.total_recieved_bch current_amount_bch_usd_amount = seeifpostdonates.total_recieved_bch_usd newamount_for_post = (floating_decimals( current_post_bch_amount + amount_to_poster, 8)) newamount_for_post_usd = (floating_decimals( current_amount_bch_usd_amount + Decimal(poster_usd_amount), 2)) seeifpostdonates.total_recieved_bch = newamount_for_post seeifpostdonates.total_recieved_bch_usd = newamount_for_post_usd db.session.add(seeifpostdonates) add_new_notification(user_id=post.content_user_id, subid=thesub.id, subname=thesub.subcommon_name, postid=idofpost, commentid=0, msg=20) if payout == 1: add_new_notification(user_id=thesub.creator_user_id, subid=thesub.id, subname=thesub.subcommon_name, postid=post.id, commentid=0, msg=26) # add exp points to donater exppoint(user_id=current_user.id, category=5) # add exp points to reciever exppoint(user_id=post.content_user_id, category=6) # create Wallet Transaction for both users take_coin_from_tipper_bch_post( sender_id=current_user.id, amount=final_amount, postid=idofpost, recieverid=post.content_user_id) # create Wallet Transaction for both users sendcoin_to_poster_bch_post( sender_id=current_user.id, amount=amount_to_poster, postid=idofpost, recieverid=post.content_user_id) if payout == 1: # create Wallet Transaction for both users sendcoin_subowner_bch_post( sender_id=current_user.id, amount=amount_to_subowner, postid=idofpost, recieverid=thesub.creator_user_id) # daily challnge if current_user.is_authenticated: daily_challenge(user_id=current_user.id, category=7) post.last_active = now post.active = 1 db.session.add(createrecenttip) db.session.add(createnewtip) db.session.add(post) db.session.add(changeposterbchstats) db.session.add(changeuserbchstats) db.session.commit() flash("Tip was successful.", category="success") return redirect( url_for('subforum.viewpost', subname=thesub.subcommon_name, postid=post.id)) else: flash("Insufficient Funds.", category="danger") return redirect( url_for('tip.create_tip_post', subname=subname, postid=postid)) else: flash( "Cannot tip yourself. You can promote your posts to boost visibility. ", category="success") return redirect( url_for('subforum.viewpost', subname=thesub.subcommon_name, postid=post.id)) else: flash("Invalid Form", category="success") return redirect( url_for('subforum.viewpost', subname=thesub.subcommon_name, postid=post.id)) return redirect( url_for('subforum.viewpost', subname=thesub.subcommon_name, postid=post.id))
def promotepost_coin(subname, postid, coinid): """ Promotes a post """ if request.method == 'POST': givecoinform = GiveCoin() # get the sub, post, comment thesub = db.session.query(SubForums).filter( SubForums.subcommon_name == subname).first() post = CommonsPost.query.get(postid) if post.shared_post != 0: idofpost = post.shared_post else: idofpost = post.id thecoins = PostCoins.query.filter( PostCoins.post_id == idofpost).first() if thesub is None: flash("Sub does not exist.", category="success") return redirect(url_for('index')) if post is None: flash("Post does not exist.", category="success") return redirect( url_for('subforum.sub', subname=thesub.subcommon_name)) if post.hidden == 1: flash("Post has been removed.", category="success") return redirect( url_for('subforum.sub', subname=thesub.subcommon_name)) # get user stats if givecoinform.validate_on_submit(): usercoin = db.session.query(UserCoins).filter( UserCoins.coin_id == coinid, UserCoins.user_id == current_user.id).first() if usercoin is not None: # give coin to post if thecoins is None: newcoinstable = PostCoins( post_id=idofpost, coin_1=0, coin_2=0, coin_3=0, coin_4=0, coin_5=0, coin_6=0, coin_7=0, coin_8=0, coin_9=0, coin_10=0, ) db.session.add(newcoinstable) db.session.commit() thecoins = PostCoins.query.filter( PostCoins.post_id == idofpost).first_or_404() if coinid == 1: new_amount = thecoins.coin_1 + 1 thecoins.coin_1 = new_amount elif coinid == 2: new_amount = thecoins.coin_2 + 1 thecoins.coin_2 = new_amount elif coinid == 3: new_amount = thecoins.coin_3 + 1 thecoins.coin_3 = new_amount elif coinid == 4: new_amount = thecoins.coin_4 + 1 thecoins.coin_4 = new_amount elif coinid == 5: new_amount = thecoins.coin_5 + 1 thecoins.coin_5 = new_amount elif coinid == 6: new_amount = thecoins.coin_6 + 1 thecoins.coin_6 = new_amount elif coinid == 7: new_amount = thecoins.coin_7 + 1 thecoins.coin_7 = new_amount elif coinid == 8: new_amount = thecoins.coin_8 + 1 thecoins.coin_8 = new_amount elif coinid == 9: new_amount = thecoins.coin_9 + 1 thecoins.coin_9 = new_amount else: flash("Coin Does not exist", category="success") return redirect( url_for('subforum.viewpost', subname=thesub.subcommon_name, postid=post.id)) db.session.add(post) # subtract or delete users coin currentcoinamount = usercoin.quantity - 1 if currentcoinamount == 0: db.session.delete(usercoin) db.session.commit() else: usercoin.quantity = currentcoinamount db.session.add(usercoin) db.session.commit() # daily challnge if current_user.is_authenticated: daily_challenge(user_id=current_user.id, category=5) # send notification you got a coin promotion add_new_notification( user_id=post.poster_user_id, subid=post.subcommon_id, subname=post.subcommon_name, postid=post.id, commentid=0, msg=60, ) # commit db.session.commit() flash("You have promoted the post!", category="success") return redirect( url_for('subforum.viewpost', subname=thesub.subcommon_name, postid=post.id)) else: flash("You do not have this coin to give", category="success") return redirect( url_for('subforum.viewpost', subname=thesub.subcommon_name, postid=post.id)) else: flash("Invalid Form", category="success") return redirect( url_for('subforum.viewpost', subname=thesub.subcommon_name, postid=post.id))