B
    b7                 @   s   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 G dd	 d	ejZG d
d dejZG dd dejZG dd dejZG dd dejZG dd dej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)Company)Employee)MyUser)Terminal)AppList)
Membershipc               @   s   e Zd ZG dd dZdS )$BackendDashboardBaseVendorSerializerc               @   s(   e Zd ZeZddddddgZddgZdS )z)BackendDashboardBaseVendorSerializer.MetaidnameZcompany_cnrZcontact_phoneZparent_vendor_company_logoZparent_vendor_software_logoN)__name__
__module____qualname__r   modelfieldsZread_only_fields r   r   1G:\easytimepro\master/mysite/cloud\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e Ze Ze Ze Z	e Z
e Ze Ze Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Zdd Zdd ZG dd dZdS )!BackendDashboardCompanySerializerc             C   s6   |j }|r.ddlm} ||j|j }|d }nd}|S )Nr   )convert_address2geolocationcountryZIndia)	address_1mysite.cloud.utilsr   r   )selfobjcompany_addressr   geolocation_infor   r   r   r   get_country_name&   s    
z2BackendDashboardCompanySerializer.get_country_namec             C   s   t jj|dd }|S )N)companyuser)r   objectsfiltervalues_listcount)r   r   
user_countr   r   r   get_user_count0   s    z0BackendDashboardCompanySerializer.get_user_countc             C   s4   ddl m}m} |jj|d}|jj|d }|S )Nr   )r   
Department)r   )department__in)mysite.personnel.modelsr   r&   r    r!   r#   )r   r   r   r&   department_queryemployee_countr   r   r   get_employee_count5   s    z4BackendDashboardCompanySerializer.get_employee_countc             C   s6   |j }|r.ddlm} ||j|j }|d }nd}|S )Nr   )r   provincezNot set)r   r   r   r   )r   r   r   r   r   r,   r   r   r   get_province>   s    
z.BackendDashboardCompanySerializer.get_provincec             C   s6   |j }|r.ddlm} ||j|j }|d }nd}|S )Nr   )r   cityzNot set)r   r   r   r   )r   r   r   r   r   r.   r   r   r   get_cityH   s    
z*BackendDashboardCompanySerializer.get_cityc             C   s   |j r|j S dS )NzNot set)company_phone)r   instancer   r   r   get_company_phoneR   s    z3BackendDashboardCompanySerializer.get_company_phonec             C   s   |j r|j S dS )NzNot set)r   )r   r1   r   r   r   get_company_addressU   s    z5BackendDashboardCompanySerializer.get_company_addressc             C   s"   t jj|d }|rdS dS d S )N)vendor_companyYesNo)r   r    r!   exists)r   r   
node_exitsr   r   r   get_vendor_status^   s    z3BackendDashboardCompanySerializer.get_vendor_statusc             C   sF   t jj|dd}tjj|dd}|r>|d jd}nd }|S )N)r   r   )id__indate_joinedr   z%d/%m/%Y)r   r    r!   r"   r   order_byr;   strftime)r   r1   user_id_listearliest_usercreate_dater   r   r   get_create_datee   s    z1BackendDashboardCompanySerializer.get_create_datec               @   s,   e Zd ZeZddddddddd	d
ddgZdS )z&BackendDashboardCompanySerializer.Metar
   r   country_namer0   r   r,   r.   r$   r*   vendor_statusr@   
sub_domainN)r   r   r   r   r   r   r   r   r   r   r   p   s   r   N)r   r   r   r   SerializerMethodFieldrB   r$   r*   r,   r.   r0   r   rC   r@   r   r%   r+   r-   r/   r2   r3   r9   rA   r   r   r   r   r   r      s&   
	

	r   c               @   s   e Zd Ze Ze Ze Ze Ze Z	e Z
