a
    E´#jÿ  ã                   @   sF   d Z ddlZddlmZ ddlmZ ddlmZ e d¡Z	dd„ Z
dS )	zK
notifications.py
Handles outgoing email notifications for the events app.
é    N)Úsettings)Ú	send_mail)Úrender_to_stringÚvcksc           	   
   C   sR  | j }|j}| ||dœ}d|j› d|j› d| j› �}z8td|ƒ}t||tj| jgdd� t	 
d| j| j¡ W n4 ty  } zt	 d| j|¡ W Y d	}~n
d	}~0 0 |jsºt	 
d
|j¡ d	S d|j› d|j› d| j› d| j› �}z8td|ƒ}t||tj|jgdd� t	 
d|j| j¡ W n6 t�yL } zt	 d| j|¡ W Y d	}~n
d	}~0 0 d	S )aN  
    Sends two emails after a successful registration:
      1. Confirmation to the registrant.
      2. Internal notification to the event-specific mailbox (skipped if not configured).

    All mail failures are logged but never raise, so registration is never blocked.

    :param registration: The saved Registration instance.
    )ÚregistrationÚ
tournamentÚeventz
Anmeldung ú z(events/email_registrant_confirmation.txtF)ÚsubjectÚmessageÚ
from_emailÚrecipient_listÚfail_silentlyz7Registrant confirmation sent to %s for registration %s.z>Failed to send registrant confirmation for registration %s: %sNuQ   No registration_mail configured for event %s â€“ skipping organizer notification.ú[u    â€“ z] Neue Anmeldung: z'events/email_organizer_notification.txtz6Organizer notification sent to %s for registration %s.z=Failed to send organizer notification for registration %s: %s)r   r   ÚnameÚclubr   r   r   ÚDEFAULT_FROM_EMAILÚmailÚloggerÚinfoÚpkÚ	ExceptionÚerrorÚregistration_mailÚteam)	r   r   r   ÚcontextZregistrant_subjectZregistrant_bodyÚexcZorganizer_subjectZorganizer_body© r   ú=/var/www/test.vcks.de/backend/backend/events/notifications.pyÚsend_registration_notifications   sv    
ýÿûþþþÿÿÿÿûþþr   )Ú__doc__ÚloggingÚdjango.confr   Údjango.core.mailr   Údjango.template.loaderr   Ú	getLoggerr   r   r   r   r   r   Ú<module>   s   
