예제 #1
0
def edit_profile():
    form = UploadPhotoForm()
    if form.validate_on_submit():
        f = form.photo.data
        if f.filename == '':
            flash('No selected file.', category='danger')
            return render_template('edit_profile.html', form=form)
        if f and allowed_file(f.filename):
            filename = secure_filename(f.filename)
            f.save(os.path.join('app', 'static', 'assets', filename))
            current_user.avatar_img = '/static/assets/' + filename
            db.session.commit()
            return redirect(
                url_for('user_page', username=current_user.username))
    return render_template('edit_profile.html', form=form)
예제 #2
0
파일: app.py 프로젝트: calvinhla/wanderlust
def upload_photos(username, iso, album_title):
    form = UploadPhotoForm()
    album = AlbumManager.get_album(g.user.id, album_title)
    if form.validate_on_submit():
        for file in form.image.data:
            if 'image' not in file.mimetype:
                form.image.errors.append('Images only!')
                return render_template('form.html', form=form)

        filenames = add_photos(
            username, iso, album.title, form.image.data
        )  # returns an array of urls linking to the uploaded images

        for name in filenames:
            db.session.add(
                Photo(user_id=g.user.id, album_id=album.id, image=name))
            db.session.commit()
        return redirect(
            url_for('show_album_photos',
                    username=username,
                    iso=iso,
                    album_title=album_title))

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