diff --git a/nummi/main/urls.py b/nummi/main/urls.py index f5637cc..ba79575 100644 --- a/nummi/main/urls.py +++ b/nummi/main/urls.py @@ -3,7 +3,7 @@ from django.urls import path from . import views urlpatterns = [ - path("", views.index, name="index"), + path("", views.IndexView.as_view(), name="index"), path("login", views.LoginView.as_view(), name="login"), path("logout", views.LogoutView.as_view(), name="logout"), path("transactions", views.TransactionListView.as_view(), name="transactions"), diff --git a/nummi/main/views.py b/nummi/main/views.py index 23016be..10ecf1b 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -12,7 +12,13 @@ from django.db import models from django.http import HttpResponse from django.shortcuts import get_object_or_404, redirect, render from django.urls import reverse_lazy -from django.views.generic import CreateView, DeleteView, ListView, UpdateView +from django.views.generic import ( + CreateView, + DeleteView, + ListView, + TemplateView, + UpdateView, +) from django.views.generic.edit import ProcessFormView from .models import ( @@ -27,18 +33,15 @@ from .models import ( ) -@login_required -def index(request): - _transactions = Transaction.objects.all()[:10] - _categories = Category.objects.all() - _snapshots = Snapshot.objects.all() +class IndexView(LoginRequiredMixin, TemplateView): + template_name = "main/index.html" - context = { - "transactions": _transactions, - "categories": _categories, - "snapshots": _snapshots, - } - return render(request, "main/index.html", context) + def get_context_data(self, **kwargs): + return super().get_context_data(**kwargs) | { + "transactions": Transaction.objects.all()[:10], + "categories": Category.objects.all(), + "snapshots": Snapshot.objects.all(), + } class LoginView(auth_views.LoginView):