95 lines
3.4 KiB
Python
95 lines
3.4 KiB
Python
|
|
import os
|
|||
|
|
from django.core.management.base import BaseCommand
|
|||
|
|
from apps.projects.models import Project, Asset
|
|||
|
|
from apps.templates.models import CardTemplate
|
|||
|
|
|
|||
|
|
|
|||
|
|
class Command(BaseCommand):
|
|||
|
|
help = 'Initialize cards design system with sample data'
|
|||
|
|
|
|||
|
|
def handle(self, *args, **options):
|
|||
|
|
self.stdout.write(self.style.SUCCESS('Starting initialization...'))
|
|||
|
|
|
|||
|
|
self.create_templates()
|
|||
|
|
self.create_sample_project()
|
|||
|
|
|
|||
|
|
self.stdout.write(self.style.SUCCESS('Initialization complete!'))
|
|||
|
|
|
|||
|
|
def create_templates(self):
|
|||
|
|
"""创建示例模板"""
|
|||
|
|
templates = [
|
|||
|
|
{
|
|||
|
|
'id': 'classic',
|
|||
|
|
'name': '经典风格',
|
|||
|
|
'description': '标准扑克牌设计,传统花色和字体',
|
|||
|
|
'color_spade': '#000000',
|
|||
|
|
'color_heart': '#E53935',
|
|||
|
|
'color_club': '#000000',
|
|||
|
|
'color_diamond': '#E53935',
|
|||
|
|
'color_background': '#FFFFFF',
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
'id': 'modern',
|
|||
|
|
'name': '现代简约',
|
|||
|
|
'description': '扁平化设计,简洁线条',
|
|||
|
|
'color_spade': '#333333',
|
|||
|
|
'color_heart': '#E53935',
|
|||
|
|
'color_club': '#333333',
|
|||
|
|
'color_diamond': '#E53935',
|
|||
|
|
'color_background': '#FAFAFA',
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
'id': 'cartoon',
|
|||
|
|
'name': '卡通风格',
|
|||
|
|
'description': 'Q版可爱人像,圆润花色图案',
|
|||
|
|
'color_spade': '#4A4A4A',
|
|||
|
|
'color_heart': '#FF6B9D',
|
|||
|
|
'color_club': '#4A4A4A',
|
|||
|
|
'color_diamond': '#FF6B9D',
|
|||
|
|
'color_background': '#FFF9E6',
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
'id': 'vintage',
|
|||
|
|
'name': '复古风格',
|
|||
|
|
'description': '复古色调和纹理,装饰性边框',
|
|||
|
|
'color_spade': '#2C1810',
|
|||
|
|
'color_heart': '#8B4513',
|
|||
|
|
'color_club': '#2C1810',
|
|||
|
|
'color_diamond': '#8B4513',
|
|||
|
|
'color_background': '#F5DEB3',
|
|||
|
|
},
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
for td in templates:
|
|||
|
|
template, created = CardTemplate.objects.update_or_create(
|
|||
|
|
id=td['id'],
|
|||
|
|
defaults={
|
|||
|
|
'name': td['name'],
|
|||
|
|
'description': td['description'],
|
|||
|
|
'color_spade': td['color_spade'],
|
|||
|
|
'color_heart': td['color_heart'],
|
|||
|
|
'color_club': td['color_club'],
|
|||
|
|
'color_diamond': td['color_diamond'],
|
|||
|
|
'color_background': td['color_background'],
|
|||
|
|
'default_assets': td,
|
|||
|
|
},
|
|||
|
|
)
|
|||
|
|
verb = 'created' if created else 'updated'
|
|||
|
|
self.stdout.write(f' template {template.id} {verb}')
|
|||
|
|
|
|||
|
|
def create_sample_project(self):
|
|||
|
|
"""创建示例项目:完整可玩的 54 张牌"""
|
|||
|
|
project, created = Project.objects.update_or_create(
|
|||
|
|
name="示例项目",
|
|||
|
|
defaults=dict(
|
|||
|
|
template_id='classic',
|
|||
|
|
card_width=750,
|
|||
|
|
card_height=1050,
|
|||
|
|
export_resolution='standard',
|
|||
|
|
export_include_back=True,
|
|||
|
|
),
|
|||
|
|
)
|
|||
|
|
verb = 'created' if created else 'updated'
|
|||
|
|
self.stdout.write(f' project "{project.name}" {verb}')
|
|||
|
|
self.stdout.write(self.style.SUCCESS(f'示例项目 ID: {project.id}'))
|