Compare commits
1 commit
f6e8b583cc
...
2736c2ae9d
Author | SHA1 | Date | |
---|---|---|---|
2736c2ae9d |
5 changed files with 21 additions and 26 deletions
|
@ -1,4 +1,3 @@
|
|||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse_lazy
|
||||
from main.views import NummiCreateView, NummiDeleteView, NummiUpdateView
|
||||
from statement.views import StatementListView
|
||||
|
@ -52,14 +51,12 @@ class AccountDeleteView(NummiDeleteView):
|
|||
|
||||
class AccountMixin:
|
||||
def get_queryset(self):
|
||||
self.account = get_object_or_404(
|
||||
Account.objects.filter(user=self.request.user),
|
||||
pk=self.kwargs.get("account"),
|
||||
)
|
||||
return super().get_queryset().filter(account=self.account)
|
||||
return super().get_queryset().filter(account=self.kwargs.get("account"))
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return super().get_context_data(**kwargs) | {"account": self.account}
|
||||
return super().get_context_data(**kwargs) | {
|
||||
"account": Account.objects.get(pk=self.kwargs.get("account")),
|
||||
}
|
||||
|
||||
|
||||
class AccountTListView(AccountMixin, TransactionListView):
|
||||
|
|
|
@ -22,10 +22,10 @@ class Category(UserModel):
|
|||
return str(self.name)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("category", args=(self.pk,))
|
||||
return reverse("category", kwargs={"pk": self.pk})
|
||||
|
||||
def get_delete_url(self):
|
||||
return reverse("del_category", args=(self.pk,))
|
||||
return reverse("del_category", kwargs={"pk": self.pk})
|
||||
|
||||
class Meta:
|
||||
ordering = ["name"]
|
||||
|
|
|
@ -4,16 +4,18 @@ from transaction.views import TransactionMonthView
|
|||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path("", views.CategoryCreateView.as_view(), name="new_category"),
|
||||
path("<category>", views.CategoryUpdateView.as_view(), name="category"),
|
||||
path("category", views.CategoryCreateView.as_view(), name="new_category"),
|
||||
path("category/<pk>", views.CategoryUpdateView.as_view(), name="category"),
|
||||
path(
|
||||
"<category>/transactions",
|
||||
"category/<pk>/transactions",
|
||||
views.CategoryTListView.as_view(),
|
||||
name="category_transactions",
|
||||
),
|
||||
path("<category>/delete", views.CategoryDeleteView.as_view(), name="del_category"),
|
||||
path(
|
||||
"<category>/history/<int:year>/<int:month>",
|
||||
"category/<pk>/delete", views.CategoryDeleteView.as_view(), name="del_category"
|
||||
),
|
||||
path(
|
||||
"category/<category>/history/<int:year>/<int:month>",
|
||||
TransactionMonthView.as_view(),
|
||||
name="transaction_month",
|
||||
),
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse_lazy
|
||||
from main.views import NummiCreateView, NummiDeleteView, NummiUpdateView
|
||||
from transaction.utils import history
|
||||
|
@ -11,12 +10,13 @@ from .models import Category
|
|||
class CategoryCreateView(NummiCreateView):
|
||||
model = Category
|
||||
form_class = CategoryForm
|
||||
template_name = "main/form/category.html"
|
||||
|
||||
|
||||
class CategoryUpdateView(NummiUpdateView):
|
||||
model = Category
|
||||
form_class = CategoryForm
|
||||
pk_url_kwarg = "category"
|
||||
template_name = "main/form/category.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
|
@ -33,19 +33,17 @@ class CategoryUpdateView(NummiUpdateView):
|
|||
|
||||
class CategoryDeleteView(NummiDeleteView):
|
||||
model = Category
|
||||
pk_url_kwarg = "category"
|
||||
|
||||
|
||||
class CategoryMixin:
|
||||
def get_queryset(self):
|
||||
self.category = get_object_or_404(
|
||||
Category.objects.filter(user=self.request.user),
|
||||
pk=self.kwargs.get("category"),
|
||||
)
|
||||
return super().get_queryset().filter(category=self.category)
|
||||
return super().get_queryset().filter(category=self.kwargs.get("pk"))
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return super().get_context_data(**kwargs) | {"category": self.category}
|
||||
return super().get_context_data(**kwargs) | {
|
||||
"object": Category.objects.get(pk=self.kwargs.get("pk")),
|
||||
"category": True,
|
||||
}
|
||||
|
||||
|
||||
class CategoryTListView(CategoryMixin, TransactionListView):
|
||||
|
|
|
@ -9,11 +9,9 @@
|
|||
{% endblock %}
|
||||
{% block h2 %}{{ form.instance.icon|remix }}{{ form.instance }}{% endblock %}
|
||||
{% block tables %}
|
||||
{% if transactions %}
|
||||
{% if form.instance.transactions %}
|
||||
<h3>{% translate "Transactions" %}</h3>
|
||||
{% include "main/table/transaction.html" %}
|
||||
{% endif %}
|
||||
{% if history.data %}
|
||||
<h3>{% translate "History" %}</h3>
|
||||
{% include "main/plot/history.html" %}
|
||||
{% endif %}
|
Loading…
Reference in a new issue