3
g"                 @   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                   s@   e Zd ZU def Zg Zee  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_namec                s   t  j| |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__ s/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django_extensions/management/commands/set_fake_emails.pyr      s,    

zCommand.add_argumentsc             O   sV  t jstdddlm} |d }|d }|d }|d }|d }|d	 }	|d
 }
t }|jj }|	rr|jdd}|
r|jdd}|r|jj	|j
dd}|r|j|d}ntd| |r|jj	|j
dd}|r|j	|d}ntd| |r |j|d}|r|j	|d}x.|D ]&}||j|j|jd |_|j  qW td|j   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   sH    

zCommand.handle)__name__
__module____qualname__r   r   Zrequires_system_checksr   strr   r   r0   __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   