
 X"                 @   s   d  Z  d d l m 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 d d l m Z d d l m Z Gd d   d e  Z Gd d   d e  Z d S)z*
Management utility to create superusers.
    )unicode_literalsN)get_user_model)get_default_username)validate_password)
exceptions)BaseCommandCommandError)DEFAULT_DB_ALIAS)	force_str)input)capfirstc               @   s   e  Z d  Z d S)NotRunningInTTYExceptionN)__name__
__module____qualname__ r   r   e/home/ubuntu/projects/ifolica/build/django/django/contrib/auth/management/commands/createsuperuser.pyr      s   r   c                   sg   e  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	   S)CommandzUsed to create a superuser.Tc                sG   t  t |   j | |   t   |  _ |  j j j |  j j  |  _ d  S)N)	superr   __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 d |  j j d d  d d | j  d d d d	 d d
 d d d d |  j j | j  d d d d d d t d d x; |  j j D]- } | j  d | d | d d  d d | q Wd  S)Nz--%sdestdefaulthelpz&Specifies the login for the superuser.z	--noinputz
--no-inputactionstore_falseinteractiveTzTells 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.z
--databasestoredatabasez4Specifies the database to use. Default is "default".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                s1   | j  d t j  |  _ t t |   j | |   S)Nstdin)getsysr,   r   r   execute)r   r   options)r   r   r   r/   =   s    zCommand.executec             O   s  | |  j  j } | d } d  } i  } i  } | d sy | sX t d |  j  j   n  |  j j | d   } x` |  j  j D]R } | | r |  j  j j |  }	 |	 j | | d   | | <qz t d |   qz WWqt j	 k
 r}
 z t d j
 |
 j    WYd  d  }
 ~
 XqXnst   } yt |  j d  rT|  j j   rTt d   n  |  j j } x | d  k rat |  } | r| d | 7} n  |  j j } t d | | rd	 | j j j | j f n d
 f  } |  j |  j | |  } | sqcn  |  j j rcy  |  j  j j |  j |  Wn |  j  j k
 r@Yq^X|  j j d |  d  } qcqcWx |  j  j D] } |  j  j j |  }	 | | | | <x | | d  k r@t d t |	 j  |	 j rd	 |	 j j j j |	 j j f n d
 f  } |  j |	 |  } | | | <| | | <|	 j r|	 j j |  | | <qqWqoWx | d  k r5t  j    } t  j  t d   } | | k r|  j j d  d  } qHn  | j!   d
 k r|  j j d  d  } qHn  y t" | |  j  |    WqHt j	 k
 r1} z' |  j j d j
 | j   d  } WYd  d  } ~ XqHXqHWWnP t# k
 rh|  j j d  t$ j% d  Yn" t k
 r|  j& j d  Yn X| r| | |  j  j <| | d <|  j  j j |  j' |   | d d k r|  j& j d  qn  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.   zSuperuser 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,   r1   r   Zverbose_namer   Zremote_fieldr
   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   r0   usernamer&   r5   Z	user_dataZfake_user_datar=   r*   eZdefault_usernameZverbose_field_nameZ	input_msgZusername_relmessageZinput_valueZ	password2errr   r   r   handleA   s    


.	"/ 8

	!!	
zCommand.handleNc             C   s   t  |  } | r' | d k r' | } n  y | j | d  } WnN t j k
 r } z+ |  j j d d j | j   d } WYd d } ~ Xn X| S)zm
        Override this method if you want to customize data inputs or
        validation exceptions.
        r2   Nz	Error: %sz; )r   r7   r   r8   r@   rA   r9   r:   )r   r*   rI   r    Z	raw_valuevalrH   r   r   r   r>      s    	 zCommand.get_input_data)
r   r   r   r!   Zrequires_migrations_checksr   r+   r/   rK   r>   r   r   )r   r   r      s   zr   )__doc__
__future__r   rB   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.encodingr
   Zdjango.utils.six.movesr   Zdjango.utils.textr   	Exceptionr   r   r   r   r   r   <module>   s   