a
    8Xh"                     @   s\   d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ dZG dd	 d	eZd
S )z
set_fake_emails.py

    Give all users a new email account. Useful for testing in a
    development environment. As such, this command is only available when
    setting.DEBUG is True.

    )List)settings)get_user_model)BaseCommandCommandError)signalcommandz%(username)s@example.comc                       sD   e Zd ZU def Zg Zee ed<  fddZ	e
dd Z  ZS )CommandzDEBUG only: give all users a new email based on their account data ("%s" by default). Possible parameters are: username, first_name, last_namerequires_system_checksc                    s   t  | |jddtdd |jddddd	d
d |jddddd	dd |jddd dd |jddd dd |jddd dd |jddd dd d S )Nz--emaildefault_emailz!Use this as the new email format.)destdefaulthelpz-az
--no-admin
store_trueno_adminFz$Do not change administrator accounts)actionr   r   r   z-sz
--no-staffno_staffzDo not change staff accountsz	--includeinclude_regexpz'Include usernames matching this regexp.z	--excludeexclude_regexpz'Exclude usernames matching this regexp.z--include-groupsinclude_groupszMInclude users matching this group. (use comma seperation for multiple groups)z--exclude-groupsexclude_groupszMExclude users matching this group. (use comma seperation for multiple groups))superadd_argumentsadd_argumentDEFAULT_FAKE_EMAIL)selfparser	__class__ z/var/www/viveiro_mudafortebrasil/venv/lib/python3.9/site-packages/django_extensions/management/commands/set_fake_emails.pyr      s:    zCommand.add_argumentsc                 O   sP  t jstdddlm} |d }|d }|d }|d }|d }|d	 }	|d
 }
t }|j }|	rr|jdd}|
r|jdd}|r|jj	|
dd}|r|j|d}ntd| |r|jj	|
dd}|r|j	|d}ntd| |r|j|d}|r|j	|d}|D ]&}||j|j|jd |_|  qtd|   d S )NzOnly available in debug moder   )Groupr
   r   r   r   r   r   r   T)Zis_superuser)Zis_staff,)Zname__in)Z
groups__inzNo groups matches filter: %s)Zusername__regex)username
first_name	last_namezChanged %d emails)r   DEBUGr   Zdjango.contrib.auth.modelsr    r   Zobjectsallexcludefiltersplitr"   r#   r$   emailsaveprintcount)r   argsoptionsr    r*   r   r   r   r   r   r   ZUserZusersgroupsuserr   r   r   handle9   sJ    

zCommand.handle)__name__
__module____qualname__r   r   r	   r   str__annotations__r   r   r2   __classcell__r   r   r   r   r      s
   

r   N)__doc__typingr   Zdjango.confr   Zdjango.contrib.authr   Zdjango.core.management.baser   r   Z"django_extensions.management.utilsr   r   r   r   r   r   r   <module>   s   	