mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-06-06 22:52:51 +02:00
feat: add actions
This commit is contained in:
@@ -2,6 +2,21 @@ from django.urls import path
|
||||
import apps.transactions.views as views
|
||||
|
||||
urlpatterns = [
|
||||
path(
|
||||
"transactions/actions/pay",
|
||||
views.bulk_pay_transactions,
|
||||
name="transactions_bulk_pay",
|
||||
),
|
||||
path(
|
||||
"transactions/actions/unpay/",
|
||||
views.bulk_unpay_transactions,
|
||||
name="transactions_bulk_unpay",
|
||||
),
|
||||
path(
|
||||
"transactions/actions/delete/",
|
||||
views.bulk_delete_transactions,
|
||||
name="transactions_bulk_delete",
|
||||
),
|
||||
path(
|
||||
"transaction/<int:transaction_id>/pay",
|
||||
views.transaction_pay,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from .transactions import *
|
||||
from .tags import *
|
||||
from .categories import *
|
||||
from .actions import *
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.http import HttpResponse
|
||||
|
||||
from apps.common.decorators.htmx import only_htmx
|
||||
from apps.transactions.models import Transaction
|
||||
|
||||
|
||||
@only_htmx
|
||||
@login_required
|
||||
def bulk_pay_transactions(request):
|
||||
selected_transactions = request.GET.getlist("transactions", [])
|
||||
Transaction.objects.filter(id__in=selected_transactions).update(is_paid=True)
|
||||
|
||||
return HttpResponse(
|
||||
status=204,
|
||||
headers={"HX-Trigger": "updated, toast, paid"},
|
||||
)
|
||||
|
||||
|
||||
@only_htmx
|
||||
@login_required
|
||||
def bulk_unpay_transactions(request):
|
||||
selected_transactions = request.GET.getlist("transactions", [])
|
||||
Transaction.objects.filter(id__in=selected_transactions).update(is_paid=False)
|
||||
|
||||
return HttpResponse(
|
||||
status=204,
|
||||
headers={"HX-Trigger": "updated, toast, unpaid"},
|
||||
)
|
||||
|
||||
|
||||
@only_htmx
|
||||
@login_required
|
||||
def bulk_delete_transactions(request):
|
||||
selected_transactions = request.GET.getlist("transactions", [])
|
||||
Transaction.objects.filter(
|
||||
id__in=selected_transactions, installment_plan__isnull=True
|
||||
).delete()
|
||||
|
||||
return HttpResponse(
|
||||
status=204,
|
||||
headers={"HX-Trigger": "updated, toast"},
|
||||
)
|
||||
Reference in New Issue
Block a user