Compare commits
3 commits
45b47dd1ba
...
75df57f42a
Author | SHA1 | Date | |
---|---|---|---|
75df57f42a | |||
3dbc31eebc | |||
caa113859d |
5 changed files with 71 additions and 3 deletions
|
@ -52,7 +52,9 @@
|
||||||
{% regroup history.data by month.year as years_list %}
|
{% regroup history.data by month.year as years_list %}
|
||||||
{% for y, year in years_list reversed %}
|
{% for y, year in years_list reversed %}
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{ y }}</th>
|
<th>
|
||||||
|
<a href="{% url "transaction_year" y %}">{{ y }}</a>
|
||||||
|
</th>
|
||||||
{% for m in year %}
|
{% for m in year %}
|
||||||
{% if forloop.parentloop.last and forloop.first %}
|
{% if forloop.parentloop.last and forloop.first %}
|
||||||
{% empty_calendar_cells_start m.month.month %}
|
{% empty_calendar_cells_start m.month.month %}
|
||||||
|
|
|
@ -66,8 +66,10 @@ table.full-width col.bar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tbody tr {
|
.history & tbody tr {
|
||||||
background: initial;
|
background: initial;
|
||||||
|
}
|
||||||
|
tbody tr {
|
||||||
&.empty {
|
&.empty {
|
||||||
height: 0.5rem;
|
height: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
{% extends "main/list.html" %}
|
||||||
|
{% load i18n main_extras static category %}
|
||||||
|
{% block link %}
|
||||||
|
{{ block.super }}
|
||||||
|
{% css "main/css/plot.css" %}
|
||||||
|
{% endblock %}
|
||||||
|
{% block name %}{{ year|date:"Y" }}{% 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 %}
|
||||||
|
{% 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