Пример #1
0
def upload_image(user_id=0):
    image_form = ImageForm()
    image_form.user_id = user_id
    if request.method == 'POST':
        my_filename = secure_filename(image_form.image.data.filename)
        image_form.image.data.save(UPLOAD_IMAGE_PATH + my_filename)
        image_info = ImageInfo()
        image_info.user_id = user_id
        image_info.url = '/static/user_image/' + my_filename
        image_info.name = my_filename
        db.session.add(image_info)
        db.session.commit()
        flash(u'照片上传成功。')

    user = get_user_by_id(user_id)

    return render_template('admin/image_add.html', form=image_form, user_name=user.username)
Пример #2
0
def upload_video(user_id=0):
    video_form = VideoForm()
    video_form.user_id = user_id
    if request.method == 'POST':
        my_filename = secure_filename(video_form.video.data.filename)
        video_form.video.data.save(UPLOAD_VIDEO_PATH + my_filename)
        video_info = VideoInfo()
        video_info.user_id = user_id
        video_info.url = '/static/user_video/' + my_filename
        video_info.name = my_filename
        db.session.add(video_info)
        db.session.commit()
        flash(u'视频上传成功。')

    user = get_user_by_id(user_id)

    return render_template('admin/video_add.html', form=video_form, user_name=user.username)