o
    Kc                     @   s   d dl Z 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
 d dlmZ d dlmZ d d	lmZ d d
lmZ dd ZG dd dejZG dd dejZG dd dejZee
eddd ZdS )    N)uuid4)models)reverse)receiver)	post_save)RegexValidator)gettext_lazy)CountryField)Userc                 C   s(   t j|\}}t  | }d| S )Nzprofile_avatar/)ospathsplitextr   )instancefilename_file_extensionnew_filename r   9/var/www/html/docker_usevoice/src/apps/profiles/models.pyavatar_filename   s   
r   c                   @   s    e Zd ZdZdZdZdZdZdS )AddressType)homeHome)workWork)billingBilling)primaryPrimary)otherOtherN)__name__
__module____qualname__HOMEWORKBILLINGPRIMARYOTHERr   r   r   r   r      s    r   c                   @   sv   e Zd ZejddddZejddddZejddddZejddddZejddddZ	e
ddZejdejdZd	S )
Address   T
max_lengthblanknull
   (select country)blank_label	   )r,   choicesN)r!   r"   r#   r   	CharFieldstreet_addresscitystateregionzip_coder	   countryr   r4   address_typer   r   r   r   r)      s    
r)   c                   @   s  e Zd ZejedejdZejdde	dZ
ejddddZejeejdddZed	d
dZejegddddZejedddZejdddZeddZejddddZejddddZejedddZejedddZejedddZdd Zdd Z dd Z!dd Z"dd  Z#d!S )"ProfileT)primary_key	on_deletezProfile Picturezprofile_avatar/default.png)verbose_namedefault	upload_tor*   r+   )r?   r-   r.   z^\d{10,15}$zRPhone number must be entered in the format: '+999999999'. Up to 15 digits allowed.)regexmessage   )
validatorsr,   r-   r.   zIs Phone VerifiedF)rA   )r-   r.   r0   r1   zCommunication With PhonezCommunication With EmailzAllow Changesc                 C      t dd| jidS )Nprofilepkkwargsr   user_idselfr   r   r   get_absolute_url8      zProfile.get_absolute_urlc                 C   rG   )Nzaccounts:profile-updaterI   rJ   rL   rN   r   r   r   get_profile_update_url;   rQ   zProfile.get_profile_update_urlc                 C   s(   z| j jddW S  tjy   Y d S w )Nr   )r<   )address_setgetr)   DoesNotExistrN   r   r   r   get_primary_address>   s
   zProfile.get_primary_addressc                 C   sb   | j d kr/| j D ]$}|jdkr|j|j|jf  S |jr.|jr.|jr.|j|j|jf  S q
dS )Nr   )NNN)addressrS   allr<   r8   r9   r;   )rO   rW   r   r   r   get_locationD   s   

zProfile.get_locationc                 C   s   | j  dS )Nz ProfileuserrN   r   r   r   __str__N   s   zProfile.__str__N)$r!   r"   r#   r   OneToOneFieldr
   CASCADEr[   
ImageFieldr   avatarr5   
occupation
ForeignKeyr)   rW   r   phone_regexphoneBooleanFieldr   phone_verifiedURLFieldchannel_urlr	   r;   language	time_zonecommunication_phonecommunication_emailallow_changesrP   rR   rV   rY   r\   r   r   r   r   r=   &   s(    

r=   )senderc                 K   s"   |rt jj|d}|  d S d S )NrZ   )r=   objectscreatesave)rn   createdr   rK   rH   r   r   r   create_profileS   s   rs   )r   uuidr   	django.dbr   django.urlsr   django.dispatchr   django.db.models.signalsr   django.core.validatorsr   django.utils.translationr   r   django_countries.fieldsr	   apps.accounts.modelsr
   r   TextChoicesr   Modelr)   r=   rs   r   r   r   r   <module>   s     	
-