Feat: Add catalog page with inline category renaming
- Create catalog view with category tree and product grid - Add grid/list view toggle for products - Implement inline category name editing (click to rename) - Add API endpoint for category rename - Extract JS to separate catalog.js file - Remove unused partial templates 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,7 @@ from django.core.cache import cache
|
||||
from django.core.exceptions import ValidationError
|
||||
import logging
|
||||
|
||||
from ..models import Product, ProductVariantGroup, ProductKit
|
||||
from ..models import Product, ProductVariantGroup, ProductKit, ProductCategory
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -873,3 +873,72 @@ def toggle_tag_status_api(request, pk):
|
||||
'success': False,
|
||||
'error': f'Ошибка при обновлении тега: {str(e)}'
|
||||
}, status=500)
|
||||
|
||||
|
||||
def rename_category_api(request, pk):
|
||||
"""
|
||||
AJAX endpoint для переименования категории (inline editing).
|
||||
|
||||
Принимает JSON:
|
||||
{
|
||||
"name": "Новое название"
|
||||
}
|
||||
|
||||
Возвращает JSON:
|
||||
{
|
||||
"success": true,
|
||||
"name": "Новое название"
|
||||
}
|
||||
"""
|
||||
if request.method != 'POST':
|
||||
return JsonResponse({
|
||||
'success': False,
|
||||
'error': 'Метод не поддерживается'
|
||||
}, status=405)
|
||||
|
||||
try:
|
||||
import json
|
||||
|
||||
data = json.loads(request.body)
|
||||
name = data.get('name', '').strip()
|
||||
|
||||
# Валидация
|
||||
if not name:
|
||||
return JsonResponse({
|
||||
'success': False,
|
||||
'error': 'Название категории не может быть пустым'
|
||||
}, status=400)
|
||||
|
||||
if len(name) > 255:
|
||||
return JsonResponse({
|
||||
'success': False,
|
||||
'error': 'Название слишком длинное (максимум 255 символов)'
|
||||
}, status=400)
|
||||
|
||||
# Получаем категорию
|
||||
category = ProductCategory.objects.get(pk=pk)
|
||||
|
||||
# Обновляем название
|
||||
category.name = name
|
||||
category.save(update_fields=['name'])
|
||||
|
||||
return JsonResponse({
|
||||
'success': True,
|
||||
'name': category.name
|
||||
})
|
||||
|
||||
except ProductCategory.DoesNotExist:
|
||||
return JsonResponse({
|
||||
'success': False,
|
||||
'error': 'Категория не найдена'
|
||||
}, status=404)
|
||||
except json.JSONDecodeError:
|
||||
return JsonResponse({
|
||||
'success': False,
|
||||
'error': 'Некорректный JSON'
|
||||
}, status=400)
|
||||
except Exception as e:
|
||||
return JsonResponse({
|
||||
'success': False,
|
||||
'error': f'Ошибка при переименовании: {str(e)}'
|
||||
}, status=500)
|
||||
|
||||
Reference in New Issue
Block a user