Add year archive view
This commit is contained in:
parent
45b47dd1ba
commit
caa113859d
3 changed files with 66 additions and 1 deletions
|
@ -0,0 +1,23 @@
|
||||||
|
{% extends "transaction/transaction_list.html" %}
|
||||||
|
{% load i18n main_extras static category %}
|
||||||
|
{% block link %}
|
||||||
|
{{ block.super }}
|
||||||
|
{% css "main/css/plot.css" %}
|
||||||
|
{% endblock %}
|
||||||
|
{% block h2 %}{{ year|date:"Y" }}{% endblock %}
|
||||||
|
{% block table %}
|
||||||
|
{% if history %}
|
||||||
|
<section>
|
||||||
|
<h3>
|
||||||
|
{% translate "History" %}
|
||||||
|
</h2>
|
||||||
|
{% include "history/plot.html" %}
|
||||||
|
</section>
|
||||||
|
{% endif %}
|
||||||
|
{% if not category %}
|
||||||
|
<h3>{% translate "Categories" %}</h3>
|
||||||
|
{% category_plot transactions month=month %}
|
||||||
|
{% endif %}
|
||||||
|
<h3>{% translate "Transactions" %}</h3>
|
||||||
|
{{ block.super }}
|
||||||
|
{% endblock %}
|
|
@ -4,6 +4,11 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("list", views.TransactionListView.as_view(), name="transactions"),
|
path("list", views.TransactionListView.as_view(), name="transactions"),
|
||||||
|
path(
|
||||||
|
"history/<int:year>",
|
||||||
|
views.TransactionYearView.as_view(),
|
||||||
|
name="transaction_year",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"history/<int:year>/<int:month>",
|
"history/<int:year>/<int:month>",
|
||||||
views.TransactionMonthView.as_view(),
|
views.TransactionMonthView.as_view(),
|
||||||
|
|
|
@ -2,7 +2,8 @@ from account.models import Account
|
||||||
from category.models import Category
|
from category.models import Category
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.views.generic.dates import MonthArchiveView
|
from django.views.generic.dates import MonthArchiveView, YearArchiveView
|
||||||
|
from history.utils import history
|
||||||
from main.views import (
|
from main.views import (
|
||||||
NummiCreateView,
|
NummiCreateView,
|
||||||
NummiDeleteView,
|
NummiDeleteView,
|
||||||
|
@ -138,3 +139,39 @@ class TransactionMonthView(UserMixin, MonthArchiveView):
|
||||||
if "account" in self.kwargs:
|
if "account" in self.kwargs:
|
||||||
return context_data | {"account": self.account}
|
return context_data | {"account": self.account}
|
||||||
return context_data
|
return context_data
|
||||||
|
|
||||||
|
|
||||||
|
class TransactionYearView(UserMixin, YearArchiveView):
|
||||||
|
model = Transaction
|
||||||
|
date_field = "date"
|
||||||
|
context_object_name = "transactions"
|
||||||
|
make_object_list = True
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
if "account" in self.kwargs:
|
||||||
|
self.account = get_object_or_404(
|
||||||
|
Account.objects.filter(user=self.request.user),
|
||||||
|
pk=self.kwargs["account"],
|
||||||
|
)
|
||||||
|
return super().get_queryset().filter(account=self.account)
|
||||||
|
if "category" in self.kwargs:
|
||||||
|
self.category = get_object_or_404(
|
||||||
|
Category.objects.filter(user=self.request.user),
|
||||||
|
pk=self.kwargs["category"],
|
||||||
|
)
|
||||||
|
return super().get_queryset().filter(category=self.category)
|
||||||
|
|
||||||
|
return super().get_queryset()
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context_data = super().get_context_data(**kwargs)
|
||||||
|
context_data |= {
|
||||||
|
"history": history(
|
||||||
|
context_data["transactions"].exclude(category__budget=False)
|
||||||
|
),
|
||||||
|
}
|
||||||
|
if "category" in self.kwargs:
|
||||||
|
return context_data | {"category": self.category}
|
||||||
|
if "account" in self.kwargs:
|
||||||
|
return context_data | {"account": self.account}
|
||||||
|
return context_data
|
||||||
|
|
Loading…
Reference in a new issue