mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-12-05 14:36:36 +01:00
feat(transactions): prefill add and transfer forms from query parameters
transaction_add accepts account and entities; transactions_transfer accepts from_account and to_account. Applied only when present.
This commit is contained in:
1 parent
4d494549b7
commit
1b9ea452d9
1 file changed
+13
@@ -119,6 +119,15 @@ def transaction_attachment_delete(request, attachment_id):
|
||||
return response
|
||||
|
||||
|
||||
def _prefill(request, *fields, entities=False):
|
||||
"""Form initial values passed as query parameters; only the named ones, and
|
||||
only when present, so they never override other defaults."""
|
||||
initial = {name: request.GET[name] for name in fields if request.GET.get(name)}
|
||||
if entities and request.GET.getlist("entities"):
|
||||
initial["entities"] = request.GET.getlist("entities") # entity names
|
||||
return initial
|
||||
|
||||
|
||||
@only_htmx
|
||||
@login_required
|
||||
@require_http_methods(["GET", "POST"])
|
||||
@@ -204,6 +213,8 @@ def transaction_add(request):
|
||||
initial={
|
||||
"date": expected_date,
|
||||
"type": transaction_type,
|
||||
# Optional prefill, e.g. a dividend from the investments page
|
||||
**_prefill(request, "account", entities=True),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -541,6 +552,8 @@ def transactions_transfer(request):
|
||||
initial={
|
||||
"reference_date": expected_date,
|
||||
"date": expected_date,
|
||||
# Optional prefill, e.g. buy/sell from the investments page
|
||||
**_prefill(request, "from_account", "to_account"),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in new issue
Block a user