o
    þÞh 5  ã                   @   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/premium_crap/venv/lib/python3.10/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 w t |j¡\}}|du r2| j dd¡S zt	 
|¡}W n tyI   | j dd¡ Y S w t|ddƒr[t tj |j¡¡}nt|dƒrst|jƒdkridS t t|jƒd ¡}td	d
„ |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_configÚmigrations_import_pathÚ_r   Ú	filenamesr   r   r   r      s,   
ÿÿ
zMigrationQuestioner.ask_initialc                 C   ó   dS )ú#Adding a NOT NULL field to a model.Nr   ©r   Ú
field_nameÚ
model_namer   r   r   Úask_not_null_addition9   ó   z)MigrationQuestioner.ask_not_null_additionc                 C   r0   )ú"Changing a NULL field to NOT NULL.Nr   r2   r   r   r   Úask_not_null_alteration>   r6   z+MigrationQuestioner.ask_not_null_alterationc                 C   ó   | j  dd¡S )úWas this field really renamed?Ú
ask_renameF©r   r   )r   r4   Úold_nameÚnew_nameÚfield_instancer   r   r   r;   C   ó   zMigrationQuestioner.ask_renamec                 C   r9   )úWas this model really renamed?Úask_rename_modelFr<   )r   Úold_model_stateÚnew_model_stater   r   r   rB   G   r@   z$MigrationQuestioner.ask_rename_modelc                 C   r9   )z)Should these migrations really be merged?Ú	ask_mergeFr<   ©r   r+   r   r   r   rE   K   r@   zMigrationQuestioner.ask_mergec                 C   r0   )ú(Adding an auto_now_add field to a model.Nr   r2   r   r   r   Úask_auto_now_add_additionO   r6   z-MigrationQuestioner.ask_auto_now_add_additionc                 C   r0   )ú.Adding a unique field with a callable default.Nr   r2   r   r   r   Ú$ask_unique_callable_default_additionT   r6   z8MigrationQuestioner.ask_unique_callable_default_addition)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r5   r8   r;   rB   rE   rH   rJ   r   r   r   r   r	      s    
r	   c                       st   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   rT   ©Ú	__class__r   r   r   [   s   ÿz'InteractiveMigrationQuestioner.__init__c                 C   sz   | j j|› d�dd� tƒ }|s|d ur|S |r |d  ¡ dvr5| j jddd� tƒ }|r |d  ¡ dvs |d  ¡ dkS )Nú Ú ©Úendingr   ÚynzPlease answer yes or no: Úy)rT   Ú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� 	 z	tƒ }t|ƒ}W n ty7   Y n" tyJ   | j  d¡ t d¡ Y nw d|  k rXt	|ƒkrY|S  | j jd	dd� q%)
Nz %s) %sr   zSelect an option: rX   rY   Tú
Cancelled.r   zPlease select a valid option: )
rT   r]   Ú	enumerater^   ÚintÚ
ValueErrorÚKeyboardInterruptrR   Úexitr(   )r   r`   ÚchoicesÚiÚchoicerb   Úvaluer   r   r   Ú_choice_inputm   s&   þÿôz,InteractiveMigrationQuestioner._choice_inputrX   c              
   C   s  | j  d¡ |r| j  d|› d�¡ | j  d¡ | j  d¡ 	 |r'd |¡}nd}| j j|d	d
� ztƒ }W n tyJ   | j  d¡ t d¡ Y nw |sQ|rQ|}|sZ| j  d¡ n4|dkrdt d¡ n*z
t|i tt	dœƒW S  t
y� } z| j  |jj› d|› �¡ W Y d}~nd}~ww q)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>>> rX   rY   rd   r   z;Please enter some code, or 'exit' (without quotes) to exit.ri   )Údatetimer   z: N)rT   r]   Úformatr^   rh   rR   ri   Úevalro   r   Ú	ExceptionrV   rK   )r   ra   ÚpromptÚcodeÚer   r   r   Ú_ask_default€   sF   
ÿÿ
þÿ&€ÿêz+InteractiveMigrationQuestioner._ask_defaultc                 C   sF   | j s!|  d|› d|› d�ddg¡}|dkrt d¡ dS |  ¡ S dS )	r1   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   rn   rR   ri   rv   ©r   r3   r4   rl   r   r   r   r5   ¬   s   ÿûú
ÿz4InteractiveMigrationQuestioner.ask_not_null_additionc                 C   sR   | j s'|  d|› d|› d�g d¢¡}|dkrtS |dkr#t d¡ dS |  ¡ S dS )r7   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:)rw   zŠIgnore for now. Existing rows that contain NULL values will have to be handled manually, for example with a RunPython or RunSQL operation.rx   ry   rz   N)r   rn   r   rR   ri   rv   r|   r   r   r   r8   Ã   s   ÿú
ÿz6InteractiveMigrationQuestioner.ask_not_null_alterationc                 C   s"   d}|   ||||||jjf d¡S )r:   z(Was %s.%s renamed to %s.%s (a %s)? [y/N]F)rc   rV   rK   )r   r4   r=   r>   r?   Úmsgr   r   r   r;   ß   s   ûÿ÷z)InteractiveMigrationQuestioner.ask_renamec                 C   s    d}|   ||j|j|jf d¡S )rA   z(Was the model %s.%s renamed to %s? [y/N]F)rc   r+   Úname)r   rC   rD   r}   r   r   r   rB   î   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)rc   rF   r   r   r   rE   ÷   s   üz(InteractiveMigrationQuestioner.ask_mergec                 C   sJ   | j s#|  d|› d|› d�ddg¡}|dkrt d¡ d
S | jdd	�S d
S )rG   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 rowsrx   ry   rz   ztimezone.now)ra   Nr{   r|   r   r   r   rH   ÿ   s   ÿýû
ÿz8InteractiveMigrationQuestioner.ask_auto_now_add_additionc                 C   sH   | j s"tƒ }|  d|› d|› d�d|› d�dg¡}|dkr"t d¡ d	S )
rI   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.ry   rz   N)r   r   rn   rR   ri   )r   r3   r4   Úversionrl   r   r   r   rJ     s   ýúü
zCInteractiveMigrationQuestioner.ask_unique_callable_default_addition)NNNNr
   )rX   )rK   rL   rM   r   rc   rn   rv   r5   r8   r;   rB   rE   rH   rJ   Ú__classcell__r   r   rU   r   rO   Z   s    ÿ


,	rO   c                       sH   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 rP   )Ú	verbosityÚlogrQ   r   )r   r   r   r   rƒ   r„   rU   r   r   r   *  s   
ýz*NonInteractiveMigrationQuestioner.__init__c              	   C   s0   | j dkr|  d|› d|› d|› d�¡ d S d S )Nr   úField 'ú' on model 'z' not migrated: r   )rƒ   r„   )r   r3   r4   Úreasonr   r   r   Úlog_lack_of_migration:  s   
ÿÿÿz7NonInteractiveMigrationQuestioner.log_lack_of_migrationc                 C   ó   |   ||d¡ t d¡ d S )NzIit is impossible to add a non-nullable field without specifying a defaultrz   ©rˆ   rR   ri   r2   r   r   r   r5   A  ó   ý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   r2   r   r   r   r8   K  s   ÿz9NonInteractiveMigrationQuestioner.ask_not_null_alterationc                 C   r‰   )NzUit is impossible to add a field with 'auto_now_add=True' without specifying a defaultrz   rŠ   r2   r   r   r   rH   S  r‹   z;NonInteractiveMigrationQuestioner.ask_auto_now_add_addition)NNNr   N)	rK   rL   rM   r   rˆ   r5   r8   rH   r�   r   r   rU   r   r‚   )  s    ú
r‚   )ro   r   r#   rR   Údjango.appsr   Údjango.core.management.baser   Údjango.db.modelsr   Údjango.utilsr   Údjango.utils.versionr   Úloaderr   r	   rO   r‚   r   r   r   r   Ú<module>   s    K P