mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-12-05 14:36:36 +01:00
Adding or editing a transaction used to fire "updated", which re-rendered the whole list. Saves now send "transactions_changed" with the saved ids. Lists with the transaction_mover behavior ask their own endpoint for just those rows (?only=<id>), and the server answers with where each row goes: the row after it and, for lists split by date, its divider. Rows it doesn't return have left the list and are removed. Covers the monthly overview, all transactions (a row joining or leaving the current page still reloads it), and the installment, recurring and calendar lists. Pages without a mover fall back to "updated".
88 lines
2.4 KiB
Python
88 lines
2.4 KiB
Python
import datetime
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
from django.shortcuts import redirect, render
|
|
from django.utils import timezone
|
|
from django.views.decorators.http import require_http_methods
|
|
|
|
from apps.calendar_view.utils.calendar import get_transactions_by_day
|
|
from apps.transactions.models import Transaction
|
|
from apps.transactions.utils.changed_rows import changed_rows
|
|
|
|
|
|
@login_required
|
|
def index(request):
|
|
now = timezone.localdate(timezone.now())
|
|
|
|
return redirect(to="calendar", month=now.month, year=now.year)
|
|
|
|
|
|
@login_required
|
|
@require_http_methods(["GET"])
|
|
def calendar(request, month: int, year: int):
|
|
if month < 1 or month > 12:
|
|
from django.http import Http404
|
|
|
|
raise Http404("Month is out of range")
|
|
|
|
next_month = 1 if month == 12 else month + 1
|
|
next_year = year + 1 if next_month == 1 and month == 12 else year
|
|
|
|
previous_month = 12 if month == 1 else month - 1
|
|
previous_year = year - 1 if previous_month == 12 and month == 1 else year
|
|
|
|
return render(
|
|
request,
|
|
"calendar_view/pages/calendar.html",
|
|
context={
|
|
"month": month,
|
|
"year": year,
|
|
"next_month": next_month,
|
|
"next_year": next_year,
|
|
"previous_month": previous_month,
|
|
"previous_year": previous_year,
|
|
},
|
|
)
|
|
|
|
|
|
@login_required
|
|
@require_http_methods(["GET"])
|
|
def calendar_list(request, month: int, year: int):
|
|
today = timezone.localdate(timezone.now())
|
|
dates = get_transactions_by_day(month=month, year=year)
|
|
|
|
return render(
|
|
request,
|
|
"calendar_view/fragments/list.html",
|
|
context={
|
|
"month": month,
|
|
"year": year,
|
|
"today": today,
|
|
"dates": dates,
|
|
},
|
|
)
|
|
|
|
|
|
@login_required
|
|
@require_http_methods(["GET"])
|
|
def calendar_transactions_list(request, day: int, month: int, year: int):
|
|
date = datetime.date(year=year, month=month, day=day)
|
|
transactions = Transaction.objects.filter(date=date).collapse_transfers().prefetch_related("sub_transactions").order_by(
|
|
"date",
|
|
"-type",
|
|
"-is_paid",
|
|
"id",
|
|
)
|
|
|
|
if "only" in request.GET:
|
|
return changed_rows(request, transactions, grouped=False)
|
|
|
|
return render(
|
|
request,
|
|
"calendar_view/fragments/list_transactions.html",
|
|
context={
|
|
"date": date,
|
|
"transactions": transactions,
|
|
},
|
|
)
|