o
    ˷e                     @   sP   d dl m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eZ
dS )	    )BaseCommand)Count)EmailAddress)
user_email)get_user_modelc                   @   s$   e Zd Zdd Zdd Zdd ZdS )Commandc                 O   s   |   D ]}| | qd S )N)%get_users_with_multiple_primary_emailunprimary_extra_primary_emails)selfargsoptionsuser r   }/var/www/ideatree/venv/lib/python3.10/site-packages/allauth/account/management/commands/account_unsetmultipleprimaryemails.pyhandle
   s   zCommand.handlec                 C   sN   g }t jjdddtdjddD ]	}||d  qt jj|dS )NTprimaryr      )user__count__gt)pk__in)r   objectsfiltervaluesannotater   appendr   )r
   user_pksemail_address_dictr   r   r   r      s   
z-Command.get_users_with_multiple_primary_emailc                 C   sj   t jj|dd}|D ]}|jt|kr nq
td|jddd |D |f  |j|jdj	dd	 d S )
NT)r   r   zZWARNING: Multiple primary without a user.email match foruser pk %s; (tried: %s, using: %s)z, c                 S   s   g | ]}|j qS r   )email).0email_addressr   r   r   
<listcomp>'   s    z:Command.unprimary_extra_primary_emails.<locals>.<listcomp>)pkFr   )
r   r   r   r   r   printr!   joinexcludeupdate)r
   r   primary_email_addressesprimary_email_addressr   r   r   r	      s$   
z&Command.unprimary_extra_primary_emailsN)__name__
__module____qualname__r   r   r	   r   r   r   r   r   	   s    r   N)django.core.management.baser   django.db.modelsr   allauth.account.modelsr   allauth.account.utilsr   allauth.utilsr   r   r   r   r   r   <module>   s    