
    g                         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/python.vincentserveurtest.ovh/public_html/venv/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
      sI    
 E**'5%t'<'<=	
 + Lr      Tc                    | j                   sy 	 |j                  dd      }t        j                  ||      sy t        | f||||d| | j                  }	 |j                  |      } |j                  dd      }t        | j                               }	 |j                  j                  |      j                  |	ddi}
t        |j                  j                  |      j                  t        |
j!                                     j#                  d	d
            }g }|	D ]s  }|
|   }t%        |j&                        D ]T  \  }}|j(                  |f|vs |       }||j*                  _        ||_        ||_        ||_        |j5                  |       V u |j                  j                  |      j7                  |       |dk\  r|D ]  }t9        d|z          y y # t        $ r Y y w xY w# t        $ r Y y w xY w)Nauth
Permission)	verbosityinteractiveusingr   contenttypesContentTypefor_concrete_modelsF)content_type__incontent_typecodenamer   zAdding permission '%s')models_module	get_modelLookupErrorr   allow_migrate_modelr   labelget_app_configlist
get_modelsobjects
db_managerget_for_modelssetr   filtervaluesvalues_listr   _metapk_statedbr#   namer"   r   bulk_createprint)
app_configr   r   r   r   kwargsr   	app_labelr   modelsctypes	all_permsr   modelctyper#   r7   
permissionperms                      r   create_permissionsrD   &   s    ##^^FL9
 %%eZ8
     I((3
nn^]C *'')*F B[  ++E2AA	%*F   '	 1 
 

 
^Z	0I Eu25;;?NHd(#94'\
',
!!$&.
#"&
*/
'Z( @  U#//6A~D*T12  o  *  s#   G #G' 	G$#G$'	G32G3c                  d    	 t        j                         } | S # t        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OSError)results    r   get_system_usernamerM   o   s7    
" M 7+  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   )r=   rF   NFKDasciiignorer   username)rR   )django.contrib.authr=   Userr3   swappedrM   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   rM   rg    r   r   <module>ro      sS      + 7 F " .@$ 
	F3R" #'1A .r   