from ..flask_extend import Blueprint from flask import request from ..utils import templated, redirect from ..model import db, Category mod = Blueprint('categories', __name__) @mod.route("/", methods=("GET", "POST")) @templated() def manage (): if request.method == "GET": categories = Category.query.order_by(Category.name).all() return { 'cats' : categories } else: for id, name in request.form.iteritems(): if id.startswith("n-"): db.session.add(Category(name = name)) else: Category.get(id).name = name db.session.commit() return redirect(".manage")