U
    ¹ßŽi4  ã                   @   sš   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
„ d
ƒZG dd„ deƒZG dd„ deƒZdS )é    N)Úapps)ÚOutputWrapper)ÚNOT_PROVIDED)Útimezone)Úget_docs_versioné   )ÚMigrationLoaderc                   @   sZ   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zd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                 C   s    |pi | _ |ptƒ | _|| _d S )N)ÚdefaultsÚsetÚspecified_appsÚdry_run)Úselfr
   r   r   © r   ú]/var/www/html/IITS/school/venv/lib/python3.8/site-packages/django/db/migrations/questioner.pyÚ__init__   s    
zMigrationQuestioner.__init__c                 C   s  || j krdS zt |¡}W n" tk
r>   | j dd¡ Y S X t |j¡\}}|dkrf| j dd¡S zt	 
|¡}W n" tk
r–   | j dd¡ Y S X t|ddƒrºt tj |j¡¡}n0t|dƒrêt|jƒdkrÖdS t t|jƒd ¡}td	d
„ |D ƒƒ S dS )z2Should we create an initial migration for the app?TÚask_initialFNÚ__file__Ú__path__r   r   c                 s   s    | ]}|d kr|  d¡V  qdS )z__init__.pyz.pyN)Úendswith)Ú.0Úxr   r   r   Ú	<genexpr>7   s      z2MigrationQuestioner.ask_initial.<locals>.<genexpr>)r   r   Úget_app_configÚLookupErrorr
   Úgetr   Úmigrations_moduleÚlabelÚ	importlibÚimport_moduleÚImportErrorÚgetattrÚosÚlistdirÚpathÚdirnamer   ÚhasattrÚlenr   ÚlistÚany)r   Ú	app_labelÚ
app_configZmigrations_import_pathÚ_r   Ú	filenamesr   r   r   r      s(    

zMigrationQuestioner.ask_initialc                 C   s   dS )ú#Adding a NOT NULL field to a model.Nr   ©r   Ú
field_nameÚ
model_namer   r   r   Úask_not_null_addition9   s    z)MigrationQuestioner.ask_not_null_additionc                 C   s   dS )ú"Changing a NULL field to NOT NULL.Nr   r/   r   r   r   Úask_not_null_alteration>   s    z+MigrationQuestioner.ask_not_null_alterationc                 C   s   | j  dd¡S )úWas this field really renamed?Ú
ask_renameF©r
   r   )r   r1   Úold_nameÚnew_nameÚfield_instancer   r   r   r6   C   s    zMigrationQuestioner.ask_renamec                 C   s   | j  dd¡S )úWas this model really renamed?Úask_rename_modelFr7   )r   Úold_model_stateÚnew_model_stater   r   r   r<   G   s    z$MigrationQuestioner.ask_rename_modelc                 C   s   | j  dd¡S )z)Should these migrations really be merged?Ú	ask_mergeFr7   ©r   r*   r   r   r   r?   K   s    zMigrationQuestioner.ask_mergec                 C   s   dS )ú(Adding an auto_now_add field to a model.Nr   r/   r   r   r   Úask_auto_now_add_additionO   s    z-MigrationQuestioner.ask_auto_now_add_additionc                 C   s   dS )ú.Adding a unique field with a callable default.Nr   r/   r   r   r   Ú$ask_unique_callable_default_additionT   s    z8MigrationQuestioner.ask_unique_callable_default_addition)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r2   r4   r6   r<   r?   rB   rD   r   r   r   r   r	      s   
r	   c                       sr   e Zd Zd‡ fdd„	Zddd„Zdd„ Zdd	d
„Zdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Z‡  ZS )ÚInteractiveMigrationQuestionerNc                    s&   t ƒ j|||d� |pttjƒ| _d S ©N)r
   r   r   )Úsuperr   r   ÚsysÚstdoutÚprompt_output)r   r
   r   r   rN   ©Ú	__class__r   r   r   [   s      ÿz'InteractiveMigrationQuestioner.__init__c                 C   sh   | j j|› d�dd� tƒ }|s,|d k	r,|S |r@|d  ¡ dkrX| j jddd� tƒ }q,|d  ¡ dkS )Nú Ú ©Úendingr   ZynzPlease answer yes or no: Úy)rN   ÚwriteÚinputÚlower)r   ÚquestionÚdefaultÚresultr   r   r   Ú_boolean_inputc   s    z-InteractiveMigrationQuestioner._boolean_inputc                 C   s¬   | j  |› ¡ t|ƒD ] \}}| j  d|d |f ¡ q| j jddd� tƒ }zt|ƒ}W n tk
rn   Y n"X d|  k rˆt|ƒkr�n n|S | j jddd� tƒ }qNd S )Nz %s) %sr   zSelect an option: rR   rS   r   zPlease select a valid option: )rN   rV   Ú	enumeraterW   ÚintÚ
ValueErrorr'   )r   rY   ÚchoicesÚiÚchoicer[   Úvaluer   r   r   Ú_choice_inputm   s    z,InteractiveMigrationQuestioner._choice_inputrR   c              
   C   sê   | j  d¡ |r$| j  d|› d�¡ | j  d¡ | j  d¡ |rLd |¡}nd}| j j|dd	� tƒ }|sr|rr|}|s„| j  d
