
    Gwgr                         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 Zd	 Zd
deefdZd ZdefdZy)zC
Creates permissions for all installed apps that need permissions.
    N)apps)get_permission_codename)create_contenttypes)
exceptions)DEFAULT_DB_ALIASrouterc                 4    g t        |       | j                  S )zH
    Return (codename, name) for all permissions in the given opts.
    )_get_builtin_permissionspermissions)optss    ^/var/www/horilla/myenv/lib/python3.12/site-packages/django/contrib/auth/management/__init__.py_get_all_permissionsr      s!     @%d+?d.>.>??    c                     g }| j                   D ]/  }|j                  t        ||       d|d| j                  f       1 |S )z
    Return (codename, name) for all autogenerated permissions.
    By default, this is ('add', 'change', 'delete', 'view')
    zCan  )default_permissionsappendr   verbose_name_raw)r   permsactions      r   r
   r
      sN    
 E** 
'5%t'<'<=	

 Lr      Tc                    | j                   sy t        | f||||d| | j                  }	 |j                  |      } |j	                  dd      }|j	                  dd      }t        j                  ||      sy g }	t               }
| j                         D ]l  }|j                  j                  |      j                  |d      }|
j                  |       t        |j                        D ]  }|	j!                  ||f        n t        |j                  j#                  |      j%                  |
      j'                  d	d
            }g }|	D ]W  \  }\  }}|j(                  |f|vs |       }||j*                  _        ||_        ||_        ||_        |j!                  |       Y |j                  j#                  |      j5                  |       |dk\  r|D ]  }t7        d|z          y y # t
        $ r Y y w xY w)N)	verbosityinteractiveusingr   contenttypesContentTypeauth
PermissionF)for_concrete_model)content_type__incontent_typecodenamer   zAdding permission '%s')models_moduler   labelget_app_config	get_modelLookupErrorr   allow_migrate_modelset
get_modelsobjects
db_managerget_for_modeladdr   _metar   r   filtervalues_listpk_statedbr#   namer"   bulk_createprint)
app_configr   r   r   r   kwargs	app_labelr   r   searched_permsctypesklassctypeperm	all_permsr   ctr#   r6   
permissions                       r   create_permissionsrD   %   s#    ##
     I((3
nn^]C^^FL9
 %%eZ8 NUF&&( 	1 ##..u5CCe D 
 	

5(5 	1D!!5$-0	1	1   '	# 
 

 
^Z	0I E . %XtEE8I-#J#(J "*J"JO&(J#LL$% U#//6A~ 	3D*T12	3 Y  s   5G+ +	G76G7c                  Z    	 t        j                         } | S # t        t        f$ r Y yw xY w)zt
    Return the current system user's username, or an empty string if the
    username could not be determined.
     )getpassgetuserImportErrorKeyError)results    r   get_system_usernamerL   r   s5    
" M "  	s    **c                    ddl m} |j                  j                  j                  ryt               }	 t        j                  d|      j                  dd      j                  d      j                  dd      j                         }	 |j                  j                  j                  d      j                  |       | r9|r7	 |j                  j"                  j%                  |      j'                  |	       y|S # t        $ r Y yw xY w# t        j                   $ r Y yw xY w# |j                  j(                  $ r Y |S w xY w)
a  
    Try to determine the current system user's username to use as a default.

    :param check_db: If ``True``, requires that the username does not match an
        existing ``auth.User`` (otherwise returns an empty string).
    :param database: The database where the unique check will be performed.
    :returns: The username, or an empty string if no username can be
        determined or the suggested username is already taken.
    r   )modelsrF   NFKDasciiignorer   username)rR   )django.contrib.authrN   Userr0   swappedrL   unicodedata	normalizeencodedecodereplacelowerUnicodeDecodeError	get_fieldrun_validatorsr   ValidationError_default_managerr-   getDoesNotExist)check_dbdatabaseauth_appdefault_usernames       r   get_default_usernamerg      s*    7 }}""*,	!!&*:;VGX&VG_WS"UW 	%%j1@@AQR
 $	MM**55h?CC) D  '   %%  }})) 	 		s6   AC8 4D  5D  8	DDDD D=<D=)__doc__rG   rV   django.appsr   global_appsrS   r   &django.contrib.contenttypes.managementr   django.corer   	django.dbr   r   r   r
   rD   rL   rg    r   r   <module>ro      sS      + 7 F " .@$ 
	J3Z #'1A .r   