
    Evg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dS )    N)apps)OutputWrapper)NOT_PROVIDED)timezone)get_docs_version   )MigrationLoaderc                   J    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dS )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                 P    |pi | _         |pt                      | _        || _        d S N)defaultssetspecified_appsdry_run)selfr   r   r   s       \/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/db/migrations/questioner.py__init__zMigrationQuestioner.__init__   s)     B,5    c                    || j         v rdS 	 t          j        |          }n+# t          $ r | j                            dd          cY S w xY wt          j        |j                  \  }}|| j                            dd          S 	 t          j
        |          }t          |dd          r7t          j        t          j                            |j                            }nVt#          |d          rFt%          |j                  dk    rdS t          j        t)          |j                  d                   }t+          d	 |D                        S # t,          $ r | 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   L   K   | ]}|d k    |                     d          V   dS )z__init__.pyz.pyN)endswith).0xs     r   	<genexpr>z2MigrationQuestioner.ask_initial.<locals>.<genexpr>7   s8      VV1CUCU1::e,,CUCUCUCUVVr   )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   s    +++4
	;,Y77JJ 	; 	; 	;=$$]E:::::	;$3$EjFV$W$W!!)=$$]E:::	W ) 78N O O (*d;; LJrw7H7Q'R'RSS		*J77 L(122Q66 5Jt,=,F'G'G'JKK	VViVVVVVVV  	; 	; 	;=$$]E:::::	;s!   " %A
	A
E %E;:E;c                     dS )#Adding a NOT NULL field to a model.N r   
field_name
model_names      r   ask_not_null_additionz)MigrationQuestioner.ask_not_null_addition9   	     tr   c                     dS )"Changing a NULL field to NOT NULL.Nr7   r8   s      r   ask_not_null_alterationz+MigrationQuestioner.ask_not_null_alteration>   r<   r   c                 8    | 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55r   c                 8    | 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                 8    | 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44r   c                     dS )(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                     dS ).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      s            
W W W<  
  
6 6 6< < <5 5 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 )InteractiveMigrationQuestionerNc                     t                                          |||           |pt          t          j                  | _        d S N)r   r   r   )superr   r   sysstdoutprompt_output)r   r   r   r   r`   	__class__s        r   r   z'InteractiveMigrationQuestioner.__init__[   sL     	ng 	 	
 	
 	
 +GmCJ.G.Gr   c                 p   | j                             | dd           t                      }|s||S |r|d                                         dvrH| j                             dd           t                      }|,|d                                         dvH|d                                         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 ;;; 	'-N 	F1IOO--T99$$%@$LLLWWF  	F1IOO--T99 ay  C''r   c                    | j                             |            t          |          D ](\  }}| j                             d|dz   d|           )| j                             dd           t                      }	 	 t	          |          }d|cxk     rt          |          k    rn n|S n# t          $ r Y nw xY w| j                             d	d           t                      }k)
Nrc   r   z) zSelect an option: rd   re   Tr   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++ 	B 	BIAv$$$!a%%%%@AAAA  !5b AAA		!F u,,,,G,,,,, L -    
 $$%Eb$QQQWWF		s    B/ /
B<;B<rd   c                    | j                             d           |r| j                             d| d           | j                             d           | j                             d           	 |rd                    |          }nd}| j                             |d	
           t                      }|s|r|}|s| j                             d           nu|dk    rt	          j        d           nZ	 t          |i t          t          d          S # t          t          f$ r'}| j                             d|z             Y d}~nd}~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 promptTz[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SS 	$$*w * * *   	  F	
 	
 	
 	  !BCCC	F  -44W==$$VB$77777D G  
F"((Q    FbxX*V*VWWW#Y/ F F F&,,-@1-DEEEEEEEEF%	Fs   3D E	"EE	c                     | j         sN|                     d| d| dddg          }|dk    rt          j        d           n|                                 S dS )	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   s    | 	+''( ( ( ( ( (B M F {{((***tr   c                     | j         s[|                     d| d| dg d          }|dk    rt          S |dk    rt          j        d           n|                                 S dS )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   s    | 	+''(
 ( ( ( ( (
	 	 	 F" {{##1((***tr   c                 V    d}|                      ||||||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   sF    8""(1 

 

 
	
r   c                 \    d}|                      ||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   s>    8""(/*>@TUV
 
 	
r   c                 .    |                      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         sP|                     d| d| dddg          }|dk    rt          j        d           n|                     d	          S d
S )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   s    | 	A''-j - -*4- - -
$L
 
F {{(((@@@tr   c                     | j         sKt                      }|                     d| d| dd| ddg          }|dk    rt          j        d           d	S )
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  s    | 	&((G''3J 3 3 3 3 3N :AN N N
 @	 F {{tr   )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 H H H H H( ( ( (  "&F &F &F &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 )	!NonInteractiveMigrationQuestionerNr   c                 l    || _         || _        t                                          |||           d S r\   )	verbositylogr]   r   )r   r   r   r   r   r   ra   s         r   r   z*NonInteractiveMigrationQuestioner.__init__$  sG     #) 	 	
 	
 	
 	
 	
r   c           	      ^    | j         dk    r!|                     d| d| d| d           d S d S )Nr   Field '' on model 'z' not migrated: r   )r   r   )r   r9   r:   reasons       r   log_lack_of_migrationz7NonInteractiveMigrationQuestioner.log_lack_of_migration4  sf    >AHH*  *         r   c                 \    |                      ||d           t          j        d           d S )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;  s8    ""	
 	
 	
 	r   c                 H    |                      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  sB    3j 3 3j 3 3 3	
 	
 	
 r   c                 \    |                      ||d           t          j        d           d S )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  s8    ""#	
 	
 	
 	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      s2        				 



       5 5 5 5 5 5 ) ) ) ) ) ) ! ! ! ! ! ! 1 1 1 1 1 1 # # # # # #H H H H H H H HVF F F F F%8 F F FR2 2 2 2 2(; 2 2 2 2 2r   