3
W­E^"  ã               @   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,|jdƒd | _t| dƒsB| jjƒ | _t| dƒsX| j|ƒ| _	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   ú4/tmp/pip-build-78s3knkw/Django/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rLt|ddƒ}|dk	r@tjj|ƒg}nt t|ƒƒ}t|ƒdkrjtd||f ƒ‚n|s|td|f ƒ‚|d S )z;Attempt to determine app's filesystem path from its module.Ú__path__é   Ú__file__Nz�The app module %r has multiple filesystem locations (%r); you must configure this app with an AppConfig subclass with a 'path' class attribute.zƒThe 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   sl  yt |ƒ}W n. tk
r:   d}|jdƒ\}}}|s6‚ Y n8X y
|j}W n tk
r`   | ||ƒS X |jdƒ\}}}t |ƒ}yt||ƒ} W n\ tk
rä   |dkrÞtdd„ |jjƒ D ƒƒ}|rÔt	d||dj
|ƒf ƒ‚t |ƒ n‚ Y nX t| tƒ� sþt	d| ƒ‚y
| j}W n" tk
�r*   t	d| ƒ‚Y nX yt |ƒ}	W n( tk
�r`   t	d	|||f ƒ‚Y nX | ||	ƒS )
zU
        Factory that creates an app config from an entry in INSTALLED_APPS.
        Nr   c             s   s6   | ].\}}t |tƒrt|tƒr|tk	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   Zdefault_app_configÚAttributeErrorr!   ÚsortedÚ__dict__Úitemsr   Újoinr*   r   r   )
ÚclsÚentryr   Zmod_pathÚ_Zcls_nameÚmodÚ
candidatesr   r   r   r   r   ÚcreateQ   sP    



zAppConfig.createTc             C   sT   |r| j jƒ  n
| j jƒ  y| j|jƒ  S  tk
rN   td| j|f ƒ‚Y nX dS )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.N)r   Úcheck_models_readyZcheck_apps_readyr   ÚlowerÚKeyErrorÚLookupErrorr   )r   Z
model_nameZrequire_readyr   r   r   Ú	get_model§   s    
zAppConfig.get_modelFc             c   sH   | j jƒ  x8| jjƒ D ]*}|jjr*| r*q|jjr:| r:q|V  qW 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   ÚvaluesZ_metaZauto_createdZswapped)r   Zinclude_auto_createdZinclude_swappedÚmodelr   r   r   Ú
get_models·   s    
zAppConfig.get_modelsc             C   s8   | j j| j | _t| jtƒr4d| jtf }t|ƒ| _	d S )Nz%s.%s)
r   Z
all_modelsr   r   r   r   ÚMODELS_MODULE_NAMEr   r   r   )r   Z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:   r?   rB   rD   rE   r   r   r   r   r   
   s   &V

	r   )	r#   Ú	importlibr   Zdjango.core.exceptionsr   Zdjango.utils.module_loadingr   rC   r   r   r   r   r   Ú<module>   s
   