from django.core.management.base import BaseCommand from django.utils.text import slugify from support.models import ( TicketStatus, TicketPriority, TicketCategory, KnowledgeBaseCategory, KnowledgeBaseArticle ) class Command(BaseCommand): help = 'Populate support center with initial data' def handle(self, *args, **kwargs): self.stdout.write(self.style.SUCCESS('Starting to populate support data...')) # Create Ticket Statuses self.create_ticket_statuses() # Create Ticket Priorities self.create_ticket_priorities() # Create Ticket Categories self.create_ticket_categories() # Create Knowledge Base Categories self.create_kb_categories() # Create Knowledge Base Articles self.create_kb_articles() self.stdout.write(self.style.SUCCESS('Successfully populated support data!')) def create_ticket_statuses(self): self.stdout.write('Creating ticket statuses...') statuses = [ {'name': 'Open', 'color': '#3b82f6', 'description': 'Ticket has been opened', 'is_closed': False, 'display_order': 1}, {'name': 'In Progress', 'color': '#f59e0b', 'description': 'Ticket is being worked on', 'is_closed': False, 'display_order': 2}, {'name': 'Pending Response', 'color': '#8b5cf6', 'description': 'Waiting for customer response', 'is_closed': False, 'display_order': 3}, {'name': 'Resolved', 'color': '#10b981', 'description': 'Ticket has been resolved', 'is_closed': True, 'display_order': 4}, {'name': 'Closed', 'color': '#6b7280', 'description': 'Ticket has been closed', 'is_closed': True, 'display_order': 5}, ] for status_data in statuses: status, created = TicketStatus.objects.get_or_create( name=status_data['name'], defaults=status_data ) if created: self.stdout.write(self.style.SUCCESS(f' ✓ Created status: {status.name}')) else: self.stdout.write(f' - Status already exists: {status.name}') def create_ticket_priorities(self): self.stdout.write('Creating ticket priorities...') priorities = [ {'name': 'Low', 'level': 4, 'color': '#6b7280', 'description': 'Low priority issue', 'sla_hours': 72}, {'name': 'Medium', 'level': 3, 'color': '#3b82f6', 'description': 'Medium priority issue', 'sla_hours': 48}, {'name': 'High', 'level': 2, 'color': '#f59e0b', 'description': 'High priority issue', 'sla_hours': 24}, {'name': 'Critical', 'level': 1, 'color': '#ef4444', 'description': 'Critical issue requiring immediate attention', 'sla_hours': 4}, ] for priority_data in priorities: priority, created = TicketPriority.objects.get_or_create( name=priority_data['name'], defaults=priority_data ) if created: self.stdout.write(self.style.SUCCESS(f' ✓ Created priority: {priority.name}')) else: self.stdout.write(f' - Priority already exists: {priority.name}') def create_ticket_categories(self): self.stdout.write('Creating ticket categories...') categories = [ {'name': 'Technical Support', 'description': 'Technical issues and troubleshooting', 'color': '#3b82f6', 'icon': 'fa-wrench', 'display_order': 1}, {'name': 'Billing & Payments', 'description': 'Billing questions and payment issues', 'color': '#10b981', 'icon': 'fa-credit-card', 'display_order': 2}, {'name': 'Account Management', 'description': 'Account settings and access issues', 'color': '#8b5cf6', 'icon': 'fa-user-cog', 'display_order': 3}, {'name': 'Product Inquiry', 'description': 'Questions about products and features', 'color': '#f59e0b', 'icon': 'fa-box', 'display_order': 4}, {'name': 'Bug Reports', 'description': 'Report software bugs and issues', 'color': '#ef4444', 'icon': 'fa-bug', 'display_order': 5}, {'name': 'Feature Requests', 'description': 'Request new features or improvements', 'color': '#06b6d4', 'icon': 'fa-lightbulb', 'display_order': 6}, ] for category_data in categories: category, created = TicketCategory.objects.get_or_create( name=category_data['name'], defaults=category_data ) if created: self.stdout.write(self.style.SUCCESS(f' ✓ Created category: {category.name}')) else: self.stdout.write(f' - Category already exists: {category.name}') def create_kb_categories(self): self.stdout.write('Creating knowledge base categories...') categories = [ {'name': 'Getting Started', 'slug': 'getting-started', 'description': 'Learn the basics and get started quickly', 'icon': 'fa-rocket', 'color': '#3b82f6', 'display_order': 1}, {'name': 'Account & Billing', 'slug': 'account-billing', 'description': 'Manage your account and billing information', 'icon': 'fa-user-circle', 'color': '#10b981', 'display_order': 2}, {'name': 'Technical Documentation', 'slug': 'technical-docs', 'description': 'Technical guides and API documentation', 'icon': 'fa-code', 'color': '#8b5cf6', 'display_order': 3}, {'name': 'Troubleshooting', 'slug': 'troubleshooting', 'description': 'Common issues and how to resolve them', 'icon': 'fa-tools', 'color': '#f59e0b', 'display_order': 4}, {'name': 'Security & Privacy', 'slug': 'security-privacy', 'description': 'Security features and privacy settings', 'icon': 'fa-shield-alt', 'color': '#ef4444', 'display_order': 5}, {'name': 'Best Practices', 'slug': 'best-practices', 'description': 'Tips and best practices for optimal use', 'icon': 'fa-star', 'color': '#daa520', 'display_order': 6}, ] for category_data in categories: category, created = KnowledgeBaseCategory.objects.get_or_create( slug=category_data['slug'], defaults=category_data ) if created: self.stdout.write(self.style.SUCCESS(f' ✓ Created KB category: {category.name}')) else: self.stdout.write(f' - KB category already exists: {category.name}') def create_kb_articles(self): self.stdout.write('Creating knowledge base articles...') # Get categories getting_started = KnowledgeBaseCategory.objects.filter(slug='getting-started').first() account_billing = KnowledgeBaseCategory.objects.filter(slug='account-billing').first() technical = KnowledgeBaseCategory.objects.filter(slug='technical-docs').first() troubleshooting = KnowledgeBaseCategory.objects.filter(slug='troubleshooting').first() articles = [ { 'title': 'How to Get Started with Our Platform', 'slug': 'how-to-get-started', 'category': getting_started, 'summary': 'A comprehensive guide to help you get started with our platform quickly and easily.', 'content': '''

