コード例 #1
0
ファイル: star_view.py プロジェクト: holdlg/zlpress
def add_star():
    star_form = StarForm()
    if request.method == 'POST' and star_form.validate:
        f = request.files['photo']
        my_filename = secure_filename(f.filename)
        f.save(UPLOAD_IMAGE_PATH + my_filename)

        star = StarInfo()
        star_form.populate_obj(star)
        star.photo = '/static/user_image/' + my_filename
        db.session.add(star)
        db.session.commit()
        flash(u'明星信息添加成功!')

    return render_template('/admin/star_add.html', form=star_form)
コード例 #2
0
ファイル: star_view.py プロジェクト: holdlg/zlpress
def update_star(sid):
    star_info = StarInfo.query.filter_by(id=sid).first_or_404()
    star_form = StarForm(obj=star_info)
    photo_img_path = star_info.photo
    if request.method == 'POST' and star_form.validate:
        my_filename = secure_filename(star_form.photo.data.filename)
        if my_filename:
            star_form.photo.data.save(UPLOAD_IMAGE_PATH + my_filename)

            star_form.populate_obj(star_info)
            star_info.photo = '/static/user_image/' + my_filename
            # 赋值回显
            photo_img_path = star_info.photo
        else:
            star_form.populate_obj(star_info)
            star_info.photo = photo_img_path

        db.session.commit()
        flash(u'明星信息更新成功!')

    return render_template('/admin/star_update.html', form=star_form, photo_img_path=photo_img_path)