
    g4                         d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ ddlmZ  G d	 d
      Z G d de      Z G d de      Zy)    N)apps)OutputWrapper)NOT_PROVIDED)timezone)get_docs_version   )MigrationLoaderc                   H    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zy)MigrationQuestionerz
    Give the autodetector responses to questions it might have.
    This base class has a built-in noninteractive mode, but the
    interactive subclass is what the command-line arguments will use.
    Nc                 N    |xs i | _         |xs
 t               | _        || _        y N)defaultssetspecified_appsdry_run)selfr   r   r   s       w/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/db/migrations/questioner.py__init__zMigrationQuestioner.__init__   s#     B,5    c                    || j                   v ry	 t        j                  |      }t        j                  |j                        \  }}|| j                  j                  dd      S 	 t        j                  |      }t        |dd      r=t        j                  t        j                  j                  |j                               }nPt#        |d      rDt%        |j&                        dkD  ryt        j                  t)        |j&                        d         }t+        d	 D               S # t        $ r | j                  j                  dd      cY S w xY w# t,        $ r | j                  j                  dd      cY S w xY w)
z2Should we create an initial migration for the app?Task_initialFN__file____path__r   r   c              3   J   K   | ]  }|d k7  s	|j                  d        yw)z__init__.pyz.pyN)endswith).0xs     r   	<genexpr>z2MigrationQuestioner.ask_initial.<locals>.<genexpr>7   s!     Vi1CU1::e,is   
##)r   r   get_app_configLookupErrorr   getr	   migrations_modulelabel	importlibimport_modulegetattroslistdirpathdirnamer   hasattrlenr   listanyImportError)r   	app_label
app_configmigrations_import_path_r"   	filenamess          r   r   zMigrationQuestioner.ask_initial   sR    +++
	;,,Y7J %4$E$EjFVFV$W!!)==$$]E::	W ) 7 78N O (*d;JJrww7H7Q7Q'RS	*J7(112Q6 JJt,=,F,F'G'JK	ViVVVV#  	;==$$]E::	;  	;==$$]E::	;s#   D) 'E )%EE%E<;E<c                      y)#Adding a NOT NULL field to a model.N r   
field_name
model_names      r   ask_not_null_additionz)MigrationQuestioner.ask_not_null_addition9        r   c                      y)"Changing a NULL field to NOT NULL.Nr7   r8   s      r   ask_not_null_alterationz+MigrationQuestioner.ask_not_null_alteration>   r<   r   c                 :    | j                   j                  dd      S )Was this field really renamed?
ask_renameFr   r!   )r   r:   old_namenew_namefield_instances        r   rB   zMigrationQuestioner.ask_renameC   s    }}  u55r   c                 :    | j                   j                  dd      S )Was this model really renamed?ask_rename_modelFrC   )r   old_model_statenew_model_states      r   rI   z$MigrationQuestioner.ask_rename_modelG   s    }}  !3U;;r   c                 :    | j                   j                  dd      S )z)Should these migrations really be merged?	ask_mergeFrC   r   r0   s     r   rM   zMigrationQuestioner.ask_mergeK   s    }}  e44r   c                      y)(Adding an auto_now_add field to a model.Nr7   r8   s      r   ask_auto_now_add_additionz-MigrationQuestioner.ask_auto_now_add_additionO   r<   r   c                      y).Adding a unique field with a callable default.Nr7   r8   s      r   $ask_unique_callable_default_additionz8MigrationQuestioner.ask_unique_callable_default_additionT   r<   r   )NNN)__name__
__module____qualname____doc__r   r   r;   r?   rB   rI   rM   rQ   rT   r7   r   r   r   r      s5    
W<

