Example #1
0
def account():

    form = UpdateUserForm()

    if form.validate_on_submit():

        if form.picture.data:
            username = current_user.username
            pic = add_profile_pic(form.picture.data, username)
            current_user.profile_image = pic

        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('User Account Updated!')
        return redirect(url_for('users.account'))

    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email

    profile_image = url_for('static',
                            filename='profile_pics/' +
                            current_user.profile_image)
    return render_template('account.html',
                           profile_image=profile_image,
                           form=form)
Example #2
0
def account():

    form = UpdateUserForm()
    if form.validate_on_submit():

        # handle picture upload
        if form.picture.data:  # if they upload picture data
            username = current_user.username
            pic = add_profile_pic(form.picture.data, username)
            current_user.profile_image = pic

        # POST
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('User Account Updated!')
        return redirect(url_for('users.account'))

    # user is not submitting anything
    # we are grabbing their current information
    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email

    # grab the profile image and send it to template to render
    profile_image = url_for('static',
                            filename='profile_pics/' +
                            current_user.profile_image)
    return render_template('account.html',
                           profile_image=profile_image,
                           form=form)
Example #3
0
def account():

    form = UpdateUserForm()

    if form.validate_on_submit():
        #in forms.py/UpdateUserForm we have a picture attribute
        #this statement gets activated

        if form.picture.data:
            #grab the current_username
            username = current_user.username
            #grab the png/jpeg file and pass it to add_profile_pic()
            #picture_handler.py / add_profile_pic
            #renames the file, sves it and saves as thumbnail
            pic = add_profile_pic(form.picture.data, username)
            #models.py/User/profile_image attribute , which is a string
            current_user.profile_image = pic

        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('User Account Updated')
        return redirect(url_for('users.account'))

    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email

    profile_image = url_for('static',
                            filename='profile_pics/' +
                            current_user.profile_image)
    return render_template('account.html',
                           profile_image=profile_image,
                           form=form)
Example #4
0
def account():

    form = UpdateUserForm()

    if form.validate_on_submit():

        if form.picture.data:
            username = current_user.username
            pic = add_profile_pic(form.picture.data, username)
            # pic will have name of the pic i.e. username.png or .jpg
            current_user.profile_image = pic
            # assigned pic name to profile_image of the user in the model

        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('User Account Updated!')

        return redirect(url_for('users.account'))

    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email

    # just to show the profile image on the account page, grabbing it using path
    profile_image = url_for('static',
                            filename='profile_pics/' +
                            current_user.profile_image)

    return render_template('account.html',
                           profile_image=profile_image,
                           form=form)
Example #5
0
def account():
    form = UpdateUserForm()
    
    if form.validate_on_submit():
        print("post request and valid submit")
        
        if form.picture.data is not None:
            print("picture")
            print(form.picture.data)
            username = current_user.username
            pic = add_profile_pic(form.picture.data, username)
            current_user.profile_image = pic 
        
        current_user.username = form.username.data
        current_user.email = form.email.data 
        db.session.commit()

        flash("User Account Updated! ")
        return redirect(url_for('users.account'))

    elif request.method == "GET":
        print("get request")
        #get request 
        #get the users current username , and email and prepolulate form 
        form.username.data = current_user.username
        form.email.data = current_user.email
        #get the current image in profile  
        profile_image = url_for('static',filename='profile_pics/'+current_user.profile_image)


    print("Post request and invalid submit") 
    profile_image = url_for('static',filename='profile_pics/'+current_user.profile_image)
    return render_template("account.html" , profile_image = profile_image , form = form)
Example #6
0
def account():
    form = UpdateUserForm()
    if form.validate_on_submit():

        #画像がセットされているか
        if form.picture.data:
            username = current_user.username
            pic = add_profile_pic(form.picture.data, username)
            current_user.profile_image = pic

        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('User Account Updated!')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email

    now = datetime.now()
    epochtime = str(now.timestamp())
    profile_image = url_for('static',
                            filename='profile_pics/' +
                            current_user.profile_image) + "?" + epochtime
    return render_template('account.html',
                           profile_image=profile_image,
                           form=form,
                           epochtime=epochtime)
Example #7
0
def account():

    form = UpdateUserForm()

    if form.validate_on_submit():
        print(form)
        if form.picture.data:
            #if they uploaded picture data
            username = current_user.username
            #taking current username if they uploaded a picture
            pic = add_profile_pic(form.picture.data, username)
            #taking the picture data and their username and passing it to the func we created
            current_user.profile_image = pic
            #in our User model they have profile_img which is just a string of the filename

        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('User Account Updated')
        return redirect(url_for('users.account'))

    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
        #this means they are not submitting anything so we just want their current info

    profile_image = url_for('static',
                            filename='profile_pics/' +
                            current_user.profile_image)
    #default image unless they have updated it
    return render_template('account.html',
                           profile_image=profile_image,
                           form=form)
def account():

    form = UpdateUserForm()

    if form.validate_on_submit():

        #if user uploaded a picture
        if form.picture.data:
            #grab current username
            username = current_user.username

            #(grab data from picture and username) pass it to the add_profile_pic function
            pic = add_profile_pic(form.picture.data, username)

            #default is changed to user's picture
            current_user.profile_image = pic

        current_user.username = form.username.data
        current_user.email = form.email.data

        db.session.commit()
        flash('User Account Updated')
        return redirect(url_for('users.account'))

    elif request.method == 'GET':
        #not submitting anything, just getting current username ******
        form.username.data = current_user.username
        form.email.data = current_user.email
    #goes to static folder under profile_pics get the current user's profile image
    profile_image = url_for('static',
                            filename='profile_pics/' +
                            current_user.profile_image)

    return render_template('account.html',
                           profile_image=profile_image,
                           form=form)