Switched index view to class-based
This commit is contained in:
parent
a722165ee2
commit
bcbf33984b
2 changed files with 16 additions and 13 deletions
|
@ -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"),
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue