a
    ÛEb®'  ã                   @   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 G dd„ dƒZG d	d
„ d
eƒZG dd„ deƒZdS )é    N)Úapps©ÚNOT_PROVIDED)Útimezoneé   )ÚMigrationLoaderc                   @   sR   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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   ú_/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/django/db/migrations/questioner.pyÚ__init__   s    
zMigrationQuestioner.__init__c                 C   sþ   || j v rdS zt |¡}W n  ty<   | j dd¡ Y S 0 t |j¡\}}|du rd| j dd¡S zt	 
|¡}W n  ty’   | j dd¡ Y S 0 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>5   ó    z2MigrationQuestioner.ask_initial.<locals>.<genexpr>)r   r   Zget_app_configÚLookupErrorr
   Úgetr   Úmigrations_moduleÚlabelÚ	importlibÚimport_moduleÚImportErrorÚgetattrÚosÚlistdirÚpathÚdirnamer   ÚhasattrÚlenr   ÚlistÚany)r   Ú	app_labelZ
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_addition7   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   r0   Úold_nameÚnew_nameÚfield_instancer   r   r   r5   A   s    zMigrationQuestioner.ask_renamec                 C   s   | j  dd¡S )úWas this model really renamed?Úask_rename_modelFr6   )r   Úold_model_stateÚnew_model_stater   r   r   r;   E   s    z$MigrationQuestioner.ask_rename_modelc                 C   s   | j  dd¡S )z)Should these migrations really be merged?Ú	ask_mergeFr6   ©r   r*   r   r   r   r>   I   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_additionM   s    z-MigrationQuestioner.ask_auto_now_add_addition)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r1   r3   r5   r;   r>   rA   r   r   r   r   r      s   
r   c                   @   sX   e Z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S )ÚInteractiveMigrationQuestionerNc                 C   sJ   t d| ƒ}|s|d ur|S |r0|d  ¡ dvr:t dƒ}q|d  ¡ dkS )Nz%s r   ZynzPlease answer yes or no: Úy)ÚinputÚlower)r   ÚquestionÚdefaultÚresultr   r   r   Ú_boolean_inputT   s    
z-InteractiveMigrationQuestioner._boolean_inputc                 C   s„   t |ƒ t|ƒD ]\}}t d|d |f ƒ qtdƒ}zt|ƒ}W n tyT   Y n"0 d|  k rnt|ƒkrvn n|S tdƒ}q6d S )Nz %s) %sr   zSelect an option: r   zPlease select a valid option: )ÚprintÚ	enumeraterH   ÚintÚ
ValueErrorr'   )r   rJ   ÚchoicesÚiÚchoicerL   Úvaluer   r   r   Ú_choice_input\   s    z,InteractiveMigrationQuestioner._choice_inputÚ c              
   C   sÆ   t dƒ |rt d|› d�ƒ t dƒ t dƒ |r<d |¡}nd}t|ƒ}|sT|rT|}|sbt dƒ q,|d	krvt d
¡ q,zt|i ttdœƒW S  tt	fy¾ } zt d| ƒ W Y d}~q,d}~0 0 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>>> z;Please enter some code, or 'exit' (without quotes) to exit.Úexitr   )Údatetimer   zInvalid input: %sN)
rN   ÚformatrH   ÚsysrX   ÚevalrY   r   ÚSyntaxErrorÚ	NameError)r   rK   ÚpromptÚcodeÚer   r   r   Ú_ask_defaultk   s.    
ÿÿ
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   rV   r[   rX   rb   ©r   r/   r0   rT   r   r   r   r1   �   s    ÿûúz4InteractiveMigrationQuestioner.ask_not_null_additionc                 C   sP   | j sL|  d|› d|› d�g d¢¡}|dkr0tS |dkrDt d¡ n|  ¡ S dS )r2   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:)rc   zŠIgnore for now. Existing rows that contain NULL values will have to be handled manually, for example with a RunPython or RunSQL operation.rd   re   rf   N)r   rV   r   r[   rX   rb   rh   r   r   r   r3   §   s    ÿúz6InteractiveMigrationQuestioner.ask_not_null_alterationc                 C   s"   d}|   ||||||jjf d¡S )r4   z(Was %s.%s renamed to %s.%s (a %s)? [y/N]F)rM   Ú	__class__rB   )r   r0   r7   r8   r9   Úmsgr   r   r   r5   Ã   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)rM   r*   Úname)r   r<   r=   rj   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)rM   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 )r@   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 rowsrd   re   rf   ztimezone.now)rK   Nrg   rh   r   r   r   rA   ã   s    ÿýûz8InteractiveMigrationQuestioner.ask_auto_now_add_addition)N)rW   )rB   rC   rD   rM   rV   rb   r1   r3   r5   r;   r>   rA   r   r   r   r   rF   S   s   

%	rF   c                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )Ú!NonInteractiveMigrationQuestionerc                 C   s   t  d¡ d S ©Nrf   ©r[   rX   r.   r   r   r   r1   ù   s    z7NonInteractiveMigrationQuestioner.ask_not_null_additionc                 C   s   t S r	   r   r.   r   r   r   r3   ý   s    z9NonInteractiveMigrationQuestioner.ask_not_null_alterationc                 C   s   t  d¡ d S rm   rn   r.   r   r   r   rA     s    z;NonInteractiveMigrationQuestioner.ask_auto_now_add_additionN)rB   rC   rD   r1   r3   rA   r   r   r   r   rl   ø   s   rl   )rY   r   r"   r[   Zdjango.appsr   Zdjango.db.modelsr   Zdjango.utilsr   Úloaderr   r   rF   rl   r   r   r   r   Ú<module>   s   F &