Beispiel #1
0
def art_add():
    form = ArtForm()
    if form.validate_on_submit():
        data = form.data
        print(data['category'],)
        if data['category'] == 1:
            category = '租房'
        if data['category'] == 2:
            category = '二手房'
        if data['category'] == 3:
            category = '商业地产'
        # 保存数据
        art = House(
            name= data['name'],
            category= category,
            number= data['number'],
            company= data['company'],
            address= data['address'],
            shop_address= data['shop_address'],
            created_time=datetime.datetime.now()
        )
        field.session.add(art)
        field.session.commit()
        flash(u"添加成功", 'ok')
    return render_template('art_add.html', title=u'添加', form=form)
Beispiel #2
0
def art_add():
    form = ArtForm()
    if form.validate_on_submit():
        data = form.data
        # 上传logo
        # uploads里面存的是图片文件
        # 数据库里存的是uploads里面的图片的文件名
        file = secure_filename(form.logo.data.filename)
        logo = change_name(file)
        # logo是时间加唯一标志服加图片文件后缀
        if not os.path.exists(app.config["UP"]):
            os.makedirs(app.config["UP"])
        form.logo.data.save(app.config["UP"] + "/" + logo)

        # 获取用户ID
        user = User.query.filter_by(name=session["user"]).first()
        user_id = user.id

        # 保存数据
        art = Art(
            title=data["title"],
            cate=data["cate"],
            user_id=user_id,
            logo=logo,
            content=data["content"],
            addtime=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        db.session.add(art)
        db.session.commit()
        flash(u"发布文章成功", "ok")

    return render_template("art_add.html", title=u"发布文章", form=form)
Beispiel #3
0
def art_add():
    form = ArtForm()
    if form.validate_on_submit():
        data = form.data
        # 上传logo
        file = secure_filename(form.logo.data.filename)
        logo = change_name(file)
        if not os.path.exists(app.config['UP']):
            os.makedirs(app.config["UP"])

        # 保存文件
        form.logo.data.save(app.config["UP"] + "/" + logo)
        # 获取用户ID
        user = User.query.filter_by(name=session["user"]).first()
        user_id = user.id
        # 保存数据
        art = Art(
            title=data["title"],
            cate=data["cate"],
            user_id=user_id,
            logo=logo,
            content=data["content"],
            addtime=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        )
        db.session.add(art)
        db.session.commit()
        flash("Post Article Successfully!", "ok")
    return render_template('art_add.html', title="Post Article", form=form)