B
    ¤0H[S!  ã               @   s�   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZ dd	lmZ G d
d„ deƒZG dd„ deƒZdS )z*
Management utility to create superusers.
é    N)Úget_user_model)Úget_default_username)Úvalidate_password)Ú
exceptions)ÚBaseCommandÚCommandError)ÚDEFAULT_DB_ALIAS)Úcapfirstc               @   s   e Zd ZdS )ÚNotRunningInTTYExceptionN)Ú__name__Ú
__module__Ú__qualname__© r   r   ú{C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\django\contrib\auth\management\commands\createsuperuser.pyr
      s   r
   c                   sN   e Zd ZdZdZdZ‡ fdd„Zdd„ Z‡ fdd	„Zd
d„ Z	ddd„Z
‡  ZS )ÚCommandzUsed to create a superuser.T)Ústdinc                s.   t ƒ j||Ž tƒ | _| jj | jj¡| _d S )N)ÚsuperÚ__init__r   Ú	UserModelÚ_metaÚ	get_fieldÚUSERNAME_FIELDÚusername_field)ÚselfÚargsÚkwargs)Ú	__class__r   r   r      s    zCommand.__init__c             C   s~   |j d| jj | jjd dd� |j ddddd| jj d	� |j d
ddtdd� x*| jjD ]}|j d| |d d| d� qXW d S )Nz--%sz&Specifies the login for the superuser.)ÚdestÚdefaultÚhelpz	--noinputz
--no-inputÚstore_falseÚinteractivezòTells Django to NOT prompt the user for input of any kind. You must use --%s with --noinput, along with an option for any other required field. Superusers created with --noinput will not be able to log in until they're given a valid password.)Úactionr   r   z
--databaseÚstoreÚdatabasez4Specifies the database to use. Default is "default".)r"   r   r   r   z#Specifies the %s for the superuser.)Úadd_argumentr   r   r   ÚREQUIRED_FIELDS)r   ÚparserÚfieldr   r   r   Úadd_arguments   s     

zCommand.add_argumentsc                s   |  dtj¡| _tƒ j||ŽS )Nr   )ÚgetÚsysr   r   Úexecute)r   r   Úoptions)r   r   r   r,   9   s    zCommand.executec          
   O   sÊ  || j j }|d }d }i }i }|d sÒyp|s>td| j j ƒ‚| j |d ¡}xH| j jD ]<}|| r†| j j |¡}	|	 || d ¡||< qVtd| ƒ‚qVW W n4 tj	k
rÌ }
 ztd 
|
j¡ƒ‚W d d }
~
X Y nX �nªtƒ }�yTt| jdƒrú| j ¡ sútdƒ‚| jj}xÄ|d k�rÆt|ƒ}|�r(|d| 7 }| jj}d||�rNd	|jjj|jf nd
f }|  | j||¡}|�sp�q| jj�ry| j j |¡ |¡ W n | j jk
�r¬   Y nX | j d| ¡ d }�qW x¨| j jD ]œ}| j j |¡}	|| ||< xz|| d k�rjdt|	jƒ|	j�r*d	|	jjjj|	jjf nd
f }|  |	|¡}|||< |||< |	j�rò|	j |¡||< �qòW �qÒW x¸|d k�r*t ¡ }t d¡}||k�r®| j d¡ d }�qt|  ¡ d
k�rÐ| j d¡ d }�qtyt!|| j f |Žƒ W n> tj	k
�r$ } z| j d 
|j¡¡ d }W d d }~X Y nX �qtW W nL t"k
�rZ   | j d¡ t# $d¡ Y n" tk
�rz   | j% d¡ Y nX |�rÆ||| j j< ||d< | j j |¡j&f |Ž |d dk�rÆ| j% d¡ d S )Nr$   r!   z!You must use --%s with --noinput.z; ÚisattyzNot running in a TTYz (leave blank to use '%s')z%s%s: z (%s.%s)Ú z Error: That %s is already taken.zPassword (again): z#Error: Your passwords didn't match.z&Error: Blank passwords aren't allowed.Ú
z
Operation cancelled.é   z‡Superuser creation skipped due to not running in a TTY. You can run `manage.py createsuperuser` in your project to create one manually.ÚpasswordÚ	verbosityzSuperuser created successfully.)'r   r   r   r   Úcleanr&   r   r   r   ÚValidationErrorÚjoinÚmessagesr   Úhasattrr   r.   r
   Zverbose_namer	   Zremote_fieldÚmodelZobject_nameÚ
field_nameÚget_input_dataÚuniqueZ_default_managerZ
db_managerZget_by_natural_keyZDoesNotExistÚstderrÚwriteÚgetpassÚstripr   ÚKeyboardInterruptr+   ÚexitÚstdoutZcreate_superuser)r   r   r-   Úusernamer$   r2   Z	user_dataZfake_user_datar:   r(   ÚeZdefault_usernameZverbose_field_nameZ	input_msgZusername_relÚmessageZinput_valueZ	password2Úerrr   r   r   Úhandle=   s     &"

(

 zCommand.handleNc          
   C   sn   t |ƒ}|r|dkr|}y| |d¡}W n@ tjk
rh } z | j dd |j¡ ¡ d}W dd}~X Y nX |S )zm
        Override this method if you want to customize data inputs or
        validation exceptions.
        r/   Nz	Error: %sz; )Úinputr4   r   r5   r=   r>   r6   r7   )r   r(   rF   r   Z	raw_valueÚvalrE   r   r   r   r;   ·   s    zCommand.get_input_data)N)r   r   r   r   Zrequires_migrations_checksZstealth_optionsr   r)   r,   rH   r;   Ú__classcell__r   r   )r   r   r      s   zr   )Ú__doc__r?   r+   Zdjango.contrib.authr   Zdjango.contrib.auth.managementr   Z'django.contrib.auth.password_validationr   Zdjango.corer   Zdjango.core.management.baser   r   Z	django.dbr   Zdjango.utils.textr	   Ú	Exceptionr
   r   r   r   r   r   Ú<module>   s   