o
    9Zc"                     @   sB   d dl Z d dlmZ d dlmZ d dlmZ dZG dd dZdS )    N)import_module)ImproperlyConfigured)module_has_submodulemodelsc                   @   sX   e Zd ZdZdd Z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   sh   || _ || _d | _t| ds|dd | _t| ds!| j | _t| ds,| || _	d | _
d | _d S )Nlabel.   verbose_namepath)namemoduleappshasattr
rpartitionr   titler
   _path_from_moduler   models_moduler   )selfapp_name
app_module r   H/var/www/chikooza/env/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__3   s   zAppConfig.__repr__c                 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|f |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   6   s&   zAppConfig._path_from_modulec           
   
   C   sX  zt |}W n ty   d}|d\}}}|s Y nw z|j}W n ty0   | || Y S w |d\}}}t |}zt||} W n- tyq   |du rntdd |j D }|rit	d||d
|f t | n Y nw t| ts}t	d| z| j}W n ty   t	d| w zt |}	W n ty   t	d	|||f w | ||	S )
zU
        Factory that creates an app config from an entry in INSTALLED_APPS.
        Nr   c                 s   s8    | ]\}}t |trt|tr|turt|V  qd S )N)
isinstancetype
issubclassr   repr).0r   	candidater   r   r   	<genexpr>}   s    
z#AppConfig.create.<locals>.<genexpr>z4'%s' does not contain a class '%s'. Choices are: %s.z, 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   ImportErrorr   default_app_configAttributeErrorr"   sorted__dict__itemsr   joinr+   r   r   )
clsentryr   mod_path_cls_namemod
candidatesr   r   r   r   r   createQ   sl   




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   r?   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 )Nz%s.%s)
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   
__module____qualname____doc__r   r   r   classmethodr>   rF   rN   rR   rS   r   r   r   r   r   
   s    &

U
	r   )	r$   	importlibr   django.core.exceptionsr   django.utils.module_loadingr   rP   r   r   r   r   r   <module>   s    