Esempio n. 1
0
def profilepicture():

    id_pic1 = id_generator_picture1()

    form = ProfilePicForm(CombinedMultiDict((request.files, request.form)), )
    user = User.query.filter_by(id=current_user.id).first()
    if request.method == 'POST':

        if form.delete.data and form.validate_on_submit():
            deleteuserprofileimage(user_id=user.id)
            return redirect((request.args.get('next', request.referrer)))

        if form.submit.data and form.validate_on_submit():

            getusernodelocation = userimagelocation(x=user.id)
            userlocation = os.path.join(UPLOADED_FILES_DEST, current_disk,
                                        'user', getusernodelocation,
                                        str(user.id))

            if form.imageprofile.data:
                try:
                    mkdir_p(path=userlocation)
                    deleteuserprofileimage(user_id=current_user.id)
                    filename = secure_filename(form.imageprofile.data.filename)
                    # makes directory (generic location + auction number id as folder)
                    # saves it to location
                    profileimagefilepath = os.path.join(userlocation, filename)
                    form.imageprofile.data.save(profileimagefilepath)
                    # RENAMING FILE
                    # split file name and ending
                    filenamenew, file_extension = os.path.splitext(
                        profileimagefilepath)
                    # 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(
                        userlocation, newfilename)
                    # renames file
                    os.rename(filenamenewfull, newfilenamedestination)
                    convert_profile_image(imagelocation=userlocation,
                                          imagename=newfilename)
                except Exception as e:
                    user.profileimage = "0"
                    flash("Error", category="success")
                    return redirect((request.args.get('next',
                                                      request.referrer)))
                if not form.imageprofile.data.filename:

                    user.profileimage = ""

                db.session.add(user)
                db.session.commit()
                flash("Profile has been changed", category="success")
                return redirect((request.args.get('next', request.referrer)))
        else:
            flash("Error.  No data submitted", category="danger")
            return redirect((request.args.get('next', request.referrer)))

    return render_template(
        'users/profile/profile_forms/profile_picture.html',
        form=form,
        user=user,
    )
Esempio n. 2
0
def post_edit_text(postid):
    now = datetime.utcnow()
    editposttextform = EditPostTextForm()
    id_pic1 = id_generator_picture1()

    thepost = db.session \
        .query(CommonsPost) \
        .filter(CommonsPost.id == int(postid)) \
        .first()

    if request.method == 'POST':

        if editposttextform.validate_on_submit():
            if editposttextform.delete.data:
                delete_image_server_one(user_id=current_user.id, postid=postid)
                return redirect((request.args.get('next', request.referrer)))

            if editposttextform.submit.data:
                urlfound, urltitlefound, urldescriptionfound, urlimagefound = geturl(editposttextform.postmessage.data)
                transformed_text, notifyuser = transform_image_links_markdown(str(editposttextform.postmessage.data))

                getpostnodelocation = postnodelocation(x=thepost.id)
                postlocation = os.path.join(UPLOADED_FILES_DEST,
                                            current_disk,
                                            "post",
                                            getpostnodelocation,
                                            str(thepost.id))
                thepost.post_text = transformed_text

                if urlfound:
                    delete_image_url_server(user_id=current_user.id, postid=postid)
                    thepost.url_image = urlimagefound
                    thepost.url_title = urltitlefound
                    thepost.url_of_post = urlfound
                    thepost.url_description = urldescriptionfound
                    post_get_image(url=thepost.url_image, imagelocation=postlocation, thepost=thepost)

                if editposttextform.image_one.data:
                    mkdir_p(path=postlocation)
                    filename = secure_filename(editposttextform.image_one.data.filename)
                    postimagefilepath = os.path.join(postlocation, filename)
                    editposttextform.image_one.data.save(postimagefilepath)
                    filenamenew, file_extension = os.path.splitext(postimagefilepath)
                    newfilename = id_pic1 + file_extension
                    filenamenewfull = filenamenew + file_extension
                    newfilenamedestination = os.path.join(postlocation, newfilename)
                    os.rename(filenamenewfull, newfilenamedestination)
                    post_convert_image(imagelocation=postlocation, imagename=newfilename, thepost=thepost)

                if notifyuser is not None:
                    # add info
                    add_new_notification(user_id=notifyuser.id,
                                         subid=thepost.subcommon_id,
                                         subname=thepost.subcommon_name,
                                         postid=thepost.id,
                                         commentid=0,
                                         msg=32
                                         )
            thepost.edited = now
            db.session.commit()

            flash("Post edited", category="success")
            return redirect(url_for('subforum.viewpost', subname=thepost.subcommon_name, postid=thepost.id))
        else:
            flash("form error")
            for errors in editposttextform.postmessage.errors:
                flash(errors, category="danger")
            return redirect((request.args.get('next', request.referrer)))
