better lots group table

This commit is contained in:
Thomas Nahuel Rusiecki 2025-02-24 16:13:34 -03:00
parent 81cd13dae4
commit e974a6744d
3 changed files with 21 additions and 11 deletions

View file

@ -5,7 +5,7 @@
{% block content %}
<a href="{% url 'lot:add' %}" type="button" class="btn btn-green-admin">
<a href="{% url 'lot:add' %}" type="button" class="btn btn-green-admin mb-3">
<i class="bi bi-plus"></i>
{% trans 'Add new lot' %}
</a>
@ -14,13 +14,13 @@
<!-- Search and Filter Section -->
<div class="row mb-4">
<!-- Search Input -->
<div class="col-md-6">
<div class="col-md-6 mb-3">
<form method="get" class="d-flex">
<input
type="text"
name="q"
class="form-control me-2"
placeholder="{% trans 'Search lots...' %}"
placeholder="{% trans 'Search by name or description...' %}"
value="{{ search_query }}">
<button type="submit" class="btn btn-outline-secondary">
<i class="bi bi-search"></i>
@ -61,9 +61,12 @@
</div>
</div>
<!-- Lots list -->
{% render_table table %}
<div class="mt-5 d-flex align-items-center justify-content-center">
{% if table.page and table.paginator.num_pages > 1 %}
{% include "django_tables2/pagination.html" %}
{% endif %}
</div>{% endblock %}
</div>
{% endblock %}

View file

@ -24,7 +24,8 @@
{% endif %}
{% bootstrap_form form %}
<div class="form-actions-no-box">
<a class="btn btn-grey" href="{% url 'dashboard:unassigned' %}">{% translate "Cancel" %}</a>
<a class="btn btn-grey" href="{{ request.META.HTTP_REFERER }}">{% translate "Cancel" %}</a>
<input class="btn btn-green-admin" type="submit" name="submit" value="{% translate 'Save' %}" />
</div>

View file

@ -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('<span class="badge bg-danger">Closed</span>')
return mark_safe('<span class="badge bg-success">Open</span>')
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):