Switched index view to class-based

This commit is contained in:
Edgar P. Burkhart 2022-12-28 12:38:20 +01:00
parent a722165ee2
commit bcbf33984b
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
2 changed files with 16 additions and 13 deletions

View file

@ -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"),

View file

@ -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,
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(),
}
return render(request, "main/index.html", context)
class LoginView(auth_views.LoginView):