示例#1
0
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
                })
示例#2
0
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
            })
示例#3
0
def create_post_room_all(userid):

    now = datetime.utcnow()
    id_pic1 = id_generator_picture1()
    wall_post_form = MainPostForm()
    uniqueid = id_generator(size=15)

    if request.method == 'POST':

        usersubforums = db.session \
            .query(Subscribed) \
            .join(SubForums, (Subscribed.subcommon_id == SubForums.id)) \
            .filter(current_user.id == Subscribed.user_id) \
            .all()

        wall_post_form.roomname.choices = [(str(row.subscriber.id),
                                            str(row.subscriber.subcommon_name))
                                           for row in usersubforums]

        theuser = User.query \
            .filter(User.id == userid) \
            .first()
        getuser_timers = db.session \
            .query(UserTimers) \
            .filter_by(user_id=current_user.id) \
            .first()
        user_stats = db.session \
            .query(UserStats) \
            .filter(UserStats.user_id == current_user.id) \
            .first()

        if wall_post_form.validate_on_submit():

            # see if user posted comment
            if wall_post_form.post_message.data == '':
                score_1 = 0
            else:
                score_1 = 1
            if wall_post_form.image_one.data:
                score_2 = 1
            else:
                score_2 = 0
            total_score = score_1 + score_2

            if total_score == 0:
                flash("You need to post some content", category="success")
                return redirect((request.args.get('next', request.referrer)))

            getmatchingsubcommon = db.session \
                .query(SubForums) \
                .filter(SubForums.id == int(wall_post_form.roomname.data)) \
                .first()

            chosen_subcommon_id = getmatchingsubcommon.id
            chosen_subcommon_name = getmatchingsubcommon.subcommon_name

            newpostnumber = user_stats.total_posts + 1

            urlfound, urltitlefound, urldescriptionfound, urlimagefound = \
                geturl(wall_post_form.post_message.data)
            transformed_text, notifyuser = \
                transform_image_links_markdown(str(wall_post_form.post_message.data))
            # add post to db
            newpost = CommonsPost(
                title=wall_post_form.post_title.data,
                user_id=theuser.id,
                user_name=theuser.user_name,

                # location
                realid=uniqueid,
                subcommon_id=chosen_subcommon_id,
                subcommon_name=chosen_subcommon_name,
                type_of_post=0,

                # text
                post_text=transformed_text,

                # url
                url_of_post=urlfound,
                url_description=urldescriptionfound,
                url_image=urlimagefound,
                url_title=urltitlefound,
                url_image_server='',

                # images
                image_server_1='',

                # stats
                total_exp_commons=0,
                highest_exp_reached=0,
                upvotes_on_post=0,
                comment_count=0,
                vote_timestamp=now,
                last_active=now,
                hotness_rating_now=0,
                page_views=0,

                # admin
                sticky=0,
                active=1,
                locked=0,
                hidden=0,
                muted=0,
                created=now,
                edited=now,
            )

            getuser_timers.last_post = now
            user_stats.total_posts = newpostnumber

            db.session.add(user_stats)
            db.session.add(getuser_timers)
            db.session.add(newpost)
            db.session.commit()

            getusernodelocation = postnodelocation(x=newpost.id)
            postlocation = os.path.join(UPLOADED_FILES_DEST, current_disk,
                                        "post", getusernodelocation,
                                        str(newpost.id))

            # image from url
            if urlfound:
                post_get_image(url=newpost.url_image,
                               imagelocation=postlocation,
                               thepost=newpost)

            # image From User
            if wall_post_form.image_one.data:
                mkdir_p(path=postlocation)
                filename = secure_filename(
                    wall_post_form.image_one.data.filename)
                postimagefilepath = os.path.join(postlocation, filename)
                wall_post_form.image_one.data.save(postimagefilepath)
                # split file name and ending
                filenamenew, file_extension = os.path.splitext(
                    postimagefilepath)
                # gets new 64 digit filename
                newfilename = id_pic1 + file_extension
                # puts new name with ending
                filenamenewfull = filenamenew + file_extension
                # gets aboslute path of new file
                newfilenamedestination = os.path.join(postlocation,
                                                      newfilename)
                # renames file
                os.rename(filenamenewfull, newfilenamedestination)
                post_convert_image(imagelocation=postlocation,
                                   imagename=newfilename,
                                   thepost=newpost)

            if wall_post_form.image_one.data \
                    or (urlimagefound is not None and urlfound is not None):
                db.session.commit()

            if notifyuser is not None:
                # add info
                add_new_notification(user_id=notifyuser.id,
                                     subid=newpost.subcommon_id,
                                     subname=newpost.subcommon_name,
                                     postid=newpost.id,
                                     commentid=0,
                                     msg=32)

            # add exp points
            exppoint(user_id=current_user.id, category=1)

            return redirect((url_for('subforum.viewpost',
                                     subname=newpost.subcommon_name,
                                     postid=newpost.id)))
        else:

            flash("Post Creation Failure.", category="danger")
            for errors in wall_post_form.roomname.errors:
                flash(errors, category="danger")
            for errors in wall_post_form.post_message.errors:
                flash(
                    "Message Failure...a message is required and 3- 5000 characters",
                    category="danger")
                flash(errors, category="danger")
            for errors in wall_post_form.image_one.errors:
                flash(errors, category="danger")
            return redirect((request.args.get('next', request.referrer)))
