58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script to generate notifications and test SSE functionality
|
|
"""
|
|
import os
|
|
import sys
|
|
import django
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'NorahUniversity.settings')
|
|
django.setup()
|
|
|
|
from django.utils import timezone
|
|
from django.contrib.auth.models import User
|
|
from recruitment.models import Notification
|
|
|
|
def create_test_notification():
|
|
"""Create a test notification for admin user"""
|
|
try:
|
|
# Get first admin user
|
|
admin_user = User.objects.filter(is_staff=True).first()
|
|
if not admin_user:
|
|
print("No admin user found!")
|
|
return
|
|
|
|
# Create a test notification
|
|
notification = Notification.objects.create(
|
|
recipient=admin_user,
|
|
notification_type=Notification.NotificationType.IN_APP,
|
|
message="Test SSE Notification - Real-time update working!",
|
|
status=Notification.Status.PENDING,
|
|
scheduled_for=timezone.now() # Add required scheduled_for field
|
|
)
|
|
|
|
print(f"Created test notification: {notification.id}")
|
|
print(f"Recipient: {admin_user.username}")
|
|
print(f"Message: {notification.message}")
|
|
print(f"Status: {notification.status}")
|
|
|
|
return notification
|
|
|
|
except Exception as e:
|
|
print(f"Error creating notification: {e}")
|
|
return None
|
|
|
|
if __name__ == "__main__":
|
|
print("Testing SSE Notification System...")
|
|
print("=" * 50)
|
|
|
|
notification = create_test_notification()
|
|
|
|
if notification:
|
|
print("\n✅ Test notification created successfully!")
|
|
print("🔥 Check the browser console for SSE events")
|
|
print("📱 Open http://localhost:8000/ and look for real-time updates")
|
|
else:
|
|
print("\n❌ Failed to create test notification")
|