o
    l~iD                     @   s   d dl mZ d dlmZ d dlmZ d dlmZ i Zdd Z	dd Z
d	d
 ZdddZdd ZdddZdd Zdd Zdd ZdS )    )apps)settings)ImproperlyConfigured)swappable_dependencyc                 C   sB   t | | }dj| | d}tt|stt|t| | |S )zReturns the setting name to use for the given model

    Returns the setting name to use for the given model (i.e.
    AUTH_USER_MODEL)
    z{prefix}_{model}_MODEL)prefixmodel)	_prefixesgetformatupperhasattrr   setattrjoin)	app_labelr   r   setting r   W/var/www/newdalilibackend/backend/venv/lib/python3.10/site-packages/swapper/__init__.pyswappable_setting	   s   
r   c                 C   s0   t | |}t| |}tt||}||kr|S dS )zReturns the value of the swapped setting.

    Returns the value of the swapped setting, or False if the model hasn't
    been swapped.
    F)r   r   getattrr   )r   r   default_modelr   valuer   r   r   
is_swapped   s   

r   c                 C   s   t | |p	t| |S )zReturns [app_label.model].

    Returns [app_label.model] unless the model has been swapped, in which
    case returns the swappable setting value.
    )r   r   r   r   r   r   r   get_model_name*   s   r   Nc                 C   s"   t t| |}|s|S |d |fS )zReturns a Django 1.7+ style dependency tuple

    Returns a Django 1.7+ style dependency tuple for inclusion in
    migration.dependencies[]
    r   )r   r   )r   r   versiondependenciesr   r   r   
dependency3   s   r   c                    s   t  fdd|D S )z>Map model names to their swapped equivalents for the given appc                 3   s    | ]
}|t  |fV  qd S N)r   ).0r   r   r   r   	<genexpr>A   s    z"get_model_names.<locals>.<genexpr>)dict)r   modelsr   r   r   get_model_names?   s   r#   Tc                 C   sl   t | |}|rt|\} }z
tj| ||d}W n ty"   d}Y nw |du r4|r4tdjt| |d|S )zDLoad the specified model class, or the class it was swapped out for.)require_readyNzCould not find {name}!)name)r   splitr   	get_modelLookupErrorr   r
   r   )r   r   requiredr$   swappedclsr   r   r   
load_modelD   s   
r,   c                 C   s   |t | < dS )z6Set a custom prefix to use for the given app (e.g. WQ)N)r   )r   r   r   r   r   set_app_prefixV   s   r-   c                 C   s   dj | |dS )Nz{app_label}.{model}r   )r
   r   r   r   r   r   [   s   r   c                 C   s   |  d\}}} || fS )N.)
rpartition)r   r   _r   r   r   r&   b   s   r&   r   )TT)django.appsr   django.confr   django.core.exceptionsr   django.db.migrationsr   r   r   r   r   r   r#   r,   r-   r   r&   r   r   r   r   <module>   s    
	
