From e974a6744d5e65f39b231b7faff7eaab99d45c3f Mon Sep 17 00:00:00 2001 From: Thomas Rusiecki Date: Mon, 24 Feb 2025 16:13:34 -0300 Subject: [PATCH] better lots group table --- lot/templates/lots.html | 11 +++++++---- lot/templates/new_lot.html | 3 ++- lot/views.py | 18 ++++++++++++------ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lot/templates/lots.html b/lot/templates/lots.html index 5b4a6b6..702c4cb 100644 --- a/lot/templates/lots.html +++ b/lot/templates/lots.html @@ -5,7 +5,7 @@ {% block content %} - + {% trans 'Add new lot' %} @@ -14,13 +14,13 @@
-
+
+ {% render_table table %}
{% if table.page and table.paginator.num_pages > 1 %} {% include "django_tables2/pagination.html" %} {% endif %} -
{% endblock %} +
+ +{% endblock %} diff --git a/lot/templates/new_lot.html b/lot/templates/new_lot.html index c4c2cc8..ba8abcb 100644 --- a/lot/templates/new_lot.html +++ b/lot/templates/new_lot.html @@ -24,7 +24,8 @@ {% endif %} {% bootstrap_form form %}
- {% translate "Cancel" %} + {% translate "Cancel" %} +
diff --git a/lot/views.py b/lot/views.py index ea28426..a09aad2 100644 --- a/lot/views.py +++ b/lot/views.py @@ -3,6 +3,7 @@ from django.urls import reverse_lazy from django.shortcuts import get_object_or_404, redirect, Http404 from django.contrib import messages from django.utils.translation import gettext_lazy as _ +from django.utils.safestring import mark_safe from django.views.generic.base import TemplateView from django.db.models import Q from django.views.generic.edit import ( @@ -180,25 +181,30 @@ class DelToLotView(AddToLotView): class LotTable(tables.Table): - name = tables.Column(linkify=("dashboard:lot", {"pk": tables.A("id")}), verbose_name=_("Lot Name")) - description = tables.Column(verbose_name=_("Description"), default="No description") + name = tables.Column(linkify=("dashboard:lot", {"pk": tables.A("id")}), verbose_name=_("Lot Name"), attrs={"td": {"class": "fw-bold"}}) + description = tables.Column(verbose_name=_("Description"), default=_("No description"),attrs={"td": {"class": "text-muted"}} ) closed = tables.Column(verbose_name=_("Status")) created = tables.DateColumn(format="Y-m-d", verbose_name=_("Created On")) - user = tables.Column(verbose_name=_("Created By"), default="Unknown") + user = tables.Column(verbose_name=("Created By"), default=_("Unknown"), attrs={"td": {"class": "text-muted"}} ) actions = tables.TemplateColumn( template_name="lot_actions.html", - verbose_name=_("Actions"), - orderable=False, + verbose_name=_(""), attrs={"td": {"class": "text-end"}} ) + def render_closed(self, value): + if value: + return mark_safe('Closed') + return mark_safe('Open') + class Meta: model = Lot - fields = ("name", "description", "closed", "created", "user", "actions") + fields = ("closed", "name", "description", "created", "user", "actions") attrs = { "class": "table table-hover align-middle", "thead": {"class": "table-light"} } + order_by = ("-created",) class LotsTagsView(DashboardView, tables.SingleTableView):