summaryrefslogtreecommitdiff
path: root/bak/unused_apps/budget/views.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2025-01-03 18:46:40 -0600
committerluxagraf <sng@luxagraf.net>2025-01-03 18:46:40 -0600
commitfe7d43f308bbc3953d4a88480b8088d12cbcb0b6 (patch)
tree3aa10d1ac8e041ad2b78a5acf6b29febad6a5fe3 /bak/unused_apps/budget/views.py
parentdf3bc581e496412ef8c263dbf1cfe00f184e4e59 (diff)
archived old not used apps
Diffstat (limited to 'bak/unused_apps/budget/views.py')
-rw-r--r--bak/unused_apps/budget/views.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/bak/unused_apps/budget/views.py b/bak/unused_apps/budget/views.py
new file mode 100644
index 0000000..6a34b1e
--- /dev/null
+++ b/bak/unused_apps/budget/views.py
@@ -0,0 +1,57 @@
+import datetime
+from django.shortcuts import render
+from django.views.generic.edit import CreateView, UpdateView
+from django.utils import timezone
+from utils.views import PaginatedListView
+from .models import LuxPurchase, LuxSource
+
+class LuxSourceModelFormView(CreateView):
+ model = LuxSource
+ fields = ['name']
+ success_url = '/spending/'
+ template_name = 'budget/create_cat_form.html'
+
+
+class PurchaseModelFormView(CreateView):
+ model = LuxPurchase
+ fields = ['amount', 'source', 'category']
+ success_url = '/spending/'
+ template_name = 'budget/create_form.html'
+
+
+class PurchaseUpdateView(UpdateView):
+ model = LuxPurchase
+ fields = ['amount', 'source', 'category']
+ success_url = '/spending/'
+ template_name = 'budget/update_form.html'
+
+
+class LuxPurchaseListView(PaginatedListView):
+ model = LuxPurchase
+
+ def get_queryset(self):
+ queryset = super(LuxPurchaseListView, self).get_queryset()
+ return queryset[:30]
+
+ def get_context_data(self, **kwargs):
+ '''
+ Get Monthly Spending for a nice bar chart
+ '''
+ # Call the base implementation first to get a context
+ context = super(LuxPurchaseListView, self).get_context_data(**kwargs)
+ context['monthly_spending'] = LuxPurchase.stats.get_monthly_spending()
+ today = timezone.now()
+ first = today.replace(day=1)
+ month_1 = first - datetime.timedelta(days=1)
+ month_2 = month_1.replace(day=1) - datetime.timedelta(days=1)
+ month_3 = month_2.replace(day=1) - datetime.timedelta(days=1)
+ context['month'] = today.strftime('%h')
+ context['monthly_spending_1'] = LuxPurchase.stats.get_monthly_spending(month_1.month)
+ context['month_1'] = month_1.strftime('%h')
+ context['monthly_spending_2'] = LuxPurchase.stats.get_monthly_spending(month_2.month)
+ context['month_2'] = month_2.strftime('%h')
+ context['monthly_spending_3'] = LuxPurchase.stats.get_monthly_spending(month_3.month)
+ context['month_3'] = month_3.strftime('%h')
+ context['food_total'] = LuxPurchase.stats.get_monthly_spending_by_category("Grocery/Home", 1)
+ context['lodge_total'] = LuxPurchase.stats.get_monthly_spending_by_category("Lodging", 1)
+ return context