1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
diff --git a/budget/views.py b/budget/views.py
index 567b95c0743eefde7782bb8dded67443a38bf530..45eff9a023d7afeb950604298d7ab4692c7dcb8c 100644
--- a/budget/views.py
+++ b/budget/views.py
@@ -1,14 +1,15 @@
+import json
+from datetime import date, datetime, timedelta
+
from django.conf import settings
+from django.contrib.auth.mixins import LoginRequiredMixin
+from django.http import HttpRequest, HttpResponse, JsonResponse
from django.shortcuts import render
-from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse
from django.views import View
-from django.http import HttpRequest, JsonResponse, HttpResponse
-from datetime import date, datetime, timedelta
-from .models import Transaction, Recurrence
-import json
-from .utils import prev_month_range, add_months
+from .models import Recurrence, Transaction
+from .utils import add_months, prev_month_range
BLUE = "#3788d8"
YELLOW = "#d4a574"
@@ -20,13 +21,17 @@
class IndexView(LoginRequiredMixin, View):
def get(self, request: HttpRequest) -> HttpResponse:
- return render(request, "budget/index.html", {
- "json_ctx": {
- "debug": settings.DEBUG,
- "adminIndex": reverse("admin:index"),
- "showAdmin": request.user.is_staff,
- }
- })
+ return render(
+ request,
+ "budget/index.html",
+ {
+ "json_ctx": {
+ "debug": settings.DEBUG,
+ "adminIndex": reverse("admin:index"),
+ "showAdmin": request.user.is_staff,
+ }
+ },
+ )
class EventsView(LoginRequiredMixin, View):
@@ -68,7 +73,6 @@ return JsonResponse(events, safe=False)
class TransactionView(LoginRequiredMixin, View):
-
def post(self, request: HttpRequest) -> HttpResponse:
data = json.loads(request.body)
props = data["extendedProps"]
@@ -114,9 +118,14 @@
class CopyView(View):
def post(self, request: HttpRequest):
- month = json.loads(request.body)["month"]
- first, last = prev_month_range(month)
- transactions = Transaction.objects.filter(date__range=[first, last], recurrence__in=[Recurrence.WEEK, Recurrence.MONTH])
+ data = json.loads(request.body)
+ month = data["month"]
+ year = data["year"]
+ first, last = prev_month_range(month, year)
+ transactions = Transaction.objects.filter(
+ date__range=[first, last],
+ recurrence__in=[Recurrence.WEEK, Recurrence.MONTH],
+ )
for transaction in transactions:
if transaction.recurrence == Recurrence.MONTH:
transaction.id = None
@@ -133,4 +142,4 @@ transaction.id = None
transaction.save()
else:
break
- return HttpResponse()
\ No newline at end of file
+ return HttpResponse()
|