a
    [f,                     @   s`   d dl Z d dlmZ d dlmZmZmZ d dlmZ dZ	dddZ
d	d
 ZG dd dejZdS )    N)color_style)IntegrityError
migrationstransaction)Qz
    A problem arose migrating proxy model permissions for {old} to {new}.

      Permission(s) for {new} already existed.
      Codenames Q: {query}

    Ensure to audit ALL permissions for {old} and {new}.
Fc                    sj  t  }| dd}| dd}|jj}|  D ]4}|j  jsBq. fdd jD }t|d}	 j	D ]\}
}|	t|
|dO }	qf|j
|}|j|d	d
}|j|dd
}|r|n|}|r|n|}zPtj|d. |j
|j|	|dj|d W d   n1 s0    Y  W q. tyb   d|j|j}d|j|j}tj|tj|||	d Y q.0 q.dS )zk
    Update the content_type of proxy model permissions to use the ContentType
    of the proxy model.
    auth
PermissioncontenttypesContentTypec                    s   g | ]}d | j f qS )z%s_%s)Z
model_name).0actionopts C:\Users\91910\OneDrive\Desktop\vts_admin_rebuild-master\vts\Lib\site-packages\django/contrib/auth/migrations/0011_update_proxy_permissions.py
<listcomp>   s   z2update_proxy_model_permissions.<locals>.<listcomp>)Zcodename__in)codenamenameT)Zfor_concrete_modelF)using)content_typeNz{}_{})oldnewquery)r   Z	get_model
connectionaliasZ
get_models_metaproxyZdefault_permissionsr   ZpermissionsobjectsZ
db_managerZget_for_modelr   Zatomicr   filterupdater   formatZ	app_labelmodelsysstdoutwriteWARNING)appsschema_editorreversestyler   r
   r   ZModelZ#proxy_default_permissions_codenamesZpermissions_queryr   r   Zcontent_type_managerZconcrete_content_typeZproxy_content_typeZold_content_typeZnew_content_typer   r   r   r   r   update_proxy_model_permissions   sJ    

*r*   c                 C   s   t | |dd dS )zn
    Update the content_type of proxy model permissions to use the ContentType
    of the concrete model.
    T)r(   N)r*   )r&   r'   r   r   r   revert_proxy_model_permissions;   s    r+   c                   @   s"   e Zd ZddgZeeegZdS )	Migration)r   Z 0010_alter_group_name_max_length)r	   Z0002_remove_content_type_nameN)	__name__
__module____qualname__dependenciesr   Z	RunPythonr*   r+   
operationsr   r   r   r   r,   C   s   r,   )F)r"   Zdjango.core.management.colorr   Z	django.dbr   r   r   Zdjango.db.modelsr   r%   r*   r+   r,   r   r   r   r   <module>   s   

*