feat: на странице заявки на модерацию показать бренд, описание и ссылку на карточку; карточка доступна модератору
This commit is contained in:
1 parent
970450cce2
commit
24e6144401
2 files changed
+19
-6
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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('<a href="{}">Открыть</a>', 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('<a href="{}" target="_blank">Открыть карточку</a>', url)
|
||||
|
||||
|
||||
@admin.register(AuditLog)
|
||||
|
||||
Reference in new issue
Block a user