6<5
r   r   c                   b     e Zd Z	 d fd	ZddZd ZddZd Zd Zd Z	d Z
d	 Zd
 Zd Z xZS )InteractiveMigrationQuestionerc                 n    t         |   |||       |xs t        t        j                        | _        y N)r   r   r   )superr   r   sysstdoutprompt_output)r   r   r   r   r`   	__class__s        r   r   z'InteractiveMigrationQuestioner.__init__[   s6     	ng 	 	
 +GmCJJ.Gr   c                 <   | j                   j                  | dd       t               }|s||S |r|d   j                         dvr@| j                   j                  dd       t               }|s*|d   j                         dvr@|d   j                         dk(  S )N  endingr   ynzPlease answer yes or no: y)r`   writeinputlower)r   questiondefaultresults       r   _boolean_inputz-InteractiveMigrationQuestioner._boolean_inputc   s      H:Q ;'-NF1IOO-T9$$%@$LWF F1IOO-T9 ay C''r   c                    | j                   j                  |        t        |      D ])  \  }}| j                   j                  d|dz   d|       + | j                   j                  dd       t               }	 	 t	        |      }d|cxk  rt        |      k  r|S  | j                   j                  dd       t               }K# t        $ r Y 3w xY w)	Nrc   r   z) zSelect an option: rd   re   r   zPlease select a valid option: )r`   ri   	enumeraterj   intr,   
