예제 #1
0
def user():
    form = UserForm(request.form)
    if request.method == 'POST' and form.validate():
        user_id = current_user.get_id()
        user = User.select_user_by_id(user_id)
        with db.session.begin(subtransactions=True):
            user.username = form.username.data
            user.email = form.email.data
            file = request.files[form.picture_path.name].read()
            if file:
                file_name = user_id + '_' + \
                    str(int(datetime.now().timestamp())) + '.jpg'
                picture_path = 'flaskr/static/user_image/' + file_name
                open(picture_path, 'wb').write(file)
                user.picture_path = 'user_image/' + file_name
        db.session.commit()
        flash('ユーザ情報の更新に成功しました')
    return render_template('user.html', form=form)
예제 #2
0
def user():
    journals = Journal.query.all()
    like_journals = LikeJournal.query.all()
    form = UserForm(request.form)

    if request.method == 'POST' and form.validate():
        user_id = current_user.get_id()
        user = User.select_user_by_id(user_id)
        with db.session.begin(subtransactions=True):
            file = request.files[form.picture_path.name].read()
            if file:
                file_name = user_id + '_' + \
                    str(int(datetime.now().timestamp())) + '.jpg'
                picture_path = 'flaskr/static/image_user/' + file_name
                open(picture_path, 'wb').write(file)
                user.picture_path = 'image_user/' + file_name
        db.session.commit()
        flash('User info update completed.')
    return render_template('user/user.html',
                           like_journals=like_journals,
                           journals=journals,
                           form=form)
예제 #3
0
def user():
    like_albums = LikeAlbum.query.all()
    like_songs = LikeSong.query.all()

    albums = Album.query.all()
    artists = Artist.query.all()

    form = UserForm(request.form)
    if request.method == 'POST' and form.validate():
        user_id = current_user.get_id()
        user = User.select_user_by_id(user_id)
        with db.session.begin(subtransactions=True):
            file = request.files[form.picture_path.name].read()
            if file:
                file_name = user_id + '_' + \
                    str(int(datetime.now().timestamp())) + '.jpg'
                picture_path = 'flaskr/static/image_user/' + file_name
                open(picture_path, 'wb').write(file)
                # Upload
                storage.child(f"image_user/{file_name}").put(
                    f"flaskr/static/image_user/{file_name}")
                # Download
                user.picture_path = storage.child(
                    f"image_user/{file_name}").get_url(
                        f"flaskr/static/image_user/{file_name}")
                print("---------------")
                print(user.picture_path)
        db.session.commit()
        return redirect(url_for('user.user'))
        flash('User info update completed.')
    return render_template('user/user.html',
                           like_albums=like_albums,
                           like_songs=like_songs,
                           albums=albums,
                           artists=artists,
                           form=form)