diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-07-23 00:28:47 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2020-07-23 00:28:47 +0200 |
commit | 81493afa53a1a1d5ff4b417d05febf9f9e2a172b (patch) | |
tree | 00de0a1bb7c386cff4203aa7b0789569e75347bb /kosten/app/views/categories.py | |
parent | 6f6c8af2a55fabb69372e3fc4e8504167805d018 (diff) | |
download | kosten-81493afa53a1a1d5ff4b417d05febf9f9e2a172b.tar.gz kosten-81493afa53a1a1d5ff4b417d05febf9f9e2a172b.tar.bz2 kosten-81493afa53a1a1d5ff4b417d05febf9f9e2a172b.zip |
Restructure
Diffstat (limited to 'kosten/app/views/categories.py')
-rw-r--r-- | kosten/app/views/categories.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/kosten/app/views/categories.py b/kosten/app/views/categories.py new file mode 100644 index 0000000..47379ba --- /dev/null +++ b/kosten/app/views/categories.py @@ -0,0 +1,31 @@ +from . import Blueprint, db, \ + current_user, login_required, \ + templated, redirect, request + +from ..model import Category + +mod = Blueprint('categories', __name__) + +@mod.route('/', methods=('GET', 'POST')) +@login_required +@templated +def manage(): + """Workhorse: List and edit/create. For historic reasons, + everything is done in JavaScript. + + NB: No deletion possible yet. + """ + if request.method == 'GET': + categories = Category.of(current_user).order_by(Category.name).all() + + return { 'cats' : categories } + else: + for id, name in request.form.items(): + if id.startswith('n-'): + db.session.add(Category(name = name, user = current_user)) + else: + Category.get(id).name = name + + db.session.commit() + + return redirect('.manage') |