3
g&                 @   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   ]/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django/db/migrations/questioner.py__init__   s    
zMigrationQuestioner.__init__c             C   s   || j krdS ytj|}W n tk
r:   | jjddS X tj|j\}}|dkrb| jjddS yt	j
|}W n tk
r   | jjddS X t|ddrtjtjj|j}n0t|drt|jdkrdS tj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|j dV  qdS )z__init__.pyz.pyN)endswith).0xr   r   r   	<genexpr>6   s    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 )z#Adding a NOT NULL field to a model.Nr   )r   
field_name
model_namer   r   r   ask_not_null_addition8   s    z)MigrationQuestioner.ask_not_null_additionc             C   s   dS )z"Changing a NULL field to NOT NULL.Nr   )r   r*   r+   r   r   r   ask_not_null_alteration=   s    z+MigrationQuestioner.ask_not_null_alterationc             C   s   | j jddS )zWas this field really renamed?
ask_renameF)r   r   )r   r+   old_namenew_namefield_instancer   r   r   r.   B   s    zMigrationQuestioner.ask_renamec             C   s   | j jddS )zWas this model really renamed?ask_rename_modelF)r   r   )r   old_model_statenew_model_stater   r   r   r2   F   s    z$MigrationQuestioner.ask_rename_modelc             C   s   | j jddS )z-Do you really want to merge these migrations?	ask_mergeF)r   r   )r   r'   r   r   r   r5   J   s    zMigrationQuestioner.ask_mergec             C   s   dS )z(Adding an auto_now_add field to a model.Nr   )r   r*   r+   r   r   r   ask_auto_now_add_additionN   s    z-MigrationQuestioner.ask_auto_now_add_addition)NNN)__name__
__module____qualname____doc__r   r   r,   r-   r.   r2   r5   r6   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   sR   t d| }| r|d k	r|S x"| s6|d j dkr@t d}q W |d j dkS )Nz%s r   ZynzPlease answer yes or no: y)inputlower)r   questiondefaultresultr   r   r   _boolean_inputV   s    z-InteractiveMigrationQuestioner._boolean_inputc             C   s   t | x(t|D ]\}}t d|d |f  qW td}xNyt|}W n tk
r\   Y n"X d|  k ott|kn  r~|S td}q<W d S )Nz %s) %sr   zSelect an option: r   zPlease select a valid option: )print	enumerater=   int
ValueErrorr$   )r   r?   choicesichoicerA   valuer   r   r   _choice_input^   s    z,InteractiveMigrationQuestioner._choice_input c             C   s   t d |rt dj| t d t d x|r<dj|}nd}t|}| rV|rV|}|sdt d q,|dkrxtjd	 q,yt|i ttd
S  tt	fk
r } zt d|  W Y dd}~X q,X q,W 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.
        z3Please enter the default value now, as valid PythonzUYou can accept the default '{}' by pressing 'Enter' or you can provide another value.z]The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.nowzType 'exit' to exit this promptz[default: {}] >>> z>>> z;Please enter some code, or 'exit' (with no quotes) to exit.exitr   )datetimer   zInvalid input: %sN)
rC   formatr=   sysrM   evalrN   r   SyntaxError	NameError)r   r@   promptcodeer   r   r   _ask_defaultm   s,    

z+InteractiveMigrationQuestioner._ask_defaultc             C   s>   | j s:| jd||f ddg}|dkr2tjd n| j S dS )z#Adding a NOT NULL field to a model.zYou are trying to add a non-nullable field '%s' to %s without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:zbProvide a one-off default now (will be set on all existing rows with a null value for this column)z+Quit, and let me add a default in models.py      N)r   rK   rP   rM   rW   )r   r*   r+   rI   r   r   r   r,      s    z4InteractiveMigrationQuestioner.ask_not_null_additionc             C   sL   | j sH| jd||f dddg}|dkr,tS |dkr@tjd n| j S dS )z"Changing a NULL field to NOT NULL.zYou are trying to change the nullable field '%s' on %s to non-nullable without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:zbProvide a one-off default now (will be set on all existing rows with a null value for this column)zIgnore for now, and let me handle existing rows with NULL myself (e.g. because you added a RunPython or RunSQL operation to handle NULL values in a previous data migration)z+Quit, and let me add a default in models.pyrX   rY   N)r   rK   r   rP   rM   rW   )r   r*   r+   rI   r   r   r   r-      s    z6InteractiveMigrationQuestioner.ask_not_null_alterationc             C   s"   d}| j ||||||jjf dS )zWas this field really renamed?z+Did you rename %s.%s to %s.%s (a %s)? [y/N]F)rB   	__class__r7   )r   r+   r/   r0   r1   msgr   r   r   r.      s    z)InteractiveMigrationQuestioner.ask_renamec             C   s    d}| j ||j|j|jf dS )zWas this model really renamed?z+Did you rename the %s.%s model to %s? [y/N]F)rB   r'   name)r   r3   r4   r[   r   r   r   r2      s    z/InteractiveMigrationQuestioner.ask_rename_modelc             C   s   | j ddS )NzH
Merging will only work if the operations printed above do not conflict
z8with each other (working on different fields or models)
z4Do you want to merge these migration branches? [y/N]Fz
Merging will only work if the operations printed above do not conflict
with each other (working on different fields or models)
z
Merging will only work if the operations printed above do not conflict
with each other (working on different fields or models)
Do you want to merge these migration branches? [y/N])rB   )r   r'   r   r   r   r5      s     z(InteractiveMigrationQuestioner.ask_mergec             C   sB   | j s>| jdj||ddg}|dkr2tjd n| jddS dS )	z(Adding an auto_now_add field to a model.zYou are trying to add the field '{}' with 'auto_now_add=True' to {} without a default; the database needs something to populate existing rows.
z@Provide a one-off default now (will be set on all existing rows)z+Quit, and let me add a default in models.pyrX   rY   ztimezone.now)r@   N)r   rK   rO   rP   rM   rW   )r   r*   r+   rI   r   r   r   r6      s    z8InteractiveMigrationQuestioner.ask_auto_now_add_addition)N)rL   )r7   r8   r9   rB   rK   rW   r,   r-   r.   r2   r5   r6   r   r   r   r   r;   T   s   

"r;   c               @   s$   e Zd Zdd Zdd Zdd ZdS )!NonInteractiveMigrationQuestionerc             C   s   t jd d S )NrY   )rP   rM   )r   r*   r+   r   r   r   r,      s    z7NonInteractiveMigrationQuestioner.ask_not_null_additionc             C   s   t S )N)r   )r   r*   r+   r   r   r   r-      s    z9NonInteractiveMigrationQuestioner.ask_not_null_alterationc             C   s   t jd d S )NrY   )rP   rM   )r   r*   r+   r   r   r   r6      s    z;NonInteractiveMigrationQuestioner.ask_auto_now_add_additionN)r7   r8   r9   r,   r-   r6   r   r   r   r   r]      s   r]   )rN   r   r   rP   Zdjango.appsr   Zdjango.db.modelsr   Zdjango.utilsr   loaderr   r   r;   r]   r   r   r   r   <module>   s   G 