Ë
    qûàgð  ã                   óN   — d dl Z d dlZd dlmZ d dlmZ d dlmZ  G d„ de«      Zy)é    N)Úsettings)Ú	send_mail)ÚBaseCommandc                   ó:   ‡ — e Zd ZdZd„ Zˆ fd„Zˆ fd„Zdd„Zˆ xZS )ÚEmailNotificationCommanda   
    A BaseCommand subclass which adds sending email fuctionality.

    Subclasses will have an extra command line option ``--email-notification``
    and will be able to send emails by calling ``send_email_notification()``
    if SMTP host and port are specified in settings. The handling of the
    command line option is left to the management command implementation.
    Configuration is done in settings.EMAIL_NOTIFICATIONS dict.

    Configuration example::

        EMAIL_NOTIFICATIONS = {
            'scripts.my_script': {
                'subject': 'my_script subject',
                'body': 'my_script body',
                'from_email': 'from_email@example.com',
                'recipients': ('recipient0@example.com',),
                'no_admins': False,
                'no_traceback': False,
                'notification_level': 0,
                'fail_silently': False
            },
            'scripts.another_script': {
                ...
            },
            ...
        }

    Configuration explained:
        subject:            Email subject.
        body:               Email body.
        from_email:         Email from address.
        recipients:         Sequence of email recipient addresses.
        no_admins:          When True do not include ADMINS to recipients.
        no_traceback:       When True do not include traceback to email body.
        notification_level: 0: send email on fail, 1: send email always.
        fail_silently:      Parameter passed to django's send_mail().
    c                 ó\   — |j                  ddddd¬«       |j                  ddddd	¬«       y )
Nz--email-notificationsÚ
store_trueFÚemail_notificationsz%Send email notifications for command.)ÚactionÚdefaultÚdestÚhelpz--email-exceptionÚemail_exceptionz"Send email for command exceptions.)Úadd_argument)ÚselfÚparsers     ún/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/django_extensions/management/email_notifications.pyÚadd_argumentsz&EmailNotificationCommand.add_arguments2   sJ   € Ø×ÑÐ3Ø#/Ø$)Ø!6Ø!Hð	 	ô 	Jð
 	×ÑÐ/Ø#/Ø$)Ø!2Ø!Eð	 	õ 	Gó    c                 óP   •— dj                  |«      | _        t        ‰| �  |«       y)z8Overriden in order to access the command line arguments.ú N)ÚjoinÚargv_stringÚsuperÚrun_from_argv)r   ÚargvÚ	__class__s     €r   r   z&EmailNotificationCommand.run_from_argv>   s    ø€ àŸ8™8 D›>ˆÔÜ‰Ñ˜dÕ#r   c                 óŠ   •— 	 t        ‰| �  |i |¤Ž y# t        $ r& |d   st        | dd«      r| j	                  d¬«       ‚ w xY w)aJ  
        Overriden in order to send emails on unhandled exception.

        If an unhandled exception in ``def handle(self, *args, **options)``
        occurs and `--email-exception` is set or `self.email_exception` is
        set to True send an email to ADMINS with the traceback and then
        reraise the exception.
        r   FT)Úinclude_tracebackN)r   ÚexecuteÚ	ExceptionÚgetattrÚsend_email_notification)r   ÚargsÚoptionsr   s      €r   r    z EmailNotificationCommand.executeC   sQ   ø€ ð	Ü‰G‰O˜TÐ- WÓ-øÜò 	ØÐ(Ò)¬W°TÐ;LÈeÔ-TØ×,Ñ,¸tÐ,ÔDØð	ús	   ƒ “/Ac           
      ó   — |�"	 t         j                  j                  |i «      }ni }|s7|j                  dd«      s%t	        | j
                  j                  d«      «       y|j                  dd«      }| j                  j                  d«      d   }|j                  d	d
|z  «      }|rX|j                  dd«      sF	 t        j                  «       \  }}	}
dj                  t        j                  |
«      «      }|d|z  z  }~
|j                  dt         j                  «      }t        |j                  dg «      «      }|j                  dd«      s|j!                  t         j"                  «       |s*|dkD  r$t	        | j
                  j                  d«      «       yt%        |||||j                  dd«      ¬«       y# t        $ r i }Y �ŒŸw xY w# ~
w xY w)zÒ
        Send email notifications.

        Reads settings from settings.EMAIL_NOTIFICATIONS dict, if available,
        using ``notification_id`` as a key or else provides reasonable
        defaults.
        NÚnotification_levelr   z%Exiting, not in 'notify always' mode.Úsubjectz%Django extensions email notification.ú.éÿÿÿÿÚbodyz$Reporting execution of command: '%s'Úno_tracebackFÚ z

Traceback:

%s
Ú
from_emailÚ
recipientsÚ	no_adminszNo email recipients available.Úfail_silentlyT)r1   )r   ÚEMAIL_NOTIFICATIONSÚgetÚAttributeErrorÚprintÚstyleÚERRORÚ
__module__ÚsplitÚsysÚexc_infor   Ú	tracebackÚ	format_tbÚDEFAULT_FROM_EMAILÚlistÚextendÚADMINSr   )r   Únotification_idr   Ú	verbosityÚemail_settingsr(   Úcommand_namer+   Úexc_typeÚ	exc_valueÚexc_tracebackÚtrbr.   r/   s                 r   r#   z0EmailNotificationCommand.send_email_notificationS   sº  € ð Ð&ð$Ü!)×!=Ñ!=×!AÑ!AÀ/ÐSUÓ!V‘ð  ˆNñ !¨×);Ñ);Ð<PÐRSÔ)TÜ�$—*‘*×"Ñ"Ð#JÓKÔLØð !×$Ñ$ YÐ0WÓXˆà—‘×,Ñ,¨SÓ1°"Ñ5ˆà×!Ñ!ØØ2°\ÑAó
ˆñ  ^×%7Ñ%7¸ÈÔ%Nð"Ü58·\±\³^Ñ2�˜) ]Ø—g‘gœi×1Ñ1°-Ó@ÓA�ØÐ0°3Ñ6Ñ6�à!ð $×'Ñ'¨´h×6QÑ6QÓRˆ
ô ˜.×,Ñ,¨\¸2Ó>Ó?ˆ
à×!Ñ! +¨uÔ5Ø×ÑœhŸo™oÔ.áØ˜1Š}Ü�d—j‘j×&Ñ&Ð'GÓHÔIØô 	�'˜4 ¨ZØ .× 2Ñ 2°?ÀDÓ Iö	KøôY "ò $Ø!#“ð$ûñ6 "ús   „ F8 Â:AG
 Æ8GÇGÇ
G)NFé   )	Ú__name__r8   Ú__qualname__Ú__doc__r   r   r    r#   Ú__classcell__)r   s   @r   r   r   
   s   ø„ ñ%òN
Gô$ô
÷ 9Kr   r   )	r:   r<   Údjango.confr   Údjango.core.mailr   Údjango.core.managementr   r   © r   r   ú<module>rS      s$   ðã 
Û å  Ý &Ý .ôBK˜{õ BKr   