From 037014d0241a93c4e695a1e532575114220900bc Mon Sep 17 00:00:00 2001 From: Herculino Trotta Date: Sun, 5 Jan 2025 01:22:14 -0300 Subject: [PATCH] feat(categories): add tab to show archived categories --- app/apps/transactions/urls.py | 10 ++++ app/apps/transactions/views/categories.py | 26 +++++++- app/templates/categories/fragments/list.html | 59 ++++--------------- app/templates/categories/fragments/table.html | 59 +++++++++++++++++++ app/templates/categories/pages/index.html | 2 +- 5 files changed, 106 insertions(+), 50 deletions(-) create mode 100644 app/templates/categories/fragments/table.html diff --git a/app/apps/transactions/urls.py b/app/apps/transactions/urls.py index f0402ea..09ec2a5 100644 --- a/app/apps/transactions/urls.py +++ b/app/apps/transactions/urls.py @@ -79,6 +79,16 @@ urlpatterns = [ ), path("categories/", views.categories_index, name="categories_index"), path("categories/list/", views.categories_list, name="categories_list"), + path( + "categories/table/active/", + views.categories_table_active, + name="categories_table_active", + ), + path( + "categories/table/archived/", + views.categories_table_archived, + name="categories_table_archived", + ), path("categories/add/", views.category_add, name="category_add"), path( "categories//edit/", diff --git a/app/apps/transactions/views/categories.py b/app/apps/transactions/views/categories.py index 4c6975a..1f6fea5 100644 --- a/app/apps/transactions/views/categories.py +++ b/app/apps/transactions/views/categories.py @@ -25,11 +25,33 @@ def categories_index(request): @login_required @require_http_methods(["GET"]) def categories_list(request): - categories = TransactionCategory.objects.all().order_by("id") return render( request, "categories/fragments/list.html", - {"categories": categories}, + ) + + +@only_htmx +@login_required +@require_http_methods(["GET"]) +def categories_table_active(request): + categories = TransactionCategory.objects.filter(active=True).order_by("id") + return render( + request, + "categories/fragments/table.html", + {"categories": categories, "active": True}, + ) + + +@only_htmx +@login_required +@require_http_methods(["GET"]) +def categories_table_archived(request): + categories = TransactionCategory.objects.filter(active=False).order_by("id") + return render( + request, + "categories/fragments/table.html", + {"categories": categories, "active": False}, ) diff --git a/app/templates/categories/fragments/list.html b/app/templates/categories/fragments/list.html index f14ba09..fe950d3 100644 --- a/app/templates/categories/fragments/list.html +++ b/app/templates/categories/fragments/list.html @@ -15,53 +15,18 @@
-
- {% if categories %} - - - - - - - - - - - {% for category in categories %} - - - - - - {% endfor %} - -
{% translate 'Name' %}{% translate 'Muted' %}
-
- - - -
-
{{ category.name }} - {% if category.mute %}{% endif %} -
- {% else %} - - {% endif %} +
+ +
+
+
diff --git a/app/templates/categories/fragments/table.html b/app/templates/categories/fragments/table.html new file mode 100644 index 0000000..b1bdcc4 --- /dev/null +++ b/app/templates/categories/fragments/table.html @@ -0,0 +1,59 @@ +{% load i18n %} +{% if active %} +
+{% else %} +
+{% endif %} +
+ {% if categories %} + + + + + + + + + + + {% for category in categories %} + + + + + + {% endfor %} + +
{% translate 'Name' %}{% translate 'Muted' %}
+
+ + + +
+
{{ category.name }} + {% if category.mute %}{% endif %} +
+ {% else %} + + {% endif %} +
+
diff --git a/app/templates/categories/pages/index.html b/app/templates/categories/pages/index.html index 4714017..218b7bc 100644 --- a/app/templates/categories/pages/index.html +++ b/app/templates/categories/pages/index.html @@ -4,5 +4,5 @@ {% block title %}{% translate 'Categories' %}{% endblock %} {% block content %} -
+
{% endblock %}