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
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", views.index, name="index"),
|
path("", views.IndexView.as_view(), name="index"),
|
||||||
path("login", views.LoginView.as_view(), name="login"),
|
path("login", views.LoginView.as_view(), name="login"),
|
||||||
path("logout", views.LogoutView.as_view(), name="logout"),
|
path("logout", views.LogoutView.as_view(), name="logout"),
|
||||||
path("transactions", views.TransactionListView.as_view(), name="transactions"),
|
path("transactions", views.TransactionListView.as_view(), name="transactions"),
|
||||||
|
|
|
@ -12,7 +12,13 @@ from django.db import models
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import get_object_or_404, redirect, render
|
from django.shortcuts import get_object_or_404, redirect, render
|
||||||
from django.urls import reverse_lazy
|
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 django.views.generic.edit import ProcessFormView
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
|
@ -27,18 +33,15 @@ from .models import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
class IndexView(LoginRequiredMixin, TemplateView):
|
||||||
def index(request):
|
template_name = "main/index.html"
|
||||||
_transactions = Transaction.objects.all()[:10]
|
|
||||||
_categories = Category.objects.all()
|
|
||||||
_snapshots = Snapshot.objects.all()
|
|
||||||
|
|
||||||
context = {
|
def get_context_data(self, **kwargs):
|
||||||
"transactions": _transactions,
|
return super().get_context_data(**kwargs) | {
|
||||||
"categories": _categories,
|
"transactions": Transaction.objects.all()[:10],
|
||||||
"snapshots": _snapshots,
|
"categories": Category.objects.all(),
|
||||||
}
|
"snapshots": Snapshot.objects.all(),
|
||||||
return render(request, "main/index.html", context)
|
}
|
||||||
|
|
||||||
|
|
||||||
class LoginView(auth_views.LoginView):
|
class LoginView(auth_views.LoginView):
|
||||||
|
|
Loading…
Reference in a new issue