Обновили шапку и вывод всехтоваров. Добавили фильтры

This commit is contained in:
2025-10-22 15:49:59 +03:00
parent d78c43d9a9
commit 85801c6c4a
13 changed files with 1849 additions and 1219 deletions

View File

@@ -0,0 +1,242 @@
{% extends 'base.html' %}
{% block title %}Все товары и комплекты{% endblock %}
{% block content %}
<div class="container mt-5">
<h2 class="mb-4">Товары</h2>
<!-- Панель быстрых фильтров по категориям -->
{% include 'components/category_filter_buttons.html' with categories=filters.categories current_category=filters.current.category show_type_filters=True %}
<!-- Панель фильтрации и действий -->
<div class="card shadow-sm mb-4">
<div class="card-body">
<!-- Кнопки действий -->
<div class="d-flex justify-content-between align-items-center mb-3 flex-wrap">
<h5 class="card-title mb-0 me-3">
<i class="bi bi-funnel-fill"></i> Поиск и фильтры
</h5>
{% if action_buttons %}
<div class="btn-toolbar" role="toolbar">
{% for button in action_buttons %}
<a href="{{ button.url }}" class="btn {{ button.class|default:'btn-primary' }} btn-sm me-2 mb-2 mb-md-0">
{% if button.icon %}<i class="bi bi-{{ button.icon }}"></i>{% endif %}
{{ button.text }}
</a>
{% endfor %}
</div>
{% endif %}
</div>
<hr class="my-3">
<!-- Форма фильтров -->
<form method="get" id="filterForm">
<div class="row g-3">
<!-- Поле поиска -->
<div class="col-12 col-md-6">
<label for="search" class="form-label">
<i class="bi bi-search"></i> Поиск
</label>
<input
type="text"
class="form-control"
id="search"
name="search"
placeholder="Поиск по названию, артикулу..."
value="{{ filters.current.search|default:'' }}"
>
</div>
<!-- Фильтр по статусу -->
<div class="col-12 col-md-3">
<label for="is_active" class="form-label">
<i class="bi bi-toggle-on"></i> Статус
</label>
<select class="form-select" id="is_active" name="is_active">
<option value="">Все</option>
<option value="1" {% if filters.current.is_active == '1' %}selected{% endif %}>Активные</option>
<option value="0" {% if filters.current.is_active == '0' %}selected{% endif %}>Неактивные</option>
</select>
</div>
<!-- Сохраняем текущую категорию при поиске -->
{% if filters.current.category %}
<input type="hidden" name="category" value="{{ filters.current.category }}">
{% endif %}
<!-- Кнопки управления фильтрами -->
<div class="col-12 col-md-3">
<label class="form-label d-none d-md-block">&nbsp;</label>
<div class="d-flex gap-2">
<button type="submit" class="btn btn-primary w-100">
<i class="bi bi-check-circle"></i> Применить
</button>
<a href="{{ request.path }}" class="btn btn-outline-secondary">
<i class="bi bi-x-circle"></i> Сброс
</a>
</div>
</div>
</div>
</form>
</div>
</div>
{% if items %}
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="table-dark">
<tr>
<th style="width: 60px;">Тип</th>
<th style="width: 80px;">Фото</th>
<th>Название</th>
<th>Артикул</th>
<th>Категория</th>
<th>Цена продажи</th>
<th>Статус</th>
<th style="width: 200px;">Действия</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
<td>
{% if item.item_type == 'product' %}
<span class="badge bg-success" title="Товар поштучно">
<i class="bi bi-box"></i>
</span>
{% else %}
<span class="badge bg-info" title="Комплект">
<i class="bi bi-box-seam"></i>
</span>
{% endif %}
</td>
<td>
{% if item.photos.all %}
{% with photo=item.photos.first %}
<img src="{{ photo.image.url }}" alt="{{ item.name }}" style="max-width: 50px; max-height: 50px;" class="img-thumbnail">
{% endwith %}
{% else %}
<span class="text-muted small">Нет фото</span>
{% endif %}
</td>
<td>
{% if item.item_type == 'product' %}
<a href="{% url 'products:product-detail' item.pk %}">{{ item.name }}</a>
{% else %}
<a href="{% url 'products:productkit-detail' item.pk %}">{{ item.name }}</a>
{% endif %}
</td>
<td>{{ item.sku }}</td>
<td>
{% if item.categories.all %}
{% for category in item.categories.all %}
<span class="badge bg-secondary">{{ category.name }}</span>{% if not forloop.last %} {% endif %}
{% endfor %}
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td>
{% if item.item_type == 'product' %}
{{ item.sale_price|floatformat:2 }} руб.
{% else %}
{{ item.get_sale_price|floatformat:2 }} руб.
{% endif %}
</td>
<td>
{% if item.is_active %}
<span class="badge bg-success">Активен</span>
{% else %}
<span class="badge bg-secondary">Неактивен</span>
{% endif %}
</td>
<td>
<div class="btn-group btn-group-sm" role="group">
{% if item.item_type == 'product' %}
<a href="{% url 'products:product-detail' item.pk %}" class="btn btn-outline-info" title="Просмотр">
<i class="bi bi-eye"></i>
</a>
{% if perms.products.change_product %}
<a href="{% url 'products:product-update' item.pk %}" class="btn btn-outline-primary" title="Изменить">
<i class="bi bi-pencil"></i>
</a>
{% endif %}
{% if perms.products.delete_product %}
<a href="{% url 'products:product-delete' item.pk %}" class="btn btn-outline-danger" title="Удалить">
<i class="bi bi-trash"></i>
</a>
{% endif %}
{% else %}
<a href="{% url 'products:productkit-detail' item.pk %}" class="btn btn-outline-info" title="Просмотр">
<i class="bi bi-eye"></i>
</a>
{% if perms.products.change_productkit %}
<a href="{% url 'products:productkit-update' item.pk %}" class="btn btn-outline-primary" title="Изменить">
<i class="bi bi-pencil"></i>
</a>
{% endif %}
{% if perms.products.delete_productkit %}
<a href="{% url 'products:productkit-delete' item.pk %}" class="btn btn-outline-danger" title="Удалить">
<i class="bi bi-trash"></i>
</a>
{% endif %}
{% endif %}
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- Pagination -->
{% if is_paginated %}
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center">
{% if page_obj.has_previous %}
<li class="page-item">
<a class="page-link" href="?page=1{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}">Первая</a>
</li>
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.previous_page_number }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}">Предыдущая</a>
</li>
{% endif %}
<li class="page-item active">
<span class="page-link">Страница {{ page_obj.number }} из {{ page_obj.paginator.num_pages }}</span>
</li>
{% if page_obj.has_next %}
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.next_page_number }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}">Следующая</a>
</li>
<li class="page-item">
<a class="page-link" href="?page={{ page_obj.paginator.num_pages }}{% for key, value in request.GET.items %}{% if key != 'page' %}&{{ key }}={{ value }}{% endif %}{% endfor %}">Последняя</a>
</li>
{% endif %}
</ul>
</nav>
{% endif %}
{% else %}
<div class="alert alert-info">
<h4><i class="bi bi-info-circle"></i> Товары не найдены</h4>
<p>В данный момент нет товаров или комплектов, соответствующих выбранным фильтрам.</p>
<div class="mt-3">
{% if perms.products.add_product %}
<a href="{% url 'products:product-create' %}" class="btn btn-primary me-2">
<i class="bi bi-plus-circle"></i> Создать товар
</a>
{% endif %}
{% if perms.products.add_productkit %}
<a href="{% url 'products:productkit-create' %}" class="btn btn-outline-primary">
<i class="bi bi-plus-circle"></i> Создать комплект
</a>
{% endif %}
</div>
</div>
{% endif %}
</div>
{% endblock %}