Compare commits
2 Commits
e9504775d7
...
824e5bde0d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
824e5bde0d | ||
|
|
e449bc26ac |
21
app.py
21
app.py
@@ -443,10 +443,25 @@ def get_total_expense_for_list(list_id, start_date=None, end_date=None):
|
||||
|
||||
|
||||
def update_list_categories_from_form(shopping_list, form):
|
||||
category_ids = form.getlist("categories")
|
||||
raw_vals = form.getlist("categories")
|
||||
candidate_ids = set()
|
||||
|
||||
for v in raw_vals:
|
||||
if not v:
|
||||
continue
|
||||
v = v.strip()
|
||||
try:
|
||||
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 category_ids:
|
||||
cats = Category.query.filter(Category.id.in_(category_ids)).all()
|
||||
if candidate_ids:
|
||||
cats = Category.query.filter(Category.id.in_(candidate_ids)).all()
|
||||
shopping_list.categories.extend(cats)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user