33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
from decimal import Decimal, InvalidOperation
|
|
|
|
from django.views.generic import TemplateView
|
|
|
|
from core.models import Subject
|
|
from core.prediction import predict_all, predict_balance
|
|
|
|
|
|
class BalanceView(TemplateView):
|
|
template_name = "core/balance.html"
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
amount, amount_error = Decimal(), False
|
|
if amount_query := self.request.GET.get("amount"):
|
|
try:
|
|
amount = Decimal(amount_query)
|
|
except InvalidOperation:
|
|
amount_error = True
|
|
context["amount"] = round(amount, 2)
|
|
context["amount_error"] = amount_error
|
|
context["future_transactions"] = predict_balance(amount)
|
|
return context
|
|
|
|
|
|
class SubjectsView(TemplateView):
|
|
template_name = "core/subjects.html"
|
|
|
|
def get_context_data(self, **kwargs):
|
|
context = super().get_context_data(**kwargs)
|
|
context["prediction_list"] = predict_all(Subject.objects.order_by("name"))
|
|
return context
|