U
    _                     @   sj   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jZ	G dd dejZ
G d	d
 d
ejZdS )    )serializers)User)Customer)UserProfilec                   @   s   e Zd ZG dd dZdS )UserSerializerc                   @   sL   e Zd ZeZdddddddgZdd	idd	idd	idd	idd	idd	id
ZdS )zUserSerializer.Metausernameemail	last_name
first_nameis_staff	is_activeis_superuser
write_onlyT)r   r   r   r	   r
   Zis_supperuserN)__name__
__module____qualname__r   modelfieldsextra_kwargs r   r   3/var/www/html/iltdigicom/account/api/serializers.pyMeta
   s   r   N)r   r   r   r   r   r   r   r   r   	   s   r   c                   @   s    e Zd Ze ZG dd dZdS )UserProfileSerializerc                   @   s   e Zd ZeZddgZdS )zUserProfileSerializer.Metaphone_numberuserN)r   r   r   r   r   r   r   r   r   r   r      s   r   N)r   r   r   r   r   r   r   r   r   r   r      s   r   c                   @   s   e Zd ZejddiddZejddiddZejddZejdddZejdddZ	ejdddZ
ejdddZejdd	ZG d
d dZdd ZdS )RegistrationSerializer
input_typepasswordT)styler      )
max_lengthF)r    required)r!   c                   @   s0   e Zd ZeZddddddddgZdd	d
iiZdS )zRegistrationSerializer.Metar	   r
   r   
user_emailr   r   	password2customer_idr   TN)r   r   r   r   r   r   r   r   r   r   r   r   &   s
    r   c              	   C   s  | j d }| j d }i }||kr(d|d< d| j kr<d|d< n8ztjj| j d d}W n tjk
rr   d|d< Y nX d| j krd	|d< d
| j krtjj| j d
 d}t|dkrd|d
< d| j kr| j d  dkrtjj| j d d}t|dkrd|d< d| j krF| j d  dkrFt	jj| j d d}t|dkrFd|d< t|dkr^t
|t	jdj|d}d}d}d}	| dkrd}d}d}	t| j d
 | j d  | j d | j d |||	d}
|
| j d  |
  t	| j d  |
|d}|  |S )Nr   r#   zThe two paswwords must match.r$   z The Customer ID cannot be empty.)idz!This customer ID doest not exist.r	   zThe user last name is required.r   )r   r   zThis user name is already used.r"    )r   zThis email is already used.r   )r   z"This phone number is already used.r   )customerFTr
   )r   r   r	   r
   r   r   r   )r   r   r'   )validated_datar   objectsgetDoesNotExistr   filterlenstripr   r   ValidationErrorselect_relatedcountset_passwordsave)selfr   r#   errorsr'   usersuserprofilesZissupperuserZisactiveisstaffr   userprofiler   r   r   r3   -   sj    





 
	zRegistrationSerializer.saveN)r   r   r   r   	CharFieldr   r#   r   r
   r	   r   r"   IntegerFieldr$   r   r3   r   r   r   r   r      s   r   N)rest_frameworkr   django.contrib.auth.modelsr   customer.modelsr   account.modelsr   ModelSerializerr   r   r   r   r   r   r   <module>   s   