ó
ø¢TQc           @   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 m Z d d
 l m Z d d l m Z d e f d „  ƒ  YZ d S(   s*   
Management utility to create superusers.
iÿÿÿÿN(   t   make_option(   t   get_user_model(   t   get_default_username(   t
   exceptions(   t   BaseCommandt   CommandError(   t   DEFAULT_DB_ALIAS(   t	   force_strt
   force_text(   t   input(   t   capfirstt   Commandc           B   s)   e  Z d  „  Z e j Z d Z d „  Z RS(   c         O   sè   t  t |  ƒ j | | Ž  t ƒ  |  _ |  j j j |  j j ƒ |  _ t	 j
 t d |  j j d |  j j d d  d d ƒt d d d d d	 d t d d
 |  j j ƒt d d d d d d t d d ƒf t d „  |  j j Dƒ ƒ |  _
 d  S(   Ns   --%st   destt   defaultt   helps&   Specifies the login for the superuser.s	   --noinputt   actiont   store_falset   interactivesó   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.s
   --databaset   storet   databases4   Specifies the database to use. Default is "default".c      
   s   s5   |  ]+ } t  d  | d | d d d d | ƒVq d S(   s   --%sR   R   R   s#   Specifies the %s for the superuser.N(   R    t   None(   t   .0t   field(    (    sP   ../Django//lib/python/django/contrib/auth/management/commands/createsuperuser.pys	   <genexpr>(   s   (   t   superR   t   __init__R   t	   UserModelt   _metat	   get_fieldt   USERNAME_FIELDt   username_fieldR   t   option_listR    R   t   TrueR   t   tuplet   REQUIRED_FIELDS(   t   selft   argst   kwargs(    (    sP   ../Django//lib/python/django/contrib/auth/management/commands/createsuperuser.pyR      s    „s   Used to create a superuser.c         O   si  | j  |  j j d  ƒ } | j  d ƒ } t | j  d d ƒ ƒ } | j  d ƒ } d  } i  } | s4y  | s‚ t d |  j j ƒ ‚ n  |  j j | d  ƒ } xe |  j j D]W }	 | j  |	 ƒ rë |  j j	 j
 |	 ƒ }
 |
 j | |	 d  ƒ | |	 <q¤ t d |	 ƒ ‚ q¤ WWqt j k
 r0} t d j | j ƒ ƒ ‚ qXnÜt ƒ  } y¢t |  j j ƒ } x| d  k rr| s¥t | ƒ } | rŒd | | f } n  t t d | ƒ ƒ } n  | rÀ| d	 k rÀ| } n  y |  j j | d  ƒ } Wn? t j k
 r} |  j j d
 d j | j ƒ ƒ d  } qUn Xy  |  j j j | ƒ j | ƒ Wn |  j j k
 rTqUX|  j j d | ƒ d  } qUWxÕ |  j j D]Ç }	 |  j j	 j
 |	 ƒ }
 | j  |	 ƒ | |	 <x– | |	 d  k rFt t d t t |
 j ƒ ƒ ƒ ƒ } y |
 j | d  ƒ | |	 <Wq±t j k
 rB} |  j j d
 d j | j ƒ ƒ d  | |	 <q±Xq±Wq€Wx | d  k rÝ| s¬t j ƒ  } t j t d ƒ ƒ } | | k r¬|  j j d ƒ d  } qNq¬n  | j ƒ  d	 k rN|  j j d ƒ d  } qNqNqNWWn. t k
 r|  j j d ƒ t j d ƒ n X| | |  j j <| | d <|  j j j | ƒ j  |   | d k re|  j! j d ƒ n  d  S(   NR   t	   verbosityi   R   s!   You must use --%s with --noinput.s   ; s   %s (leave blank to use '%s')s   %s: t    s	   Error: %ss    Error: That %s is already taken.s   Password (again): s#   Error: Your passwords didn't match.s&   Error: Blank passwords aren't allowed.s   
Operation cancelled.t   passwords   Superuser created successfully.("   t   getR   R   R   t   intR   R   t   cleanR!   R   R   R   t   ValidationErrort   joint   messagesR   R   t   verbose_nameR
   R	   R   t   stderrt   writet   _default_managert
   db_managert   get_by_natural_keyt   DoesNotExistt   getpasst   stript   KeyboardInterruptt   syst   exitt   create_superusert   stdout(   R"   R#   t   optionst   usernameR   R%   R   R'   t	   user_datat
   field_nameR   t   et   default_usernamet   verbose_field_namet	   input_msgt	   raw_valuet	   password2(    (    sP   ../Django//lib/python/django/contrib/auth/management/commands/createsuperuser.pyt   handle0   s”    		  
% 	
(   t   __name__t
   __module__R   R   R   R   RF   (    (    (    sP   ../Django//lib/python/django/contrib/auth/management/commands/createsuperuser.pyR      s   		(   t   __doc__R5   R8   t   optparseR    t   django.contrib.authR   t   django.contrib.auth.managementR   t   django.coreR   t   django.core.management.baseR   R   t	   django.dbR   t   django.utils.encodingR   R   t   django.utils.six.movesR	   t   django.utils.textR
   R   (    (    (    sP   ../Django//lib/python/django/contrib/auth/management/commands/createsuperuser.pyt   <module>   s   