e Ze Ze Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Zdd Zdd ZG dd dZdS ))BackendDashboardCompanyEmployeeSerializerc             C   s6   |j }|r.ddlm} ||j|j }|d }nd}|S )Nr   )r   r   Mexico)r   r   r   r   )r   r   r   r   r   r   r   r   r   r      s    
z:BackendDashboardCompanyEmployeeSerializer.get_country_namec             C   s   t jj|dd }|S )N)r   r   )r   r    r!   r"   r#   )r   r   r$   r   r   r   r%      s    z8BackendDashboardCompanyEmployeeSerializer.get_user_countc             C   s4   ddl m}m} |jj|d}|jj|d }|S )Nr   )r   r&   )r   )r'   )r(   r   r&   r    r!   r#   )r   r   r   r&   r)   r*   r   r   r   r+      s    z<BackendDashboardCompanyEmployeeSerializer.get_employee_countc             C   s6   |j }|r.ddlm} ||j|j }|d }nd}|S )Nr   )r   r,   zNot set)r   r   r   r   )r   r   r   r   r   r,   r   r   r   r-      s    
z6BackendDashboardCompanyEmployeeSerializer.get_provincec             C   s6   |j }|r.ddlm} ||j|j }|d }nd}|S )Nr   )r   r.   zNot set)r   r   r   r   )r   r   r   r   r   r.   r   r   r   r/      s    
z2BackendDashboardCompanyEmployeeSerializer.get_cityc             C   s   |j r|j S dS )NzNot set)r0   )r   r1   r   r   r   r2      s    z;BackendDashboardCompanyEmployeeSerializer.get_company_phonec             C   s   |j r|j S dS )NzNot set)r   )r   r1   r   r   r   r3      s    z=BackendDashboardCompanyEmployeeSerializer.get_company_addressc             C   s"   t jj|d }|rdS dS d S )N)r4   r5   r6   )r   r    r!   r7   )r   r   r8   r   r   r   r9      s    z;BackendDashboardCompanyEmployeeSerializer.get_vendor_statusc             C   sF   t jj|dd}tjj|dd}|r>|d jd}nd }|S )N)r   r   )r:   r;   r   z%d/%m/%Y)r   r    r!   r"   r   r<   r;   r=   )r   r1   r>   r?   r@   r   r   r   rA      s    z9BackendDashboardCompanyEmployeeSerializer.get_create_datec               @   s,   e Zd ZeZddddddddd	d
ddgZdS )z.BackendDashboardCompanyEmployeeSerializer.Metar
   r   rB   r0   r   r,   r.   r$   r*   rC   r@   rD   N)r   r   r   r   r   r   r   r   r   r   r      s   r   N)r   r   r   r   rE   rB   r$   r*   r,   r.   r0   r   rC   r@   r   r%   r+   r-   r/   r2   r3   r9   rA   r   r   r   r   r   rF   x   s&   
	

rF   c               @   sJ   e Zd Ze Ze Ze Zdd Zdd Z	dd Z
G dd dZd	S )
/BackendDashboardCompanyEmployeeExportSerializerc             C   s6   |j }|r.ddlm} ||j|j }|d }nd}|S )Nr   )r   r   rG   )r   r   r   r   )r   r   r   r   r   r   r   r   r   r      s    
z@BackendDashboardCompanyEmployeeExportSerializer.get_country_namec             C   s   t jj|dd }|S )N)r   r   )r   r    r!   r"   r#   )r   r   r$   r   r   r   r%      s    z>BackendDashboardCompanyEmployeeExportSerializer.get_user_countc             C   s4   ddl m}m} |jj|d}|jj|d }|S )Nr   )r   r&   )r   )r'   )r(   r   r&   r    r!   r#   )r   r   r   r&   r)   r*   r   r   r   r+      s    zBBackendDashboardCompanyEmployeeExportSerializer.get_employee_countc               @   s   e Zd ZeZddddgZdS )z4BackendDashboardCompanyEmployeeExportSerializer.Metar   r$   r*   rB   N)r   r   r   r   r   r   r   r   r   r   r      s   r   N)r   r   r   r   rE   rB   r$   r*   r   r%   r+   r   r   r   r   r   rH      s   
	rH   c               @   sZ   e Zd Ze Ze Ze Ze Zdd Z	dd Z
dd Zdd ZG d	d
 d
ZdS ) BackendDashboardDeviceSerializerc             C   s   |  }|dkrd}nd}|S )N)         OnlineOffline)getDynState)r   r   real_statusstatusr   r   r   get_real_status   s
    z0BackendDashboardDeviceSerializer.get_real_statusc             C   s   |j r|j S dS )N-)last_activity)r   r1   r   r   r   get_last_activity  s    z2BackendDashboardDeviceSerializer.get_last_activityc             C   sJ   ddl m}m} |j}|j}|rB||s<|||}|d }qFd}nd}|S )Nr   )convert_ip2addresscheck_ip_is_privateaddressz Private IP, Can not get locationrS   )r   rV   rW   sn
ip_address)r   r   rV   rW   rY   rZ   device_addressrX   r   r   r   get_address  s    

z,BackendDashboardDeviceSerializer.get_addressc             C   s
   |j jjS )N)arear   r   )r   r   r   r   r   get_company  s    z,BackendDashboardDeviceSerializer.get_companyc               @   s$   e Zd ZeZddddddddgZd	S )
z%BackendDashboardDeviceSerializer.Metar
   rY   aliasrZ   rP   rT   rX   r   N)r   r   r   r   r   r   r   r   r   r   r     s   r   N)r   r   r   r   rE   rP   rX   r   rT   rR   rU   r\   r^   r   r   r   r   r   rI      s   
rI   c               @   sZ   e Zd Ze Ze Ze Ze Zdd Z	dd Z
dd Zdd ZG d	d
 d