¡ q<|dkr˜t d¡ q<zt|i ttdœƒW S  t	t
fk
râ } z| j  d| ¡ W 5 d}~X Y q<X q<dS )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>>> rR   rS   z;Please enter some code, or 'exit' (without quotes) to exit.Úexitr   )Údatetimer   zInvalid input: %sN)rN   rV   ÚformatrW   rL   re   Úevalrf   r   ÚSyntaxErrorÚ	NameError)r   rZ   ÚpromptÚcodeÚer   r   r   Ú_ask_default~   s4    
ÿÿÿz+InteractiveMigrationQuestioner._ask_defaultc                 C   sD   | j s@|  d|› d|› d�ddg¡}|dkr8t d¡ n|  ¡ S dS )	r.   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   rd   rL   re   rn   ©r   r0   r1   rb   r   r   r   r2   ¦   s    ûúz4InteractiveMigrationQuestioner.ask_not_null_additionc                 C   sR   | j sN|  d|› d|› d�dddg¡}|dkr2tS |dkrFt d¡ n|  ¡ S d	S )
r3   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:ro   zŠIgnore for now. Existing rows that contain NULL values will have to be handled manually, for example with a RunPython or RunSQL operation.rp   rq   rr   N)r   rd   r   rL   re   rn   rt   r   r   r   r4   ½   s    øúz6InteractiveMigrationQuestioner.ask_not_null_alterationc                 C   s"   d}|   ||||||jjf d¡S )r5   z(Was %s.%s renamed to %s.%s (a %s)? [y/N]F)r\   rP   rE   )r   r1   r8   r9   r:   Úmsgr   r   r   r6   Ù   s    ûÿ÷z)InteractiveMigrationQuestioner.ask_renamec                 C   s    d}|   ||j|j|jf d¡S )r;   z(Was the model %s.%s renamed to %s? [y/N]F)r\   r*   Úname)r   r=   r>   ru   r   r   r   r<   è   s    ÿýz/InteractiveMigrationQuestioner.ask_rename_modelc                 C   s   |   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)r\   r@   r   r   r   r?   ñ   s    üz(InteractiveMigrationQuestioner.ask_mergec                 C   sH   | j sD|  d|› d|› d�ddg¡}|dkr8t d¡ n| jdd	�S d
S )rA   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 rowsrp   rq   rr   ztimezone.now)rZ   Nrs   rt   r   r   r   rB   ù   s    ýûz8InteractiveMigrationQuestioner.ask_auto_now_add_additionc                 C   sH   | j sDtƒ }|  d|› d|› d�d|› d�dg¡}|dkrDt d¡ d	S )
rC   z!Callable default on unique field Ú.zO will not generate unique values upon migrating.
Please choose how to proceed:
z›Continue 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.rq   rr   N)r   r   rd   rL   re   )r   r0   r1   Úversionrb   r   r   r   rD     s    
úü
zCInteractiveMigrationQuestioner.ask_unique_callable_default_addition)NNNN)N)rR   )rE   rF   rG   r   r\   rd   rn   r2   r4   r6   r<   r?   rB   rD   Ú__classcell__r   r   rO   r   rI   Z   s          ÿ


(	rI   c                       s>   e Zd Zd‡ fdd„	Zdd„ Zdd„ Zd	d
„ Zdd„ Z‡  ZS )Ú!NonInteractiveMigrationQuestionerNr   c                    s"   || _ || _tƒ j|||d� d S rJ   )Ú	verbosityÚlogrK   r   )r   r
   r   r   r{   r|   rO   r   r   r   $  s    ýz*NonInteractiveMigrationQuestioner.__init__c              	   C   s,   | j dkr(|  d|› d|› d|› d�¡ d S )Nr   úField 'ú' on model 'z' not migrated: rw   )r{   r|   )r   r0   r1   Úreasonr   r   r   Úlog_lack_of_migration4  s    
ÿz7NonInteractiveMigrationQuestioner.log_lack_of_migrationc                 C   s   |   ||d¡ t d¡ d S )NzIit is impossible to add a non-nullable field without specifying a defaultrr   ©r€   rL   re   r/   r   r   r   r2   ;  s    ýz7NonInteractiveMigrationQuestioner.ask_not_null_additionc                 C   s   |   d|› d|› d�¡ tS )Nr}   r~   z8' given a default of NOT PROVIDED and must be corrected.)r|   r   r/   r   r   r   r4   E  s    ÿz9NonInteractiveMigrationQuestioner.ask_not_null_alterationc                 C   s   |   ||d¡ t d¡ d S )NzUit is impossible to add a field with 'auto_now_add=True' without specifying a defaultrr   r�   r/   r   r   r   rB   M  s    ýz;NonInteractiveMigrationQuestioner.ask_auto_now_add_addition)NNNr   N)	rE   rF   rG   r   r€   r2   r4   rB   ry   r   r   rO   r   rz   #  s        ú
rz   )rf   r   r"   rL   Údjango.appsr   Údjango.core.management.baser   Údjango.db.modelsr   Údjango.utilsr   Údjango.utils.versionr   Úloaderr   r	   rI   rz   r   r   r   r   Ú<module>   s   K J