<reponame>black-redoc/trackash
from django.shortcuts import render
from django.contrib.auth.mixins import LoginRequiredMixin
from django.urls import reverse_lazy
from django.views import View
from django.views.generic.edit import CreateView

from .models import Budget, Income, Expense
from .forms import IncomeForm, ExpenseForm


class DashboardView(LoginRequiredMixin, View):
    budget = Budget.objects.first()
    context = {"budget": budget}

    def get(self, request, *args, **kwargs):
        return render(request, "budget/dashboard.html", self.context)


class IncomeCreateView(LoginRequiredMixin, CreateView):
    model = Income
    form_class = IncomeForm
    success_url = reverse_lazy("budget:dashboard")


class ExpenseCreateView(LoginRequiredMixin, CreateView):
    model = Expense
    form_class = ExpenseForm
    success_url = reverse_lazy("budget:dashboard")


def budget_view(request):
    return render(
        request,
        "budget/budget.html",
        {"foo": "bar", "name": "<NAME>"},
        content_type="text/html",
    )
