""" Management command to initialize default notification templates """ from django.core.management.base import BaseCommand from apps.notifications.models import NotificationTemplate class Command(BaseCommand): help = 'Initialize default notification templates for onboarding and other features' def handle(self, *args, **options): self.stdout.write('Initializing notification templates...') self.create_onboarding_templates() self.stdout.write(self.style.SUCCESS('Notification templates initialized successfully!')) def create_onboarding_templates(self): """Create default onboarding email templates""" self.stdout.write('Creating onboarding templates...') templates = [ { 'name': 'Onboarding Invitation', 'template_type': 'onboarding_invitation', 'description': 'Sent to new users to invite them to complete onboarding', 'email_subject': 'Welcome to PX360 - Complete Your Registration', 'email_subject_ar': 'مرحباً بك في PX360 - أكمل تسجيلك', 'email_template': '''

Welcome to PX360!

Hello {{first_name}},

You have been invited to join PX360 - Patient Experience Management System.

To get started, please complete your registration by clicking the button below:

Complete Registration

Important: This invitation will expire on {{expires_at}}.

If you have any questions, please contact your administrator.

''', 'email_template_ar': '''

مرحباً بك في PX360!

مرحباً {{first_name}}،

لقد تمت دعوتك للانضمام إلى نظام إدارة تجربة المريض PX360.

للبدء، يرجى إكمال تسجيلك بالنقر على الزر أدناه:

إكمال التسجيل

مهم: تنتهي صلاحية هذه الدعوة في {{expires_at}}.

إذا كان لديك أي أسئلة، يرجى الاتصال بالمسؤول.

''', 'sms_template': 'Welcome to PX360! Complete your registration here: {{activation_url}}. Expires: {{expires_at}}', 'sms_template_ar': 'مرحباً بك في PX360! أكمل تسجيلك هنا: {{activation_url}}. تنتهي الصلاحية: {{expires_at}}', }, { 'name': 'Onboarding Reminder', 'template_type': 'onboarding_reminder', 'description': 'Reminder to complete onboarding before invitation expires', 'email_subject': 'Reminder: Complete Your PX360 Registration', 'email_subject_ar': 'تذكير: أكمل تسجيلك في PX360', 'email_template': '''

Registration Reminder

Hello {{first_name}},

Your invitation will expire soon!

This is a friendly reminder to complete your PX360 registration.

Your invitation expires on: {{expires_at}}

Complete Registration Now

Don't miss out on accessing the PX360 system. Complete your registration today!

''', 'email_template_ar': '''

تذكير بالتسجيل

مرحباً {{first_name}}،

ستنتهي صلاحية دعوتك قريباً!

هذا تذكير ودي لإكمال تسجيلك في PX360.

تنتهي صلاحية دعوتك في: {{expires_at}}

أكمل التسجيل الآن

لا تفوت فرصة الوصول إلى نظام PX360. أكمل تسجيلك اليوم!

''', 'sms_template': 'Reminder: Your PX360 invitation expires on {{expires_at}}. Complete now: {{activation_url}}', 'sms_template_ar': 'تذكير: تنتهي صلاحية دعوتك في PX360 في {{expires_at}}. أكمل الآن: {{activation_url}}', }, { 'name': 'Onboarding Completion - Admin Notification', 'template_type': 'onboarding_completion', 'description': 'Sent to admins when a user completes onboarding', 'email_subject': 'User Completed Onboarding - {{user_name}}', 'email_subject_ar': 'أكمل المستخدم التسجيل - {{user_name}}', 'email_template': '''

Onboarding Complete

Good News!

A user has successfully completed their onboarding process.

User Details:

Name: {{user_name}}

Email: {{user_email}}

Role: {{user_role}}

Hospital: {{hospital_name}}

Completed At: {{completed_at}}

You can view the user's details in the admin dashboard.

''', 'email_template_ar': '''

اكتمال التسجيل

أخبار سارة!

أكمل أحد المستخدمين عملية التسجيل بنجاح.

تفاصيل المستخدم:

الاسم: {{user_name}}

البريد الإلكتروني: {{user_email}}

الدور: {{user_role}}

المستشفى: {{hospital_name}}

اكتمل في: {{completed_at}}

يمكنك عرض تفاصيل المستخدم في لوحة التحكم.

''', 'sms_template': '{{user_name}} has completed PX360 onboarding. Role: {{user_role}}, Hospital: {{hospital_name}}', 'sms_template_ar': 'أكمل {{user_name}} التسجيل في PX360. الدور: {{user_role}}، المستشفى: {{hospital_name}}', }, ] for template_data in templates: template, created = NotificationTemplate.objects.update_or_create( name=template_data['name'], defaults={ 'template_type': template_data['template_type'], 'description': template_data['description'], 'email_subject': template_data['email_subject'], 'email_subject_ar': template_data['email_subject_ar'], 'email_template': template_data['email_template'].strip(), 'email_template_ar': template_data['email_template_ar'].strip(), 'sms_template': template_data.get('sms_template', ''), 'sms_template_ar': template_data.get('sms_template_ar', ''), 'whatsapp_template': template_data.get('whatsapp_template', ''), 'whatsapp_template_ar': template_data.get('whatsapp_template_ar', ''), 'is_active': True, } ) action = 'Created' if created else 'Updated' self.stdout.write(f' {action}: {template.name}')