
 X                 @   sr   d  d l  Z  d  d l m Z d  d l m Z m Z d  d l m Z d  d l m	 Z	 d Z
 Gd d   d e  Z d S)	    N)import_module)AppRegistryNotReadyImproperlyConfigured)upath)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   Z	 d d   Z
 d d d d  Z d d   Z d d   Z d S)	AppConfigzH
    Class representing a Django application and its configuration.
    c             C   s   | |  _  | |  _ t |  d  s: | j d  d |  _ n  t |  d  s^ |  j j   |  _ n  t |  d  s |  j |  |  _ n  d  |  _	 d  |  _
 d  S)Nlabel.   verbose_namepath)namemodulehasattr
rpartitionr	   titler   _path_from_moduler   models_moduler   )selfapp_name
app_module r   @/home/ubuntu/projects/ifolica/build/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 ru t | d d  } | d k	 r` t j j |  g } qu t  t |   } n  t |  d k r t d | | f   n | s t d | f   n  t | 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   r   pathsfilenamer   r   r   r   6   s    zAppConfig._path_from_modulec       	   #   C   sS  y t  |  } Wn< t k
 rN d } | j d  \ } } } | sJ   n  YnH Xy | j } Wn t k
 r} |  | |  SYn X| j d  \ } } } t  |  } y t | |  }  Wn. t k
 r | d k r t  |  n   Yn Xt |  t  st d |   n  y |  j	 } Wn" t k
 r9t d |   Yn Xt  |  } |  | |  S)zU
        Factory that creates an app config from an entry in INSTALLED_APPS.
        Nr
   z#'%s' isn't a subclass of AppConfig.z"'%s' must supply a name attribute.)
r   ImportErrorr   Zdefault_app_configAttributeErrorr"   
issubclassr   r   r   )	clsentryr   Zmod_path_Zcls_namemodr   r   r   r   r   createQ   s:    zAppConfig.createc             C   s)   |  j  d k r% t d |  j   n  d S)zJ
        Raises an exception if models haven't been imported yet.
        Nz.Models for app '%s' haven't been imported yet.)r   r   r	   )r   r   r   r   check_models_ready   s    zAppConfig.check_models_readyc             C   sQ   |  j    y |  j | j   SWn+ t k
 rL t d |  j | f   Yn Xd S)z
        Returns the model with the given case-insensitive model_name.

        Raises LookupError if no model exists with this name.
        z#App '%s' doesn't have a '%s' model.N)r1   r   lowerKeyErrorLookupErrorr	   )r   Z
model_namer   r   r   	get_model   s    
zAppConfig.get_modelFc             c   s_   |  j    xN |  j j   D]= } | j j r9 | r9 q n  | j j rR | rR q n  | Vq Wd S)a  
        Returns 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 created to satisfy deferred attribute queries,
        - 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)r1   r   valuesZ_metaZauto_createdZswapped)r   Zinclude_auto_createdZinclude_swappedmodelr   r   r   
get_models   s    
zAppConfig.get_modelsc             C   sD   | |  _  t |  j t  r@ d |  j t f } t |  |  _ n  d  S)Nz%s.%s)r   r   r   MODELS_MODULE_NAMEr   r   r   )r   Z
all_modelsZ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   classmethodr0   r1   r5   r8   r:   r;   r   r   r   r   r      s   #Br   )r$   	importlibr   Zdjango.core.exceptionsr   r   Zdjango.utils._osr   Zdjango.utils.module_loadingr   r9   objectr   r   r   r   r   <module>   s   