WIP: Lot groups search/filtering and lot groups panel ui changes #61

Draft
rskthomas wants to merge 17 commits from rework/lots into main
2 changed files with 112 additions and 50 deletions
Showing only changes of commit 5ea174d553 - Show all commits

View file

@ -1,43 +1,63 @@
{% extends "base.html" %}
{% load i18n %}
{% load i18n paginacion %}
{% load render_table from django_tables2 %}
{% block content %}
<div class="row mb-3">
<div class="col">
<h3>{{ subtitle }}</h3>
</div>
<div class="col text-center">
{% if show_closed %}
<a href="?show_closed=false" class="btn btn-green-admin">
{% trans 'Hide closed lots' %}
</a>
{% else %}
<a href="?show_closed=true" class="btn btn-green-admin">
{% trans 'Show closed lots' %}
</a>
{% endif %}
<a href="{% url 'lot:add' %}" type="button" class="btn btn-green-admin">
<a href="{% url 'lot:add' %}" type="button" class="btn btn-green-admin">
<i class="bi bi-plus"></i>
{% trans 'Add new lot' %}
</a>
<h3>{{ subtitle }}</h3>
<!-- Search and Filter Section -->
<div class="row mb-4">
<!-- Search Input -->
<div class="col-md-6">
<form method="get" class="d-flex">
<input
type="text"
name="q"
class="form-control me-2"
placeholder="{% trans 'Search lots...' %}"
value="{{ search_query }}">
<button type="submit" class="btn btn-outline-secondary">
<i class="bi bi-search"></i>
</button>
</form>
</div>
<!-- Filter Dropdown -->
<div class="col-md-6 text-md-end">
<div class="dropdown">
<button class="btn btn-outline-secondary dropdown-toggle" type="button" id="filterDropdown" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-filter me-2"></i>
{% trans 'Filter' %}
</button>
<ul class="dropdown-menu" aria-labelledby="filterDropdown">
<li>
<a class="dropdown-item {% if show_closed %}border border-info rounded{% endif %} " href="?show_closed={% if show_closed %}false{% else %}true{% endif %}{% if search_query %}&q={{ search_query }}{% endif %}">
{% trans 'Closed Lots' %}
{% if show_closed %}<i class="bi bi-check"></i>{% endif %}
</a>
</li>
<li>
<a class="dropdown-item" href="?{% if search_query %}q={{ search_query }}{% endif %}">
{% trans 'Clear Filters' %}
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="row">
<table class= "table table-striped table-sm">
{% for lot in lots %}
<tr>
<td><a href="{% url 'dashboard:lot' lot.id %}">{{ lot.name }}</a></td>
<td>
<a href="{% url 'lot:edit' lot.id %}"><i class="bi bi-pen"></i></a>
</td>
<td>
<a href="{% url 'lot:delete' lot.id %}"><i class="bi bi-trash text-danger"></i></a>
</td>
</tr>
{% endfor %}
</table>
</div>
{% endblock %}
<!-- Lots Table -->
{% 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 %}

View file

@ -4,12 +4,14 @@ 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.views.generic.base import TemplateView
from django.db.models import Q
from django.views.generic.edit import (
CreateView,
DeleteView,
UpdateView,
FormView,
)
import django_tables2 as tables
from dashboard.mixins import DashboardView
from lot.models import Lot, LotTag, LotProperty
from lot.forms import LotsForm
@ -137,31 +139,71 @@ class DelToLotView(AddToLotView):
return response
class LotsTagsView(DashboardView, TemplateView):
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")
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")
actions = tables.TemplateColumn(
template_name="lot_actions.html",
verbose_name=_("Actions"),
orderable=False,
attrs={"td": {"class": "text-end"}}
)
class Meta:
model = Lot
fields = ("name", "description", "closed", "created", "user", "actions")
attrs = {
"class": "table table-hover align-middle",
"thead": {"class": "table-light"}
}
class LotsTagsView(DashboardView, tables.SingleTableView):
template_name = "lots.html"
title = _("lots")
breadcrumb = _("lots") + " /"
success_url = reverse_lazy('dashboard:unassigned')
model = Lot
table_class = LotTable
def get_queryset(self):
self.pk = self.kwargs.get('pk')
self.tag = get_object_or_404(LotTag, owner=self.request.user.institution, id=self.pk)
self.show_closed = self.request.GET.get('show_closed', 'false') == 'true'
self.search_query = self.request.GET.get('q', '').strip()
queryset = Lot.objects.filter(owner=self.request.user.institution, type=self.tag)
if not self.show_closed:
queryset = queryset.filter(closed=True)
if self.search_query:
queryset = queryset.filter(
Q(name__icontains=self.search_query) |
Q(description__icontains=self.search_query) |
Q(code__icontains=self.search_query)
)
sort = self.request.GET.get('sort')
if sort:
queryset = queryset.order_by(sort)
return queryset
def get_context_data(self, **kwargs):
self.pk = kwargs.get('pk')
context = super().get_context_data(**kwargs)
tag = get_object_or_404(LotTag, owner=self.request.user.institution, id=self.pk)
self.title += " {}".format(tag.name)
self.breadcrumb += " {}".format(tag.name)
show_closed = self.request.GET.get('show_closed', 'false') == 'true'
lots = Lot.objects.filter(owner=self.request.user.institution).filter(
type=tag, closed=show_closed
)
context.update({
'lots': lots,
'title': self.title,
'breadcrumb': self.breadcrumb,
'show_closed': show_closed
'title': self.title + " " + self.tag.name,
'breadcrumb': self.breadcrumb + " " + self.tag.name,
'show_closed': self.show_closed,
'search_query': self.search_query, # Pass the search query to the template
})
return context
class LotPropertiesView(DashboardView, TemplateView):
template_name = "properties.html"
title = _("New Lot Property")