
TRNc           @   s   d  Z  d d l m Z m Z d d l m Z d   Z d   Z d   Z	 d   Z
 e j j e	 d d	 e j j e
 d
 e d d d S(   sC   
Creates permissions for all installed apps that need permissions.
i(   t
   get_modelst   signals(   t   modelsc         C   s   d |  | j  j   f S(   Nu   %s_%s(   t   object_namet   lower(   t   actiont   opts(    (    sT   /home/panlixing/Python_Projects/gaeseries/django/contrib/auth/management/__init__.pyt   _get_permission_codename   s    c         C   sQ   g  } x7 d D]/ } | j  t | |   d | |  j f f  q W| t |  j  S(   s?   Returns (codename, name) for all permissions in the given opts.t   addt   changet   deleteu	   Can %s %s(   s   addR	   s   delete(   t   appendR   t   verbose_name_rawt   listt   permissions(   R   t   permsR   (    (    sT   /home/panlixing/Python_Projects/gaeseries/django/contrib/auth/management/__init__.pyt   _get_all_permissions   s    -c         K   s   d d l  m } d d l m } t |   } | s6 d  Sx | D] } | j j |  } xs t | j  D]b \ }	 }
 | j j	 d |	 d | j
 d i |
 d 6| d 6 \ } } | re | d	 k re d
 | GHqe qe Wq= Wd  S(   Ni(   t   ContentType(   t
   Permissiont   codenamet   content_type__pkt   defaultst   namet   content_typei   s   Adding permission '%s'(   t"   django.contrib.contenttypes.modelsR   t   django.contrib.auth.modelsR   R    t   objectst   get_for_modelR   t   _metat   get_or_createt   id(   t   appt   created_modelst	   verbosityt   kwargsR   R   t
   app_modelst   klasst   ctypeR   R   t   pt   created(    (    sT   /home/panlixing/Python_Projects/gaeseries/django/contrib/auth/management/__init__.pyt   create_permissions   s    c         K   s   d d l  m } d d l m } | | k r | j d t  r d } t |  } xD | d
 k rq t d  } qS n  | d k r | d	 d t n  PqS n  d  S(   Ni(   t   User(   t   call_commandt   interactives   
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): t   yest   nos#   Please enter either "yes" or "no": t   createsuperuser(   s   yess   no(   R   R)   t   django.core.managementR*   t   gett   Truet	   raw_input(   R   R    R!   R"   R)   R*   t   msgt   confirm(    (    sT   /home/panlixing/Python_Projects/gaeseries/django/contrib/auth/management/__init__.pyt   create_superuser    s    t   dispatch_uids1   django.contrib.auth.management.create_permissionst   senders/   django.contrib.auth.management.create_superuserN(   t   __doc__t   django.db.modelsR    R   t   django.contrib.authR   t   auth_appR   R   R(   R5   t   post_syncdbt   connect(    (    (    sT   /home/panlixing/Python_Projects/gaeseries/django/contrib/auth/management/__init__.pyt   <module>   s   				