
u^"                 @   sY   d  d l  Z  d  d l m Z d  d l m Z d  d l m Z d Z Gd d   d  Z d S)    N)import_module)ImproperlyConfigured)module_has_submodulemodelsc               @   s   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 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@ | j d  d |  _ t |  d  sa |  j j   |  _ t |  d  s |  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-8lau8j11/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 rr t | d d  } | d k	 r` t j j |  g } n t  t |   } t |  d k r t d | | f   n | 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   s  y t  |  } Wn9 t k
 rK d } | j d  \ } } } | sG   YnH Xy | j } Wn t k
 rz |  | |  SYn X| j d  \ } } } t  |  } y t | |  }  Wnx t k
 r,| d k r%t d d   | j j   D  } | rt	 d | | d j
 |  f   t  |  n   Yn Xt |  t  sLt	 d |   y |  j } Wn" t k
 r}t	 d |   Yn Xy t  |  }	 Wn+ t k
 rt	 d	 | | | f   Yn X|  | |	  S)
zU
        Factory that creates an app config from an entry in INSTALLED_APPS.
        Nr   c             s   sK   |  ]A \ } } 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   sj   | r |  j  j   n |  j  j   y |  j | j   SWn+ t k
 re t d |  j | f   Yn Xd 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   s\   |  j  j   xH |  j j   D]7 } | j j r9 | r9 q | j j rO | rO q | Vq Wd 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   sN   |  j  j |  j |  _ t |  j t  rJ d |  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)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
   