HH/apps/notifications/management/commands/init_notification_templates.py

309 lines
14 KiB
Python

"""
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': '''
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.header { background: #0d6efd; color: white; padding: 20px; text-align: center; }
.content { background: #f8f9fa; padding: 30px; margin: 20px 0; }
.button { display: inline-block; background: #0d6efd; color: white; padding: 12px 30px;
text-decoration: none; border-radius: 5px; margin: 20px 0; }
.footer { text-align: center; color: #6c757d; font-size: 12px; margin-top: 30px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Welcome to PX360!</h1>
</div>
<div class="content">
<h2>Hello {{first_name}},</h2>
<p>You have been invited to join PX360 - Patient Experience Management System.</p>
<p>To get started, please complete your registration by clicking the button below:</p>
<center>
<a href="{{activation_url}}" class="button">Complete Registration</a>
</center>
<p><strong>Important:</strong> This invitation will expire on {{expires_at}}.</p>
<p>If you have any questions, please contact your administrator.</p>
</div>
<div class="footer">
<p>If the button doesn't work, copy and paste this link:</p>
<p>{{activation_url}}</p>
<p>&copy; PX360 - Patient Experience Management System</p>
</div>
</div>
</body>
</html>
''',
'email_template_ar': '''
<!DOCTYPE html>
<html dir="rtl">
<head>
<meta charset="UTF-8">
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.header { background: #0d6efd; color: white; padding: 20px; text-align: center; }
.content { background: #f8f9fa; padding: 30px; margin: 20px 0; }
.button { display: inline-block; background: #0d6efd; color: white; padding: 12px 30px;
text-decoration: none; border-radius: 5px; margin: 20px 0; }
.footer { text-align: center; color: #6c757d; font-size: 12px; margin-top: 30px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>مرحباً بك في PX360!</h1>
</div>
<div class="content">
<h2>مرحباً {{first_name}}،</h2>
<p>لقد تمت دعوتك للانضمام إلى نظام إدارة تجربة المريض PX360.</p>
<p>للبدء، يرجى إكمال تسجيلك بالنقر على الزر أدناه:</p>
<center>
<a href="{{activation_url}}" class="button">إكمال التسجيل</a>
</center>
<p><strong>مهم:</strong> تنتهي صلاحية هذه الدعوة في {{expires_at}}.</p>
<p>إذا كان لديك أي أسئلة، يرجى الاتصال بالمسؤول.</p>
</div>
<div class="footer">
<p>إذا لم يعمل الزر، انسخ والصق هذا الرابط:</p>
<p>{{activation_url}}</p>
<p>&copy; PX360 - نظام إدارة تجربة المريض</p>
</div>
</div>
</body>
</html>
''',
'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': '''
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.header { background: #ffc107; color: #333; padding: 20px; text-align: center; }
.content { background: #f8f9fa; padding: 30px; margin: 20px 0; }
.button { display: inline-block; background: #0d6efd; color: white; padding: 12px 30px;
text-decoration: none; border-radius: 5px; margin: 20px 0; }
.alert { background: #fff3cd; border: 1px solid #ffc107; padding: 15px; margin: 20px 0; border-radius: 5px; }
.footer { text-align: center; color: #6c757d; font-size: 12px; margin-top: 30px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Registration Reminder</h1>
</div>
<div class="content">
<h2>Hello {{first_name}},</h2>
<div class="alert">
<strong>Your invitation will expire soon!</strong>
</div>
<p>This is a friendly reminder to complete your PX360 registration.</p>
<p>Your invitation expires on: <strong>{{expires_at}}</strong></p>
<center>
<a href="{{activation_url}}" class="button">Complete Registration Now</a>
</center>
<p>Don't miss out on accessing the PX360 system. Complete your registration today!</p>
</div>
<div class="footer">
<p>&copy; PX360 - Patient Experience Management System</p>
</div>
</div>
</body>
</html>
''',
'email_template_ar': '''
<!DOCTYPE html>
<html dir="rtl">
<head>
<meta charset="UTF-8">
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.header { background: #ffc107; color: #333; padding: 20px; text-align: center; }
.content { background: #f8f9fa; padding: 30px; margin: 20px 0; }
.button { display: inline-block; background: #0d6efd; color: white; padding: 12px 30px;
text-decoration: none; border-radius: 5px; margin: 20px 0; }
.alert { background: #fff3cd; border: 1px solid #ffc107; padding: 15px; margin: 20px 0; border-radius: 5px; }
.footer { text-align: center; color: #6c757d; font-size: 12px; margin-top: 30px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>تذكير بالتسجيل</h1>
</div>
<div class="content">
<h2>مرحباً {{first_name}}،</h2>
<div class="alert">
<strong>ستنتهي صلاحية دعوتك قريباً!</strong>
</div>
<p>هذا تذكير ودي لإكمال تسجيلك في PX360.</p>
<p>تنتهي صلاحية دعوتك في: <strong>{{expires_at}}</strong></p>
<center>
<a href="{{activation_url}}" class="button">أكمل التسجيل الآن</a>
</center>
<p>لا تفوت فرصة الوصول إلى نظام PX360. أكمل تسجيلك اليوم!</p>
</div>
<div class="footer">
<p>&copy; PX360 - نظام إدارة تجربة المريض</p>
</div>
</div>
</body>
</html>
''',
'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': '''
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.header { background: #198754; color: white; padding: 20px; text-align: center; }
.content { background: #f8f9fa; padding: 30px; margin: 20px 0; }
.details { background: white; padding: 20px; margin: 20px 0; border-left: 4px solid #198754; }
.footer { text-align: center; color: #6c757d; font-size: 12px; margin-top: 30px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Onboarding Complete</h1>
</div>
<div class="content">
<h2>Good News!</h2>
<p>A user has successfully completed their onboarding process.</p>
<div class="details">
<h3>User Details:</h3>
<p><strong>Name:</strong> {{user_name}}</p>
<p><strong>Email:</strong> {{user_email}}</p>
<p><strong>Role:</strong> {{user_role}}</p>
<p><strong>Hospital:</strong> {{hospital_name}}</p>
<p><strong>Completed At:</strong> {{completed_at}}</p>
</div>
<p>You can view the user's details in the admin dashboard.</p>
</div>
<div class="footer">
<p>&copy; PX360 - Patient Experience Management System</p>
</div>
</div>
</body>
</html>
''',
'email_template_ar': '''
<!DOCTYPE html>
<html dir="rtl">
<head>
<meta charset="UTF-8">
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.header { background: #198754; color: white; padding: 20px; text-align: center; }
.content { background: #f8f9fa; padding: 30px; margin: 20px 0; }
.details { background: white; padding: 20px; margin: 20px 0; border-right: 4px solid #198754; }
.footer { text-align: center; color: #6c757d; font-size: 12px; margin-top: 30px; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>اكتمال التسجيل</h1>
</div>
<div class="content">
<h2>أخبار سارة!</h2>
<p>أكمل أحد المستخدمين عملية التسجيل بنجاح.</p>
<div class="details">
<h3>تفاصيل المستخدم:</h3>
<p><strong>الاسم:</strong> {{user_name}}</p>
<p><strong>البريد الإلكتروني:</strong> {{user_email}}</p>
<p><strong>الدور:</strong> {{user_role}}</p>
<p><strong>المستشفى:</strong> {{hospital_name}}</p>
<p><strong>اكتمل في:</strong> {{completed_at}}</p>
</div>
<p>يمكنك عرض تفاصيل المستخدم في لوحة التحكم.</p>
</div>
<div class="footer">
<p>&copy; PX360 - نظام إدارة تجربة المريض</p>
</div>
</div>
</body>
</html>
''',
'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}')