Hospital: {appreciation.hospital.name}
{f'Category: {appreciation.category.name_en}
' if appreciation.category else ''}
Message:
{appreciation.message_en}
Congratulations on this recognition! Your dedication is truly appreciated.
""" Appreciation signals - Signal handlers for appreciation events This module handles: - Sending notifications when appreciations are sent - Updating statistics when appreciations are created - Checking and awarding badges """ from django.db.models import Q from django.db.models.signals import post_save from django.dispatch import receiver from django.utils import timezone from apps.appreciation.models import ( Appreciation, AppreciationBadge, AppreciationStats, AppreciationStatus, UserBadge, ) @receiver(post_save, sender=Appreciation) def handle_appreciation_sent(sender, instance, created, **kwargs): """ Handle appreciation sent events. This signal triggers: 1. Send notification to recipient 2. Update statistics 3. Check for badge awards """ # Only process when appreciation is sent (status changes to 'sent') if instance.status == AppreciationStatus.SENT and not instance.notification_sent: # Send notification send_appreciation_notification(instance) # Update statistics update_appreciation_stats(instance) # Check for badge awards check_and_award_badges(instance) def send_appreciation_notification(appreciation): """ Send notification to recipient when appreciation is sent. Uses the notification system to send email/SMS/WhatsApp. """ try: from apps.notifications.services import send_email, send_sms # Get recipient details recipient_email = appreciation.get_recipient_email() recipient_phone = appreciation.get_recipient_phone() # Get sender name sender_name = "Anonymous" if appreciation.is_anonymous else appreciation.sender.get_full_name() # Build HTML with navy theme html_message = f"""
Congratulations on this recognition! Your dedication is truly appreciated.