
    kh                     V    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dS )    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                 n    |                     ddddd           |                     ddddd	           d S )
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     g/var/www/histauto/venv/lib/python3.11/site-packages/django_extensions/management/email_notifications.pyadd_argumentsz&EmailNotificationCommand.add_arguments2   sf    #&8 	 	
 	
 	
 	"5 	 	
 	
 	
 	
 	
    c                 ~    d                     |          | _        t                                          |           dS )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_argvB   s3    88D>>d#####r   c                     	  t                      j        |i | dS # t          $ r1 |d         st          | dd          r|                     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.executeG   s    	EGGOT-W----- 	 	 	() EWT;Le-T-T E,,t,DDD	s	    ;ANF   c           
         |4	 t           j                            |i           }n# t          $ r i }Y nw xY wi }|s?|                    dd          s)t	          | j                            d                     dS |                    dd          }| j                            d          d         }|                    d	d
|z            }|re|                    dd          sO	 t          j
                    \  }}	}
d                    t          j        |
                    }|d|z  z  }~
n# ~
w xY w|                    dt           j                  }t          |                    dg                     }|                    dd          s|                    t           j                   |s/|dk    r't	          | j                            d                     dS t%          |||||                    dd                     dS )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)r2   )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/   r0   s                 r   r#   z0EmailNotificationCommand.send_email_notificationW   sD    &$!)!=!A!A/SU!V!V! $ $ $!#$  N ! 	););<PRS)T)T 	$*""#JKKLLLF !$$Y0WXX,,S11"5!!:\I
 

  	"^%7%7%N%N 	""58\^^2)]ggi1-@@AA0366!MM!!!! $''h6QRR
 .,,\2>>??
!!+u55 	/ho... 	1}}dj&&'GHHIIIF 	(,,_dCC	
 	
 	
 	
 	
 	
s    % 44"AD* *D-)NFr&   )	__name__r9   __qualname____doc__r   r   r    r#   __classcell__)r   s   @r   r   r   
   s        % %N
 
 
 $ $ $ $ $
    " HI?
 ?
 ?
 ?
 ?
 ?
 ?
 ?
r   r   )	r;   r=   django.confr   django.core.mailr   django.core.managementr   r    r   r   <module>rS      s    



                 & & & & & & . . . . . .L
 L
 L
 L
 L
{ L
 L
 L
 L
 L
r   