Lifecycle Events System
Over the past week i have been focused on the user experience.
Specifically i implemented a lifecycle approach where various events trigger specific actions that are under our control. Actions are things like “Log The Event” or “Sent Email Template”
HerpesHearts includes a comprehensive lifecycle events system that automatically tracks user milestones, sends notifications, and maintains an audit log of important events.
Overview
The lifecycle events system provides:
Automatic UserAction logging for all lifecycle events
Configurable email notifications to users and/or staff
Extensible event handlers for custom business logic
Template-based email rendering with consistent branding
Available Lifecycle Events
| Event Name | Trigger | Notification Target | Email Template |
first_login | User logs in for first time | Staff | lifecycle_notification.html |
profile_activated | User makes profile visible | Staff | lifecycle_notification.html |
profile_completed | User fills all required fields | User | profile_completed.html |
profile_deleted | User deletes account | User + Staff | profile_deleted_user.html, profile_deleted_staff.html |
role_assigned | Admin assigns role | User + Staff | role_assigned.html |
badge_assigned | Admin assigns badge | User | badge_assigned.html |
first_message_sent | User sends first message | None (disabled) | first_message_sent.html |
first_message_received | User receives first message | None (disabled) | - |
first_like_sent | User sends first like | None (disabled) | first_like_sent.html |
first_like_received | User receives first like | None (disabled) | - |
first_profile_photo | User uploads first photo | None (disabled) | first_profile_photo.html |
Configuration
Lifecycle events are configured in src/profiles/lifecycle_events.py via the DEFAULT_LIFECYCLE_ACTIONS dictionary. You can override this in settings.py:
# In settings.py
LIFECYCLE_ACTIONS = {
'first_login': [
{
'type': 'email_notification',
'enabled': True,
'notification_target': 'staff', # 'staff', 'user', or 'both'
'staff_email': 'support@herpeshearts.com',
'subject': '[HerpesHearts] New User: {display_name}',
'template_name': 'emails/lifecycle_notification.html', # Optional
}
],
# ... more events
}
Notification Targets
Each event can notify:
staff- Sends to configured staff email (default: support@herpeshearts.com)user- Sends to the user's email addressboth- Sends to both staff and user
Template Variables
All email templates receive these standard variables:
display_name- User's profile display nameemail- User's email addressuser_id- User's database IDtimestamp- Event timestamp (formatted)event_name- Name of the lifecycle eventSITE_NAME- Site name from settingsSITE_PURPOSE- Site purpose from settings
Event-specific variables (e.g., role_name, badge_name, badge_description) are passed based on the event context.

