U
    9d                     @   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_Zfile_extensionZnew_filename r   8/var/www/html/UseVoiceDocker/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)homeZHome)ZworkZWork)ZbillingZBilling)primaryZPrimary)otherOtherN)__name__
__module____qualname__HOMEWORKZBILLINGPRIMARYZ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)Zblank_label	   )r"   choicesN)r   r   r   r   	CharFieldZstreet_addressZcitystateregionZzip_coder	   countryr   r)   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!   )r1   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)r3   )r#   r$   r&   r'   zCommunication With PhonezCommunication With EmailzAllow Changesc                 C   s   t dd| jidS )Nprofilepkkwargsr   user_idselfr   r   r   get_absolute_url8   s    zProfile.get_absolute_urlc                 C   s   t dd| jidS )Nzaccounts:profile-updater:   r;   r=   r?   r   r   r   get_profile_update_url;   s    zProfile.get_profile_update_urlc                 C   s.   z| j jddW S  tjk
r(   Y d S X d S )Nr   )r.   )address_setgetr   DoesNotExistr?   r   r   r   get_primary_address>   s    zProfile.get_primary_addressc                 C   sb   | j d kr^| j D ]H}|jdkr6|j|j|jf  S |jr|jr|jr|j|j|jf  S qdS )Nr   )NNN)addressrC   allr.   r+   r,   r-   )r@   rG   r   r   r   get_locationD   s    

zProfile.get_locationc                 C   s   | j  dS )Nz Profileuserr?   r   r   r   __str__N   s    zProfile.__str__N)$r   r   r   r   OneToOneFieldr
   CASCADErK   
ImageFieldr   Zavatarr*   Z
occupation
ForeignKeyr   rG   r   Zphone_regexphoneBooleanFieldr   Zphone_verifiedURLFieldZchannel_urlr	   r-   language	time_zoneZcommunication_phoneZcommunication_emailZallow_changesrA   rB   rF   rI   rL   r   r   r   r   r/   &   s&   

r/   )senderc                 K   s   |rt jj|d}|  d S )NrJ   )r/   objectscreatesave)rV   createdr   r<   r9   r   r   r   create_profileS   s    r[   )r   uuidr   	django.dbr   django.urlsr   django.dispatchr   Zdjango.db.models.signalsr   Zdjango.core.validatorsr   django.utils.translationr   r   Zdjango_countries.fieldsr	   Zapps.accounts.modelsr
   r   TextChoicesr   Modelr   r/   r[   r   r   r   r   <module>   s   	-
