ó
¸9—^c           @   sl   d  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
 d e f d „  ƒ  YZ d	 S(
   s»   
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.

iÿÿÿÿ(   t   settings(   t   get_user_model(   t   BaseCommandt   CommandError(   t   signalcommands   %(username)s@example.comt   Commandc           B   s3   e  Z d  e f Z e Z d „  Z e d „  ƒ Z RS(   sŽ   DEBUG only: give all users a new email based on their account data ("%s" by default). Possible parameters are: username, first_name, last_namec         C   s  t  t |  ƒ j | ƒ | j d d d d t d d ƒ| j d d d	 d
 d d d t d d ƒ| j d d d	 d
 d 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  d d ƒ| j d d d d d  d d ƒd  S(   Ns   --emailt   destt   default_emailt   defaultt   helps!   Use this as the new email format.s   -as
   --no-admint   actiont
   store_truet   no_admins$   Do not change administrator accountss   -ss
   --no-stafft   no_staffs   Do not change staff accountss	   --includet   include_regexps'   Include usernames matching this regexp.s	   --excludet   exclude_regexps'   Exclude usernames matching this regexp.s   --include-groupst   include_groupssM   Include users matching this group. (use comma seperation for multiple groups)s   --exclude-groupst   exclude_groupssM   Exclude users matching this group. (use comma seperation for multiple groups)(   t   superR   t   add_argumentst   add_argumentt   DEFAULT_FAKE_EMAILt   Falset   None(   t   selft   parser(    (    sW   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/set_fake_emails.pyR      s,    c         O   sï  t  j s t d ƒ ‚ n  d d l m } | d } | d } | d } | d } | d } | d	 }	 | d
 }
 t ƒ  } | j j ƒ  } |	 r¡ | j d t	 ƒ } n  |
 r¼ | j d t	 ƒ } n  | r| j j
 d | j d ƒ ƒ } | rû | j d | ƒ } qt d | ƒ ‚ n  | r`| j j
 d | j d ƒ ƒ } | rM| j
 d | ƒ } q`t d | ƒ ‚ n  | r{| j d | ƒ } n  | r–| j
 d | ƒ } n  xC | D]; } | i | j d 6| j d 6| j d 6| _ | j ƒ  qWd | j ƒ  GHd  S(   Ns   Only available in debug modeiÿÿÿÿ(   t   GroupR   R   R   R   R   R   R   t   is_superusert   is_stafft   name__int   ,t
   groups__ins   No groups matches filter: %st   username__regext   usernamet
   first_namet	   last_names   Changed %d emails(   R    t   DEBUGR   t   django.contrib.auth.modelsR   R   t   objectst   allt   excludet   Truet   filtert   splitR!   R"   R#   t   emailt   savet   count(   R   t   argst   optionsR   R,   R   R   R   R   R   R   t   Usert   userst   groupst   user(    (    sW   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/set_fake_emails.pyt   handle7   sH    	






	
(	   t   __name__t
   __module__R   R	   R   t   requires_system_checksR   R   R5   (    (    (    sW   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/set_fake_emails.pyR      s   	N(   t   __doc__t   django.confR    t   django.contrib.authR   t   django.core.management.baseR   R   t"   django_extensions.management.utilsR   R   R   (    (    (    sW   /tmp/pip-unpacked-wheel-a0M10Y/django_extensions/management/commands/set_fake_emails.pyt   <module>	   s   