ValueError)r   rl   choicesichoicern   values          r   _choice_inputz,InteractiveMigrationQuestioner._choice_inputm   s      H:/"7+IAv$$!a%%@A ,  !5b A!F u,G, L -$$%Eb$QWF   s   =C 	CCc                    | j                   j                  d       |r| j                   j                  d| d       | j                   j                  d       | j                   j                  d       	 |rdj                  |      }nd}| j                   j                  |d	       t               }|s|r|}|s| j                   j                  d
       n4|dk(  rt	        j
                  d       n	 t        |i t        t        d      S # t        t        f$ r(}| j                   j                  d|z         Y d}~3d}~ww xY w)z
        Prompt for a default value.

        The ``default`` argument allows providing a custom default value (as a
        string) which will be shown to the user and used as the return value
        if the user doesn't provide any other input.
        z/Please enter the default value as valid Python.zAccept the default 'z/' by pressing 'Enter' or provide another value.zxThe datetime and django.utils.timezone modules are available, so it is possible to provide e.g. timezone.now as a value.zType 'exit' to exit this promptz[default: {}] >>> z>>> rd   re   z;Please enter some code, or 'exit' (without quotes) to exit.exitr   )datetimer   zInvalid input: %sN)r`   ri   formatrj   r^   rz   evalr{   r   SyntaxError	NameError)r   rm   promptcodees        r   _ask_defaultz+InteractiveMigrationQuestioner._ask_default~   s<    	  !RS$$&wi 0) * 	  F	
 	  !BC-44W=$$VB$77DG""((Q FbxX*VWW# $ $Y/ F&&,,-@1-DEEFs   1D
 
ED<<Ec                     | j                   sF| j                  d| d| dddg      }|dk(  rt        j                  d       y| j	                         S y)	r6   z.It is impossible to add a non-nullable field 'z' to z{ without specifying a default. This is because the database needs something to populate existing rows.
Please select a fix:bProvide a one-off default now (will be set on all existing rows with a null value for this column)6Quit and manually define a default value in models.py.      Nr   rx   r^   rz   r   r   r9   r:   rv   s       r   r;   z4InteractiveMigrationQuestioner.ask_not_null_addition   ss    ||''@ M \ "'(B MF {  ((**r   c                     | j                   sQ| j                  d| d| dg d      }|dk(  rt        S |dk(  rt        j                  d       y| j                         S y)r>   z-It is impossible to change a nullable field 'z' on z to non-nullable without providing a default. This is because the database needs something to populate existing rows.
Please select a fix:)r   zIgnore for now. Existing rows that contain NULL values will have to be handled manually, for example with a RunPython or RunSQL operation.r   r   r   N)r   rx   r   r^   rz   r   r   s       r   r?   z6InteractiveMigrationQuestioner.ask_not_null_alteration   st    ||''?
| L \ "'(
	F" {##1  ((**r   c                 b    d}| j                  ||||||j                  j                  fz  d      S )rA   z(Was %s.%s renamed to %s.%s (a %s)? [y/N]F)ro   ra   rU   )r   r:   rD   rE   rF   msgs         r   rB   z)InteractiveMigrationQuestioner.ask_rename   sG    8""((11 

 
	
r   c                 r    d}| j                  ||j                  |j                  |j                  fz  d      S )rH   z(Was the model %s.%s renamed to %s? [y/N]F)ro   r0   name)r   rJ   rK   r   s       r   rI   z/InteractiveMigrationQuestioner.ask_rename_model   sB    8""((/*>*>@T@TUV
 	
r   c                 &    | j                  dd      S )Nz
Merging will only work if the operations printed above do not conflict
with each other (working on different fields or models)
Should these migration branches be merged? [y/N]F)ro   rN   s     r   rM   z(InteractiveMigrationQuestioner.ask_merge   s     ""A 	
 	
r   c                     | j                   sH| j                  d| d| dddg      }|dk(  rt        j                  d       y
| j	                  d	      S y
)rP   z#It is impossible to add the field 'z' with 'auto_now_add=True' to zf without providing a default. This is because the database needs something to populate existing rows.
zDProvide a one-off default now which will be set on all existing rowsr   r   r   ztimezone.now)rm   Nr   r   s       r   rQ   z8InteractiveMigrationQuestioner.ask_auto_now_add_addition   st    ||''5j\ B**4 6,-
$L
F {  (((@@r   c                     | j                   sCt               }| j                  d| d| dd| ddg      }|dk(  rt        j                  d       y	)
rS   z!Callable default on unique field .zO will not generate unique values upon migrating.
Please choose how to proceed:
zContinue making this migration as the first step in writing a manual migration to generate unique values described here: https://docs.djangoproject.com/en/z=/howto/writing-migrations/#migrations-that-add-unique-fields.z)Quit and edit field options in models.py.r   r   N)r   r   rx   r^   rz   )r   r9   r:   versionrv   s        r   rT   zCInteractiveMigrationQuestioner.ask_unique_callable_default_addition  su    ||&(G''3J<q M2 39 :A	 BMN
 @	F {r   )NNNNr   )rd   )rU   rV   rW   r   ro   rx   r   r;   r?   rB   rI   rM   rQ   rT   __classcell__ra   s   @r   rZ   rZ   Z   s@    NRH("&FP.8


(r   rZ   c                   B     e Zd Z	 	 	 	 	 d fd	Zd Zd Zd Zd Z xZS )!NonInteractiveMigrationQuestionerc                 F    || _         || _        t        |   |||       y r\   )	verbositylogr]   r   )r   r   r   r   r   r   ra   s         r   r   z*NonInteractiveMigrationQuestioner.__init__$  s.     #) 	 	
r   c           	      Z    | j                   dkD  r| j                  d| d| d| d       y y )Nr   Field '' on model 'z' not migrated: r   )r   r   )r   r9   r:   reasons       r   log_lack_of_migrationz7NonInteractiveMigrationQuestioner.log_lack_of_migration4  s;    >>AHH*\*=M(! r   c                 T    | j                  ||d       t        j                  d       y )NzIit is impossible to add a non-nullable field without specifying a defaultr   r   r^   rz   r8   s      r   r;   z7NonInteractiveMigrationQuestioner.ask_not_null_addition;  s(    ""	
 	r   c                 >    | j                  d| d| d       t        S )Nr   r   z8' given a default of NOT PROVIDED and must be corrected.)r   r   r8   s      r   r?   z9NonInteractiveMigrationQuestioner.ask_not_null_alterationE  s-    j\j\ :2 3	
 r   c                 T    | j                  ||d       t        j                  d       y )NzUit is impossible to add a field with 'auto_now_add=True' without specifying a defaultr   r   r8   s      r   rQ   z;NonInteractiveMigrationQuestioner.ask_auto_now_add_additionM  s(    ""#	
 	r   )NNNr   N)	rU   rV   rW   r   r   r;   r?   rQ   r   r   s   @r   r   r   #  s-     
 r   r   )r{   r$   r'   r^   django.appsr   django.core.management.baser   django.db.modelsr   django.utilsr   django.utils.versionr   loaderr	   r   rZ   r   r7   r   r   <module>r      sM      	 
  5 ) ! 1 #H HVF%8 FR2(; 2r   