def account():

    form = UpdateUserForm()
    if form.validate_on_submit():
        print(form)
        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)
예제 #2
0
def account():

    form = UpdateUserForm()

    if form.validate_on_submit():

        ## for Profile picture
        if form.picture.data:
            username = current_user.username
            pic = add_profile_pic(form.picture.data, username)

            current_user.profile_image = pic  ## under User we have profile_image

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

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

    elif request.method == "GET":
        ## grab Information
        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)
예제 #3
0
def account():
    form = UpdateUserForm()
    if form.validate_on_submit():
        # Check if there is a picture upload
        if form.picture.data:
            username = current_user.username
            #pass to the add_profile_pic function in picture handler
            # where the image is saved to the static folder
            pic = add_profile_pic(form.picture.data, username)
            #set the image to the profile image attribute in the User
            current_user.profile_image = pic
        #set the username and email from the form data
        current_user.username = form.username.data
        current_user.email = form.email.data
        # save to the database
        db.session.commit()
        flash('User account updated')
        return redirect(url_for('core.index'))
    # First time page is hit get populate with the  current data
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    # The profile image will either be the unchanged image if it hasn't been updated
    # or the updated image saved to the static/profile_pic
    profile_image = url_for('static',
                            filename='profile_pics/' +
                            current_user.profile_image)
    return render_template('account.html',
                           form=form,
                           profile_image=profile_image)
예제 #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)
            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)
    page = request.args.get('page', 1, type=int)
    text_output = TextOutput.query.order_by(TextOutput.date.desc()).paginate(
        page=page, per_page=2)
    return render_template('account.html',
                           profile_image=profile_image,
                           form=form,
                           text_output=text_output)
예제 #5
0
def account():
    """Displays users account and updates it with new info if provided"""
    form = UpdateUserForm(
        # passes in current email and username so that it doesn't trigger
        # the unique constraint by updating
        orig_username=current_user.username,
        orig_email=current_user.email)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.email = form.email.data

        # checks if there is an image provided in form, handles it and
        # sets it as profile photo
        if form.picture.data:
            email = current_user.email
            pic = add_profile_pic(form.picture.data, email)
            current_user.profile_image = pic
        db.session.commit()
        flash("User account succesfully updated!", "success")
        return redirect(url_for("users.account"))

    # prepopulates the form fields with current data
    elif request.method == "GET":
        form.email.data = current_user.email
        form.username.data = current_user.username

    profile_image = url_for('static',
                            filename='profile_pics/' +
                            current_user.profile_image)

    return render_template("account.html",
                           profile_image=profile_image,
                           form=form)
예제 #6
0
def account():
    form = UpdateUserForm()
    if form.validate_on_submit():

        #Adding picture to the profie
        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)