o
    i                     @   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 separation for multiple groups)z--exclude-groupsexclude_groupszMExclude users matching this group. (use comma separation for multiple groups))superadd_argumentsadd_argumentDEFAULT_FAKE_EMAIL)selfparser	__class__ u/var/www/html/formularioweb/env/lib/python3.10/site-packages/django_extensions/management/commands/set_fake_emails.pyr      s^   	
zCommand.add_argumentsc                 O   sL  t jstdddlm} |d }|d }|d }|d }|d }|d	 }	|d
 }
t }|j }|	r9|jdd}|
rA|jdd}|r\|jj	|
dd}|rV|j|d}ntd| |rw|jj	|
dd}|rq|j	|d}ntd| |r|j|d}|r|j	|d}|D ]}||j|j|jd |_|  qtd|   d S )NzOnly available in debug moder   )Groupr
   r   r   r   r   r   r   T)is_superuser)is_staff,)name__in)
groups__inzNo groups matches filter: %s)username__regex)username
first_name	last_namezChanged %d emails)r   DEBUGr   django.contrib.auth.modelsr    r   objectsallexcludefiltersplitr'   r(   r)   emailsaveprintcount)r   argsoptionsr    r1   r   r   r   r   r   r   Userusersgroupsuserr   r   r   handleU   sL   


zCommand.handle)__name__
__module____qualname__r   r   r	   r   str__annotations__r   r   r;   __classcell__r   r   r   r   r      s   
 7r   N)__doc__typingr   django.confr   django.contrib.authr   django.core.management.baser   r   "django_extensions.management.utilsr   r   r   r   r   r   r   <module>   s   	