def create():
    form = AttributeEditingForm(request.form)
    if request.method == "POST" and form.validate():
        db.session().add(Attribute(name=form.name.data))
        db.session().commit()
        flash("Attribute added")
        return redirect(url_for("general.admin"))
    return render_template("edit_attribute.html", form=form, heading="New attribute")
def edit(id):
    try:
        attr = db.session().query(Attribute).filter(Attribute.id == id).one()
    except NoResultFound:
        return render_template("layout.html", error="No such atribute")

    form = AttributeEditingForm(request.form)
    if request.method == "GET":
        form.name.data = attr.name
        form.id.data = attr.id

    if request.method == "POST" and form.validate():
        attr.name = form.name.data
        db.session().add(attr)
        db.session().commit()
        flash("Attribute saved")
        return redirect(url_for("general.admin"))

    return render_template("edit_attribute.html", form=form, heading="Edit attribute")