o
    z,h,                     @   s^   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	m
Z
 dZdZG dd	 d	ZdS )
    N)import_module)ImproperlyConfigured)cached_property)import_stringmodule_has_submoduleappsmodelsc                   @   sp   e Zd ZdZdd Zdd Zedd Zedd	 Z	d
d Z
edd ZdddZdddZdd Zdd ZdS )	AppConfigz>Class representing a Django application and its configuration.c                 C   s   || _ || _d | _t| ds|dd | _| j s"td| j t| ds-| j | _	t| ds8| 
|| _d | _d | _d S )Nlabel.   z4The app label '%s' is not a valid Python identifier.verbose_namepath)namemoduler   hasattr
rpartitionr
   isidentifierr   titler   _path_from_moduler   models_moduler   )selfapp_name
app_module r   H/var/www/html/rh/venv/lib/python3.10/site-packages/django/apps/config.py__init__   s   




zAppConfig.__init__c                 C   s   d| j j| jf S )Nz<%s: %s>)	__class____name__r
   r   r   r   r   __repr__:   s   zAppConfig.__repr__c                 C   s   ddl m} |jS )Nr   )settings)django.confr!   DEFAULT_AUTO_FIELD)r   r!   r   r   r   default_auto_field=   s   zAppConfig.default_auto_fieldc                 C   s   | j jtjuS )N)r   r$   r	   r   r   r   r   !_is_default_auto_field_overriddenC   s   z+AppConfig._is_default_auto_field_overriddenc                 C   s   t t|dg }t|dkr&t|dd}|dur tj|g}nt t|}t|dkr4td||f |s<td| |d S )z;Attempt to determine app's filesystem path from its module.__path__   __file__NzThe app module %r has multiple filesystem locations (%r); you must configure this app with an AppConfig subclass with a 'path' class attribute.zThe app module %r has no filesystem location, you must configure this app with an AppConfig subclass with a 'path' class attribute.r   )listgetattrlenosr   dirnamesetr   )r   r   pathsfilenamer   r   r   r   G   s&   zAppConfig._path_from_modulec                    s  d}d}d}zt |}W n	 ty   Y n^w t|trkd|tf }t |} fddt|tjD }t|dkr@|d d }n+dd |D }t|dkr_dd |D }td	|d
	|f t|dkrk|d d }|du rs }|}|du rzt
|}W n	 ty   Y nw |du r|du r|d\}}	}
|r|
d  rt |} fddt|tjD }d||
f }|r|dd
	| 7 }t|t | t|tstd| |du rz|j}W n ty   td| w zt |}W n ty   td||j|jf w |||S )zU
        Factory that creates an app config from an entry in INSTALLED_APPS.
        N%s.%sc                    s6   g | ]\}}t | r| urt|d dr||fqS )defaultT)
issubclassr*   .0r   	candidateclsr   r   
<listcomp>~   s    
z$AppConfig.create.<locals>.<listcomp>r'   r   c                 S   s$   g | ]\}}t |d dr||fqS )r2   F)r*   r4   r   r   r   r9      s    
c                 S   s   g | ]\}}t |qS r   )repr)r5   r   _r   r   r   r9      s    z0%r declares more than one default AppConfig: %s.z, r   c                    s*   g | ]\}}t | r| urt|qS r   )r3   r:   r4   r7   r   r   r9      s    z*Module '%s' does not contain a '%s' class.z Choices are: %s.z#'%s' isn't a subclass of AppConfig.z"'%s' must supply a name attribute.z7Cannot import '%s'. Check that '%s.%s.name' is correct.)r   	Exceptionr   APPS_MODULE_NAMEinspect
getmembersisclassr+   RuntimeErrorjoinr   r   isupperImportErrorr3   r	   r   r   AttributeError
__module____qualname__)r8   entryapp_config_classr   r   mod_pathmodapp_configs
candidatesr;   cls_namemsgr   r7   r   createc   s   
	
	



zAppConfig.createTc                 C   sL   |r| j   n| j   z| j|  W S  ty%   td| j|f w )z
        Return the model with the given case-insensitive model_name.

        Raise LookupError if no model exists with this name.
        z#App '%s' doesn't have a '%s' model.)r   check_models_readycheck_apps_readyr   lowerKeyErrorLookupErrorr
   )r   
model_namerequire_readyr   r   r   	get_model   s   
zAppConfig.get_modelFc                 c   sB    | j   | j D ]}|jjr|sq|jjr|sq|V  qdS )a  
        Return an iterable of models.

        By default, the following models aren't included:

        - auto-created models for many-to-many relations without
          an explicit intermediate table,
        - models that have been swapped out.

        Set the corresponding keyword argument to True to include such models.
        Keyword arguments aren't documented; they're a private API.
        N)r   rQ   r   values_metaauto_createdswapped)r   include_auto_createdinclude_swappedmodelr   r   r   
get_models   s   
zAppConfig.get_modelsc                 C   s<   | j j| j | _t| jtrd| jtf }t|| _	d S d S )Nr1   )
r   
all_modelsr
   r   r   r   MODELS_MODULE_NAMEr   r   r   )r   models_module_namer   r   r   import_models  s
   zAppConfig.import_modelsc                 C   s   dS )zT
        Override this method in subclasses to run code when Django starts.
        Nr   r   r   r   r   ready  s    zAppConfig.readyN)T)FF)r   rF   rG   __doc__r   r    r   r$   propertyr%   r   classmethodrP   rX   r`   rd   re   r   r   r   r   r	      s    *



|
	r	   )r>   r,   	importlibr   django.core.exceptionsr   django.utils.functionalr   django.utils.module_loadingr   r   r=   rb   r	   r   r   r   r   <module>   s    