Esempio n. 3
0
def createcomment(subname, postid):
    """
    View / Reply to a post
    """
    comment_form = CreateCommentForm()
    uniqueid = id_generator(size=15)
    id_pic1 = id_generator_picture1()
    now = datetime.utcnow()
    currentbchprice = BchPrices.query.get(1)

    the_post = db.session \
        .query(CommonsPost) \
        .filter(CommonsPost.id == postid) \
        .first()
    getmatchingsubcommon = db.session \
        .query(SubForums) \
        .filter(SubForums.subcommon_name == subname) \
        .first()
    chosen_subcommon_id = getmatchingsubcommon.id
    chosen_subcommon_name = getmatchingsubcommon.subcommon_name

    if request.method == 'GET':
        return render_template(
            'comments/_comment.html',
            comment_form=comment_form,
            currentbchprice=currentbchprice,
        )

    if request.method == 'POST':

        # see if user posted comment
        if comment_form.post_message.data == '':
            score_1 = 0
        else:
            score_1 = 1
        if comment_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)))

        urlfound, urltitlefound, urldescriptionfound, urlimagefound = \
            geturl(comment_form.post_message.data)
        transformed_text, notifyuser = \
            transform_image_links_markdown(str(comment_form.post_message.data))

        new_reply_to_question = Comments(
            realid=uniqueid,
            # the id's
            commons_post_id=chosen_subcommon_id,
            subcommon_id=chosen_subcommon_name,
            created=now,
            # if answer is a right one
            accepted_answer=0,
            # user_name
            user_name=current_user.user_name,
            user_id=current_user.id,
            # stats
            total_exp_commons=0,
            upvotes_on_comment=0,
            downvotes_on_comment=0,
            # reported
            active=1,
            hidden=0,
            deleted=0,
            # donations
            total_recieved_bch=0,
            total_recieved_bch_usd=0,
            # the content
            url_image=urlimagefound,
            url_title=urltitlefound,
            url_of_post=urlfound,
            url_description=urldescriptionfound,
            url_image_server='',
            image_server_1='',
            body=transformed_text,
        )

        db.session.add(new_reply_to_question)

        db.session.commit()

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

        # image from url
        if urlfound:
            comment_get_image(url=new_reply_to_question.url_image,
                              imagelocation=comment_image_location,
                              the_comment=new_reply_to_question)

        # image From User
        if comment_form.image_one.data:
            mkdir_p(path=comment_image_location)
            filename = secure_filename(comment_form.image_one.data.filename)
            postimagefilepath = os.path.join(comment_image_location, filename)
            comment_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(comment_image_location,
                                                  newfilename)
            # renames file
            os.rename(filenamenewfull, newfilenamedestination)
            # convert image to right size and ending
            comment_convert_image(imagelocation=comment_image_location,
                                  imagename=newfilename,
                                  the_comment=new_reply_to_question)

        if comment_form.image_one.data \
                or (urlimagefound is not None and urlfound is not None):
            db.session.commit()
Esempio n. 4
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)))
Esempio n. 5
0
def bannerpicture(business_id):

    id_pic1 = id_generator_picture1()

    form = BannerPicForm(
        CombinedMultiDict((request.files, request.form)),
    )
    thebiz = db.session.query(Business).filter(Business.id == business_id).first()
    if current_user.id != thebiz.user_id:
        return redirect(url_for('index'))
    if request.method == 'POST':
        if current_user.id != thebiz.user_id:
            return redirect(url_for('index'))
        if form.delete.data and form.validate_on_submit():
            deletebannerimage(business_id=thebiz.id)
            return redirect((request.args.get('next', request.referrer)))

        if form.submit.data and form.validate_on_submit():
            getusernodelocation = userimagelocation(x=thebiz.id)
            userlocation = os.path.join(UPLOADED_FILES_DEST, current_disk, 'business', getusernodelocation, str(thebiz.id))

            if form.imageprofile.data:
                try:
                    # make a user a directory
                    mkdir_p(path=userlocation)
                    deletebannerimage(business_id=thebiz.id)
                    filename = secure_filename(form.imageprofile.data.filename)
                    # makes directory (generic location + auction number id as folder)
                    profileimagefilepath = os.path.join(userlocation, filename)
                    # saves it to location
                    form.imageprofile.data.save(profileimagefilepath)
                    # RENAMING FILE
                    # split file name and ending
                    filenamenew, file_extension = os.path.splitext(profileimagefilepath)
                    # 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(userlocation, newfilename)
                    # renames file
                    os.rename(filenamenewfull, newfilenamedestination)
                    convert_banner_image(imagelocation=userlocation, imagename=newfilename, business_id=thebiz.id)

                except Exception as e:
                    thebiz.bannerimage = ""
                    flash("Error", category="success")
                    return redirect((request.args.get('next', request.referrer)))

                if not form.imageprofile.data.filename:
                    thebiz.bannerimage = ''

                db.session.add(thebiz)
                db.session.commit()
                flash("Profile banner has been changed", category="success")
                return redirect((request.args.get('next', request.referrer)))
        else:
            flash("Error. No data submitted", category="danger")
            return redirect((request.args.get('next', request.referrer)))

    return render_template('business/edit/images/profile_banner.html',
                           form=form,
                           thebiz=thebiz,
                           )