ó
i4Vdc           @  s~   d  d l  m Z d  d l Z d  d l Z d  d l m Z d  d l m Z m Z d  d l	 m
 Z
 m Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   OrderedDict(   t   BaseCommandt   CommandError(   t   DEFAULT_DB_ALIASt   connectionst   Commandc           B  sP   e  Z d  Z e Z d Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(   uX   Introspects the database tables in the given database and outputs a Django model module.u	   django.dbc      
   C  s)   | j  d d d d d d t d d ƒd  S(	   Nu
   --databaset   actionu   storet   destu   databaset   defaultt   helpuM   Nominates a database to introspect. Defaults to using the "default" database.(   t   add_argumentR   (   t   selft   parser(    (    sw   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/inspectdb.pyt   add_arguments   s    c         K  sV   y2 x+ |  j  | ƒ D] } |  j j d | ƒ q WWn t k
 rQ t d ƒ ‚ n Xd  S(   Nu   %s
uP   Database inspection isn't supported for the currently selected database backend.(   t   handle_inspectiont   stdoutt   writet   NotImplementedErrorR   (   R   t   optionst   line(    (    sw   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/inspectdb.pyt   handle   s
    c      
   #  s‘  t  | d } | j d ƒ } d „  } d „  ‰  | j ƒ  P} d Vd Vd Vd Vd	 Vd
 Vd Vd Vd Vd |  j Vg  } x| j j | ƒ D]ó} | d  k	 rÃ t | ƒ rÃ | | ƒ sÃ q qÃ n  d Vd Vd | | ƒ V| j | | ƒ ƒ y | j j	 | | ƒ } Wn t
 k
 r!i  } n Xy | j j | | ƒ }	 Wn t
 k
 rTi  }	 n Xy | j j | | ƒ }
 Wn t
 k
 r‡i  }
 n Xg  } i  } xÇ| j j | | ƒ D]°} g  } t ƒ  } | d } | | k } |  j | | | ƒ \ } } } | j | ƒ | j | ƒ | j | ƒ | | | <| |	 k ri|	 | d rKt | d <qi|	 | d rit | d <qin  | rÃ| | d | k r‰d n | | | d ƒ } | | k r¶d | } qd | } nB |  j | | | ƒ \ } } } | j | ƒ | j | ƒ | d 7} | d k rb| i t d 6k rb| d k r6qªqb| d k rb| j j rb| j d ƒ qbn  | d r˜| d k rd } q˜t | d <t | d  <n  d! | d" | k r°d n d# | f } | j d$ ƒ rÙ| d% 7} n  | r'| j d ƒ sû| d& 7} n  | d& j ‡  f d' †  | j ƒ  Dƒ ƒ 7} n  | d( 7} | rQ| d) d* j | ƒ 7} n  d+ | VqªWx" |  j | |
 | ƒ D] } | VqtWq WWd  QXd  S(,   Nu   databaseu   table_name_filterc         S  s   t  j d d |  j ƒ  ƒ S(   Nu   [^a-zA-Z0-9]u    (   t   ret   subt   title(   t
   table_name(    (    sw   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/inspectdb.pyt   <lambda>#   t    c         S  s   |  j  d ƒ r |  d S|  S(   Nu   u'i   (   t
   startswith(   t   s(    (    sw   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/inspectdb.pyR   $   R   u0   # This is an auto-generated Django model module.u<   # You'll have to do the following manually to clean this up:u   #   * Rearrange models' orderu>   #   * Make sure each model has one field with primary_key=TrueuL   #   * Make sure each ForeignKey has `on_delete` set to the desired behavior.uh   #   * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the tableuR   # Feel free to rename the models, but don't rename db_table values or field names.u'   from __future__ import unicode_literalsu    u   from %s import modelsu   class %s(models.Model):i    u   primary_keyu   uniquei   u   selfu   ForeignKey(%su   ForeignKey('%s'u   (u   idu
   AutoField(u   IntegerField(u
   AutoField?i   u   BooleanField(u   NullBooleanField(u   blanku   nullu	   %s = %s%su   .u   models.u   ForeignKey(u   , models.DO_NOTHINGu   , c         3  s1   |  ]' \ } } d  | ˆ  t  | ƒ ƒ f Vq d S(   u   %s=%sN(   t   repr(   t   .0t   kt   v(   t   strip_prefix(    sw   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/inspectdb.pys	   <genexpr>   s   u   )u     # u    u       %s(   R   t   gett   cursort	   db_modulet   introspectiont   table_namest   Nonet   callablet   appendt   get_relationsR   t   get_indexest   get_constraintst   get_table_descriptionR   t   normalize_col_namet   updatet   extendt   Truet   get_field_typet   featurest   can_introspect_autofieldR   t   endswitht   joint   itemst   get_meta(   R   R   t
   connectiont   table_name_filtert   table2modelR$   t   known_modelsR   t	   relationst   indexest   constraintst   used_column_namest   column_to_field_namet   rowt   comment_notest   extra_paramst   column_namet   is_relationt   att_namet   paramst   notest   rel_tot
   field_typet   field_paramst   field_notest
   field_desct	   meta_line(    (   R"   sw   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/inspectdb.pyR      s¸    			


	



	

	
c   	      C  s5  i  } g  } | j  ƒ  } | | k r4 | j d ƒ n  | rc | j d ƒ rV | d  } qc | | d <n  t j d d | ƒ \ } } | d k rš | j d ƒ n  | j d	 ƒ d k rx+ | j d	 ƒ d k rÜ | j d	 d ƒ } q² W| j  ƒ  j d	 ƒ d k r| j d
 ƒ qn  | j d ƒ r4d | } | j d ƒ n  | j d ƒ r]d | } | j d ƒ n  t j	 | ƒ r†| d 7} | j d ƒ n  | d j
 ƒ  r°d | } | j d ƒ n  | | k r	d } x$ d | | f | k rè| d 7} qÅWd | | f } | j d ƒ n  | | k r(| r(| | d <n  | | | f S(   uU   
        Modify the column name to make it Python-compatible as a field name
        u   Field name made lowercase.u   _idiýÿÿÿu	   db_columnu   \Wu   _i    u.   Field renamed to remove unsuitable characters.u   __u>   Field renamed because it contained more than one '_' in a row.u   field%su*   Field renamed because it started with '_'.u   %sfieldu(   Field renamed because it ended with '_'.u   _fieldu4   Field renamed because it was a Python reserved word.u	   number_%su:   Field renamed because it wasn't a valid Python identifier.u   %s_%di   u'   Field renamed because of name conflict.(   t   lowerR*   R6   R   t   subnt   findt   replaceR   t   keywordt	   iskeywordt   isdigit(	   R   t   col_nameRA   RG   RM   RN   t   new_namet   num_replt   num(    (    sw   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/inspectdb.pyR/   ™   sL    



c         C  s^  t  ƒ  } g  } y | j j | d | ƒ } Wn$ t k
 rR d } | j d ƒ n Xt | ƒ t k r | \ } } | j | ƒ n  | d k r® | d r® t | d ƒ | d <n  | d k rQ| d d k sÚ | d	 d k r2| j d
 ƒ | d d k	 r| d n d | d <| d	 d k	 r%| d	 n d	 | d <qQ| d | d <| d	 | d <n  | | | f S(   uê   
        Given the database connection, the table name, and the cursor row
        description, this routine will return the given field type name, as
        well as any additional keyword parameters and notes for the field.
        i   u	   TextFieldu   This field type is a guess.u	   CharFieldi   u
   max_lengthu   DecimalFieldi   i   ua   max_digits and decimal_places have been guessed, as this database handles decimal fields as floati
   u
   max_digitsu   decimal_placesN(
   R   R&   R3   t   KeyErrorR*   t   typet   tupleR0   t   intR(   (   R   R:   R   RC   RM   RN   RL   t
   new_params(    (    sw   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/inspectdb.pyR3   Ñ   s*    	 $'c   
        sÎ   g  } xz | j  ƒ  D]l \ } } | d r | d } t | ƒ d k r d d j ‡  f d †  | Dƒ ƒ d } | j | ƒ q q q Wd d	 d
 d | g }	 | rÊ d d j | ƒ d } |	 d | g 7}	 n  |	 S(   uº   
        Return a sequence comprising the lines of code necessary
        to construct the inner Meta class for the model corresponding
        to the given database table name.
        u   uniqueu   columnsi   u   (u   , c         3  s   |  ] } d  ˆ  | Vq d S(   u   '%s'N(    (   R   t   c(   RB   (    sw   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/inspectdb.pys	   <genexpr>  s    u   )u    u       class Meta:u           managed = Falseu           db_table = '%s'u   ,)u           unique_together = %s(   R8   t   lenR7   R*   (
   R   R   R@   RB   t   unique_togethert   indexRI   t   columnst   tupt   meta(    (   RB   sw   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/inspectdb.pyR9   ÷   s    

'(   t   __name__t
   __module__R
   t   Falset   requires_system_checksR%   R   R   R   R/   R3   R9   (    (    (    sw   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/inspectdb.pyR      s   			{	8	&(   t
   __future__R    RU   R   t   collectionsR   t   django.core.management.baseR   R   t	   django.dbR   R   R   (    (    (    sw   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/core/management/commands/inspectdb.pyt   <module>   s   