示例#4
0
def createsubforum():
    """
    Creates a subcommon
    """
    form = CreateSubcommonForm()

    now = datetime.utcnow()

    currentbchprice = BchPrices.query.get(1)

    usersubforums = db.session.query(Subscribed) \
        .join(SubForums, (Subscribed.subcommon_id == SubForums.id)) \
        .filter(current_user.id == Subscribed.user_id) \
        .filter(SubForums.id != 1) \
        .filter(SubForums.room_banned == 0,
                SubForums.room_deleted == 0,
                SubForums.room_suspended == 0
                ) \
        .all()

    if request.method == 'GET':
        return render_template(
            'create/subforum/create_subforum.html',
            form=form,
            usersubforums=usersubforums,
            currentbchprice=currentbchprice,
        )

    elif request.method == 'POST':

        if form.validate_on_submit():

            name_of_subcommon = form.subcommonname.data
            description_of_subcommon = form.subcommondescription.data
            exp_req = 0
            subtype = 1

            # create subcommon
            newcommon = SubForums(
                subcommon_name=str(name_of_subcommon),
                creator_user_id=current_user.id,
                creator_user_name=current_user.user_name,
                created=now,
                description=str(description_of_subcommon),
                type_of_subcommon=subtype,
                exp_required=int(exp_req),
                age_required=0,
                allow_text_posts=1,
                allow_url_posts=1,
                allow_image_posts=1,
                total_exp_subcommon=0,
                members=1,
                mini_image='',
                room_banned=0,
                room_suspended=0,
                room_deleted=0,
            )

            db.session.add(newcommon)
            db.session.commit()
            # create Sub Stats
            substats = SubForumStats(
                subcommon_name=str(name_of_subcommon),
                subcommon_id=newcommon.id,
                total_posts=0,
                total_exp_subcommon=0,
                members=1,
            )

            # sub customization ie banner
            newsubcustom = SubForumCustom(
                subcommon_name=str(name_of_subcommon),
                subcommon_id=newcommon.id,
                banner_image='',
                mini_image='',
            )

            # subscribe user to that forum
            newsubscription = Subscribed(
                user_id=current_user.id,
                subcommon_id=newcommon.id,
            )

            exppoint(user_id=current_user.id, category=7)

            db.session.add(newsubcustom)
            db.session.add(substats)
            db.session.add(newsubscription)
            db.session.commit()
            flash("Room created.", category="success")

            return redirect(
                url_for('subforum.sub', subname=newcommon.subcommon_name))
        else:
            for errors in form.subcommonname.errors:
                flash(errors, category="danger")
            for errors in form.subcommondescription.errors:
                flash(errors, category="danger")
            return redirect((request.args.get('next', request.referrer)))
示例#5
0
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))