diff --git a/car_inventory/__pycache__/settings.cpython-311.pyc b/car_inventory/__pycache__/settings.cpython-311.pyc index 83e468dc..5122bb2d 100644 Binary files a/car_inventory/__pycache__/settings.cpython-311.pyc and b/car_inventory/__pycache__/settings.cpython-311.pyc differ diff --git a/inventory/__pycache__/admin.cpython-311.pyc b/inventory/__pycache__/admin.cpython-311.pyc index 9025ad27..ebd396fb 100644 Binary files a/inventory/__pycache__/admin.cpython-311.pyc and b/inventory/__pycache__/admin.cpython-311.pyc differ diff --git a/inventory/__pycache__/forms.cpython-311.pyc b/inventory/__pycache__/forms.cpython-311.pyc index 07debbfb..340c29d4 100644 Binary files a/inventory/__pycache__/forms.cpython-311.pyc and b/inventory/__pycache__/forms.cpython-311.pyc differ diff --git a/inventory/__pycache__/middleware.cpython-311.pyc b/inventory/__pycache__/middleware.cpython-311.pyc index b16ec950..a96fc8cb 100644 Binary files a/inventory/__pycache__/middleware.cpython-311.pyc and b/inventory/__pycache__/middleware.cpython-311.pyc differ diff --git a/inventory/__pycache__/models.cpython-311.pyc b/inventory/__pycache__/models.cpython-311.pyc index cc0cdbbd..f45e13c7 100644 Binary files a/inventory/__pycache__/models.cpython-311.pyc and b/inventory/__pycache__/models.cpython-311.pyc differ diff --git a/inventory/__pycache__/tables.cpython-311.pyc b/inventory/__pycache__/tables.cpython-311.pyc index c99760b1..066c1013 100644 Binary files a/inventory/__pycache__/tables.cpython-311.pyc and b/inventory/__pycache__/tables.cpython-311.pyc differ diff --git a/inventory/__pycache__/utils.cpython-311.pyc b/inventory/__pycache__/utils.cpython-311.pyc index 8a743419..f564af6f 100644 Binary files a/inventory/__pycache__/utils.cpython-311.pyc and b/inventory/__pycache__/utils.cpython-311.pyc differ diff --git a/inventory/__pycache__/views.cpython-311.pyc b/inventory/__pycache__/views.cpython-311.pyc index 30b9dfa2..b8521974 100644 Binary files a/inventory/__pycache__/views.cpython-311.pyc and b/inventory/__pycache__/views.cpython-311.pyc differ diff --git a/inventory/tables.py b/inventory/tables.py index 01288b6d..7d9b1b04 100644 --- a/inventory/tables.py +++ b/inventory/tables.py @@ -1,26 +1,15 @@ -from django.utils.html import format_html - from django.conf import settings from django.utils.timesince import timesince - -from . import models -from django_tables2.utils import A -from django import forms import django_tables2 as tables from django.utils.translation import gettext_lazy as _ from .models import Car, CarFinance, ExteriorColors, InteriorColors, CarColors from .utils import get_local_name - - - -class ImageColumn(tables.Column): - def render(self, value): - return format_html('', settings.MEDIA_URL, value) +from django.utils.html import format_html class CarTable(tables.Table): stock_type = tables.Column(verbose_name=_("Stock Type")) - vin = tables.LinkColumn("car_detail", args=[tables.A("pk")], verbose_name=_("VIN"), attrs={"td": {"class": "fw-bold"}, "span": {"class": "fas fa-bars"}}) + vin = tables.LinkColumn("car_detail", args=[tables.A("pk")], verbose_name=_("VIN"), attrs={"td": {"class": "fw-bold"}}) id_car_make = tables.Column(verbose_name=_("Make")) id_car_model = tables.Column(verbose_name=_("Model")) year = tables.Column(verbose_name=_("Year")) @@ -36,7 +25,7 @@ class CarTable(tables.Table): class Meta: model = Car template_name = settings.DJANGO_TABLES2_TEMPLATE - export_formats = ["xlsx", ] + export_formats = ["xlsx"] fields = ( "stock_type", "vin", @@ -52,7 +41,7 @@ class CarTable(tables.Table): "receiving_date", "status", ) - attrs = {"class": "table table-hover fs-9 mb-0"} + attrs = {"class": "table table-hover fs-9 mb-0 p-1"} def render_id_car_make(self, value): return get_local_name(value) @@ -73,4 +62,22 @@ class CarTable(tables.Table): return str(value) def render_receiving_date(self, value): - return timesince(value) if value else "-" \ No newline at end of file + return timesince(value) if value else "-" + + def render_status(self, value): + status_badges = { + "available": "badge-phoenix-success", + "reserved": "badge-phoenix-danger", + "sold": "badge-phoenix-info", + "transfer": "badge-phoenix-warning", + } + badge_class = status_badges.get(value.lower(), "badge-secondary") + return format_html('{}', badge_class, value) + + def render_stock_type(self, value): + type_badges = { + "new": "badge-phoenix-success", + "used": "badge-phoenix-warning", + } + badge_class = type_badges.get(value.lower(), "badge-secondary") + return format_html('{}', badge_class, value) \ No newline at end of file diff --git a/templates/inventory/car_list_table.html b/templates/inventory/car_list_table.html index b5d3ae91..c60b51a8 100644 --- a/templates/inventory/car_list_table.html +++ b/templates/inventory/car_list_table.html @@ -1,10 +1,11 @@ {% extends 'base.html' %} + {% load static i18n django_tables2 %} {% load export_url from django_tables2 %} {% block content %} -
+
-
-
+
+
{% render_table table %} +
+
diff --git a/templates/partials/tables.html b/templates/partials/tables.html new file mode 100644 index 00000000..04f90924 --- /dev/null +++ b/templates/partials/tables.html @@ -0,0 +1,87 @@ +{% load django_tables2 %} +{% load i18n l10n %} +{% block table-wrapper %} +
+{% endblock table-wrapper %}