Files
game-cards-poker-design/backend/apps/templates/views.py
Poker Design Developer 48629736f4 Implement Django backend and Vue frontend structure
- Django backend with projects, templates, exports apps
- SQLite database models for Project, Asset, CardLayer
- REST API endpoints for project management
- Vue frontend with Vite, Element Plus, Fabric.js
- Home page for project selection
- Editor page with Fabric.js canvas integration
2026-05-31 14:55:01 +08:00

59 lines
1.9 KiB
Python

from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from .models import CardTemplate
@api_view(['GET'])
def template_list(request):
"""获取所有模板列表"""
templates = CardTemplate.objects.all()
data = []
for template in templates:
data.append({
'id': template.id,
'name': template.name,
'description': template.description,
'preview_image': template.preview_image.url if template.preview_image else None,
'colors': {
'spade': template.color_spade,
'heart': template.color_heart,
'club': template.color_club,
'diamond': template.color_diamond,
'background': template.color_background,
},
})
return Response(data)
@api_view(['GET'])
def template_detail(request, pk):
"""获取模板详情"""
try:
template = CardTemplate.objects.get(pk=pk)
except CardTemplate.DoesNotExist:
return Response({'error': 'Template not found'}, status=status.HTTP_404_NOT_FOUND)
data = {
'id': template.id,
'name': template.name,
'description': template.description,
'preview_image': template.preview_image.url if template.preview_image else None,
'colors': {
'spade': template.color_spade,
'heart': template.color_heart,
'club': template.color_club,
'diamond': template.color_diamond,
'background': template.color_background,
},
'default_assets': template.default_assets,
'suit_symbols': {
ss.suit_name: {
'svg_path': ss.svg_path,
'color': ss.color,
}
for ss in template.suit_symbols.all()
}
}
return Response(data)