release nouri 0.5.0 shopping rhythm pwa and reminders
This commit is contained in:
+35
-6
@@ -4,7 +4,7 @@ from flask import Blueprint, flash, g, redirect, render_template, request, url_f
|
||||
from werkzeug.security import generate_password_hash
|
||||
|
||||
from .auth import admin_required, can_remove_last_admin, validate_admin_user_form
|
||||
from .constants import DEFAULT_CATEGORIES, ROLE_LABELS
|
||||
from .constants import BUILDER_DESCRIPTIONS, BUILDER_OPTIONS, DEFAULT_CATEGORIES, DEFAULT_CATEGORY_BUILDERS, ROLE_LABELS
|
||||
from .db import get_db
|
||||
|
||||
|
||||
@@ -197,6 +197,7 @@ def user_edit(user_id: int):
|
||||
def category_settings():
|
||||
if request.method == "POST":
|
||||
name = request.form.get("name", "").strip()
|
||||
builder_key = request.form.get("builder_key", "neutral").strip()
|
||||
if not name:
|
||||
flash("Bitte einen Kategorienamen eintragen.", "error")
|
||||
else:
|
||||
@@ -210,8 +211,8 @@ def category_settings():
|
||||
).fetchone()
|
||||
if existing:
|
||||
get_db().execute(
|
||||
"UPDATE household_categories SET is_active = 1 WHERE id = ?",
|
||||
(existing["id"],),
|
||||
"UPDATE household_categories SET is_active = 1, builder_key = ? WHERE id = ?",
|
||||
(builder_key, existing["id"]),
|
||||
)
|
||||
flash("Die Kategorie ist wieder aktiv.", "success")
|
||||
else:
|
||||
@@ -221,10 +222,10 @@ def category_settings():
|
||||
).fetchone()
|
||||
get_db().execute(
|
||||
"""
|
||||
INSERT INTO household_categories (household_id, name, sort_order, is_active)
|
||||
VALUES (?, ?, ?, 1)
|
||||
INSERT INTO household_categories (household_id, name, builder_key, sort_order, is_active)
|
||||
VALUES (?, ?, ?, ?, 1)
|
||||
""",
|
||||
(g.user["household_id"], name, int(sort_row["max_sort"]) + 10),
|
||||
(g.user["household_id"], name, builder_key, int(sort_row["max_sort"]) + 10),
|
||||
)
|
||||
flash("Die Kategorie wurde ergänzt.", "success")
|
||||
get_db().commit()
|
||||
@@ -234,6 +235,9 @@ def category_settings():
|
||||
"admin/categories.html",
|
||||
categories=fetch_household_categories(),
|
||||
default_categories=DEFAULT_CATEGORIES,
|
||||
default_category_builders=DEFAULT_CATEGORY_BUILDERS,
|
||||
builder_options=BUILDER_OPTIONS,
|
||||
builder_descriptions=BUILDER_DESCRIPTIONS,
|
||||
)
|
||||
|
||||
|
||||
@@ -260,3 +264,28 @@ def category_toggle(category_id: int):
|
||||
get_db().commit()
|
||||
flash("Die Kategorie wurde aktualisiert.", "success")
|
||||
return redirect(url_for("admin.category_settings"))
|
||||
|
||||
|
||||
@admin_bp.post("/categories/<int:category_id>/update")
|
||||
@admin_required
|
||||
def category_update(category_id: int):
|
||||
category = get_db().execute(
|
||||
"""
|
||||
SELECT *
|
||||
FROM household_categories
|
||||
WHERE id = ? AND household_id = ?
|
||||
""",
|
||||
(category_id, g.user["household_id"]),
|
||||
).fetchone()
|
||||
if category is None:
|
||||
flash("Die Kategorie wurde nicht gefunden.", "error")
|
||||
return redirect(url_for("admin.category_settings"))
|
||||
|
||||
builder_key = request.form.get("builder_key", "neutral").strip()
|
||||
get_db().execute(
|
||||
"UPDATE household_categories SET builder_key = ? WHERE id = ?",
|
||||
(builder_key, category_id),
|
||||
)
|
||||
get_db().commit()
|
||||
flash("Die Zuordnung wurde aktualisiert.", "success")
|
||||
return redirect(url_for("admin.category_settings"))
|
||||
|
||||
Reference in New Issue
Block a user