fix przy nie wybraniu kategorii
This commit is contained in:
24
app.py
24
app.py
@@ -442,18 +442,28 @@ def get_total_expense_for_list(list_id, start_date=None, end_date=None):
|
||||
return query.scalar() or 0
|
||||
|
||||
|
||||
|
||||
def update_list_categories_from_form(shopping_list, form):
|
||||
cat = form.get("categories")
|
||||
shopping_list.categories.clear()
|
||||
if cat:
|
||||
raw_vals = form.getlist("categories")
|
||||
candidate_ids = set()
|
||||
|
||||
for v in raw_vals:
|
||||
if not v:
|
||||
continue
|
||||
v = v.strip()
|
||||
try:
|
||||
cid = int(cat)
|
||||
cats = Category.query.filter(Category.id == cid).all()
|
||||
shopping_list.categories.extend(cats)
|
||||
candidate_ids.add(int(v))
|
||||
continue
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
cat = Category.query.filter(func.lower(Category.name) == v.lower()).first()
|
||||
if cat:
|
||||
candidate_ids.add(cat.id)
|
||||
shopping_list.categories.clear()
|
||||
if candidate_ids:
|
||||
cats = Category.query.filter(Category.id.in_(candidate_ids)).all()
|
||||
shopping_list.categories.extend(cats)
|
||||
|
||||
|
||||
def generate_share_token(length=8):
|
||||
return secrets.token_hex(length // 2)
|
||||
|
Reference in New Issue
Block a user