ZdS )&BackendDashboardDeviceExportSerializerc             C   s   |  }|dkrd}nd}|S )N)rJ   rK   rL   rM   rN   )rO   )r   r   rP   rQ   r   r   r   rR   '  s
    z6BackendDashboardDeviceExportSerializer.get_real_statusc             C   s   |j r|j S dS )NrS   )rT   )r   r1   r   r   r   rU   1  s    z8BackendDashboardDeviceExportSerializer.get_last_activityc             C   sJ   ddl m}m} |j}|j}|rB||s<|||}|d }qFd}nd}|S )Nr   )rV   rW   rX   z Private IP, Can not get locationrS   )r   rV   rW   rY   rZ   )r   r   rV   rW   rY   rZ   r[   rX   r   r   r   r\   4  s    

z2BackendDashboardDeviceExportSerializer.get_addressc             C   s
   |j jjS )N)r]   r   r   )r   r   r   r   r   r^   C  s    z2BackendDashboardDeviceExportSerializer.get_companyc               @   s.   e Zd ZeZddddddddd	d
dddgZdS )z+BackendDashboardDeviceExportSerializer.Metar
   rY   r_   rZ   rP   rT   rX   r   r$   Zfp_countZ
face_countZfv_countZ
palm_countN)r   r   r   r   r   r   r   r   r   r   r   G  s   r   N)r   r   r   r   rE   rP   rX   r   rT   rR   rU   r\   r^   r   r   r   r   r   r`   !  s   
r`   c               @   sJ   e Zd Ze Ze Ze Zdd Zdd Z	dd Z
G dd dZd	S )
BackendDashboardUserSerializerc             C   s   |j }|rd}nd}|S )NActiveInactive)	is_active)r   r   rd   rQ   r   r   r   get_active_statusT  s
    z0BackendDashboardUserSerializer.get_active_statusc             C   sF   ddl m} |jj|dd}tjj|d}ddd |D }|S )	Nr   )r   )r   r   )r:   ,c             S   s   g | ]
}|j qS r   )r   ).0cr   r   r   
<listcomp>b  s    zFBackendDashboardUserSerializer.get_belongs_company.<locals>.<listcomp>)mysite.base.modelsr   r    r!   r"   r   join)r   r   r   Zcompany_id_listZcompany_queryZcompany_list_formatr   r   r   get_belongs_company]  s
    z2BackendDashboardUserSerializer.get_belongs_companyc             C   s   |j r|j S dS )NzNot set)mobile)r   r1   r   r   r   
get_mobilef  s    z)BackendDashboardUserSerializer.get_mobilec               @   s$   e Zd ZeZddddddddgZd	S )
z#BackendDashboardUserSerializer.Metar
   usernameZemailrm   active_statusZ
last_loginr;   belongs_companyN)r   r   r   r   r   r   r   r   r   r   r   i  s   r   N)r   r   r   r   rE   rq   rp   rm   re   rl   rn   r   r   r   r   r   ra   O  s   		ra   c               @   s*   e Zd Ze Zdd ZG dd dZdS )"BackendDashboardEmployeeSerializerc             C   s   |j jj}|S )N)Z
departmentr   r   )r   r   company_namer   r   r   r^   s  s    
z.BackendDashboardEmployeeSerializer.get_companyc               @   s    e Zd ZeZddddddgZdS )z'BackendDashboardEmployeeSerializer.MetaZ
first_name	last_nameZgenderZ	hire_dateZemp_typer   N)r   r   r   r   r   r   r   r   r   r   r   x  s   r   N)r   r   r   r   rE   r   r^   r   r   r   r   r   rr   p  s   rr   c               @   sJ   e Zd Ze Ze Ze Zdd Zdd Z	dd Z
G dd dZd	S )
!BackendDashboardAppListSerializerc             C   s   |j j}|S )N)r   r   )r   r   rs   r   r   r   r^     s    z-BackendDashboardAppListSerializer.get_companyc             C   s   |j r
dS dS d S )Nr5   r6   )enable)r   r1   r   r   r   
get_enable  s    z,BackendDashboardAppListSerializer.get_enablec             C   s   |j r
dS dS d S )Nrb   rc   )active)r   r1   r   r   r   
get_active  s    z,BackendDashboardAppListSerializer.get_activec               @   s    e Zd ZeZddddddgZdS )z&BackendDashboardAppListSerializer.Metaro   rv   rx   Z
login_timeZlast_activer   N)r   r   r   r   r   r   r   r   r   r   r     s   r   N)r   r   r   r   rE   r   rv   rx   r^   rw   ry   r   r   r   r   r   ru     s   ru   N)Zrest_frameworkr   Zmysite.cloud.modelsr   r(   r   Zmysite.accounts.modelsr   Zmysite.iclock.modelsr   Zmysite.mobile.modelsr   rj   r   ZModelSerializerr	   r   rF   rH   rI   r`   ra   rr   ru   r   r   r   r   <module>   s   _W$..!