Welcome to Our Platform!

This guide will help you get started with our platform in just a few simple steps.

Step 1: Create Your Account

Visit our sign-up page and create your account using your email address or social login.

Step 2: Complete Your Profile

Add your company information and customize your profile settings.

Step 3: Explore the Dashboard

Familiarize yourself with the main dashboard and available features.

Step 4: Start Using Our Services

Begin using our services and tools to achieve your business goals.

If you need any help, our support team is always here to assist you!

''', 'is_published': True, 'is_featured': True, }, { 'title': 'Understanding Your Billing Cycle', 'slug': 'understanding-billing-cycle', 'category': account_billing, 'summary': 'Learn how our billing cycle works and how to manage your payments.', 'content': '''

Billing Cycle Overview

Understanding your billing cycle is important for managing your subscription effectively.

Monthly Billing

For monthly subscriptions, you'll be charged on the same date each month.

Annual Billing

Annual subscriptions offer a discount and are billed once per year.

Managing Your Subscription

You can upgrade, downgrade, or cancel your subscription at any time from your account settings.

''', 'is_published': True, 'is_featured': True, }, { 'title': 'API Documentation Overview', 'slug': 'api-documentation-overview', 'category': technical, 'summary': 'Complete guide to our API endpoints and authentication.', 'content': '''

API Documentation

Our API provides programmatic access to all platform features.

Authentication

All API requests require authentication using an API key.

Authorization: Bearer YOUR_API_KEY

Rate Limits

Standard accounts are limited to 1000 requests per hour.

Response Format

All responses are returned in JSON format.

''', 'is_published': True, 'is_featured': True, }, { 'title': 'Common Login Issues and Solutions', 'slug': 'common-login-issues', 'category': troubleshooting, 'summary': 'Troubleshoot common login problems and learn how to resolve them.', 'content': '''

Login Troubleshooting

Having trouble logging in? Here are some common issues and solutions.

Forgot Password

Click "Forgot Password" on the login page to reset your password via email.

Account Locked

After multiple failed login attempts, your account may be temporarily locked for security.

Browser Issues

Clear your browser cache and cookies, or try a different browser.

Still Having Issues?

Contact our support team for personalized assistance.

''', 'is_published': True, 'is_featured': False, }, { 'title': 'How to Update Your Payment Method', 'slug': 'update-payment-method', 'category': account_billing, 'summary': 'Step-by-step guide to updating your payment information.', 'content': '''

Updating Payment Information

Keep your payment method up to date to avoid service interruptions.

Steps to Update

  1. Go to Account Settings
  2. Click on "Billing & Payments"
  3. Select "Update Payment Method"
  4. Enter your new payment details
  5. Click "Save Changes"

Supported Payment Methods

We accept all major credit cards, PayPal, and bank transfers.

''', 'is_published': True, 'is_featured': False, }, { 'title': 'Security Best Practices', 'slug': 'security-best-practices', 'category': KnowledgeBaseCategory.objects.filter(slug='security-privacy').first(), 'summary': 'Essential security practices to keep your account safe.', 'content': '''

Account Security

Follow these best practices to keep your account secure.

Use Strong Passwords

Create complex passwords with a mix of letters, numbers, and symbols.

Enable Two-Factor Authentication

Add an extra layer of security with 2FA.

Regular Security Audits

Review your account activity regularly for any suspicious behavior.

Keep Software Updated

Always use the latest version of our software for the best security.

''', 'is_published': True, 'is_featured': True, }, ] for article_data in articles: if article_data['category']: article, created = KnowledgeBaseArticle.objects.get_or_create( slug=article_data['slug'], defaults=article_data ) if created: self.stdout.write(self.style.SUCCESS(f' ✓ Created article: {article.title}')) else: self.stdout.write(f' - Article already exists: {article.title}')