From 24e61444011141caad4646457b7ab2a38a947e06 Mon Sep 17 00:00:00 2001 From: Kavalar Date: Wed, 23 Sep 2026 18:45:12 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=86=D0=B5=20=D0=B7=D0=B0=D1=8F=D0=B2=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=BC=D0=BE=D0=B4=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8E=20=D0=BF=D0=BE=D0=BA=D0=B0=D0=B7=D0=B0=D1=82=D1=8C?= =?UTF-8?q?=20=D0=B1=D1=80=D0=B5=D0=BD=D0=B4,=20=D0=BE=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D1=81=D1=81=D1=8B=D0=BB?= =?UTF-8?q?=D0=BA=D1=83=20=D0=BD=D0=B0=20=D0=BA=D0=B0=D1=80=D1=82=D0=BE?= =?UTF-8?q?=D1=87=D0=BA=D1=83;=20=D0=BA=D0=B0=D1=80=D1=82=D0=BE=D1=87?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=BC=D0=BE=D0=B4=D0=B5=D1=80=D0=B0=D1=82=D0=BE=D1=80=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/catalog/views.py | 6 +++++- apps/moderation/admin.py | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/apps/catalog/views.py b/apps/catalog/views.py index 0b7db79..d6f0381 100644 --- a/apps/catalog/views.py +++ b/apps/catalog/views.py @@ -1,3 +1,4 @@ +from django.http import Http404 from django.shortcuts import get_object_or_404, render from apps.catalog.models import Brand, Category, ModerationStatus, Product @@ -50,7 +51,10 @@ def product_detail(request, slug): def brand_detail(request, slug): - brand = get_object_or_404(Brand, slug=slug, verification_status='approved') + brand = get_object_or_404(Brand, slug=slug) + # Неодобренные бренды видны только модераторам/администраторам (для проверки). + if brand.verification_status != 'approved' and not request.user.is_staff: + raise Http404 products = brand.products.filter(moderation_status=PUBLISHED, is_active=True) return render(request, 'catalog/brand_detail.html', { 'brand': brand, diff --git a/apps/moderation/admin.py b/apps/moderation/admin.py index 399c351..bb1e66d 100644 --- a/apps/moderation/admin.py +++ b/apps/moderation/admin.py @@ -2,6 +2,8 @@ from django.contrib import admin from django.urls import reverse from django.utils.html import format_html +from apps.catalog.models import Brand, Product + from .models import AuditLog, ModerationRequest @@ -13,6 +15,10 @@ class ModerationRequestAdmin(admin.ModelAdmin): ) list_filter = ('decision', 'content_type') search_fields = ('comment', 'user__username', 'user__full_name') + readonly_fields = ( + 'get_entity_name', 'get_user', 'get_story', 'get_link', + 'created_at', 'decided_at', + ) @admin.display(description='Сущность') def get_entity_name(self, obj): @@ -40,15 +46,18 @@ class ModerationRequestAdmin(admin.ModelAdmin): story = getattr(entity, 'story', '') or '' return story[:80] + ('…' if len(story) > 80 else '') - @admin.display(description='Полное описание') + @admin.display(description='Страница карточки') def get_link(self, obj): entity = obj.entity if entity is None: return '-' - app_label = entity._meta.app_label - model_name = entity._meta.model_name - url = reverse(f'admin:{app_label}_{model_name}_change', args=[entity.pk]) - return format_html('Открыть', url) + if isinstance(entity, Brand): + url = reverse('catalog:brand_detail', args=[entity.slug]) + elif isinstance(entity, Product): + url = reverse('catalog:product_detail', args=[entity.slug]) + else: + return '-' + return format_html('Открыть карточку', url) @admin.register(AuditLog)