B
    Ob                 @   s   d dl mZ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mZ d d	lmZmZ d d
lmZ G dd deejZG dd deejZG dd deejZG dd deejZG dd deejZdS )    )responsestatus)gettext)	force_str)cache)
Department)viewsets)
user_photo)stamp2datetimedatetime2stamp)Datetime2StampSerializerStamp2DatetimeSerializer)APPCustomizeResponseModelMixinc               @   s   e Zd Zdd ZdS )AppSettingViewc             C   s   |j jr|j }|jr|jjpd}|jr.|jjp0d}t|jt|j	d}d|j j
|j j|j|||| |j jdddd}td| t|S |j j
ddddd	}t|S d S )
N )Zemp_companyzsoftwaresupport@zkteco.comzhttps://www.zkteco.in/u5   Copyright ©2020 ZKTECO CO.,LTD.
All rights reserved.)server_nameemp_idemp_codenameZphoto
departmentpositionZareaapp_rolets_emailwebsite	copyrightz[*]Payload:   )r   r   r   r   r   )userZis_employeer   	dept_namer   Zposition_namer	   r   strcompanyZpkZ
first_nameZget_attarear   printr   Response)selfrequestempr   r   Z	photo_urlZpayload r%   FG:\easytimepro\master/mysite/mobile\api_rest\views\view_app_setting.pylist   s2    

zAppSettingView.listN)__name__
__module____qualname__r'   r%   r%   r%   r&   r      s   r   c               @   s   e Zd Zdd ZdS )DateChoicesViewc          
   C   s   dt tdddt tdddt tdddt td	dd
t tdddt tdddt tddg}tj|tjdS )N   Zapp_attendance_date_today)coder   r   Zapp_attendance_date_yesterday   Zapp_attendance_date_this_week   Zapp_attendance_date_last_week   Zapp_attendance_date_this_month   Zapp_attendance_date_last_month   z app_attendance_date_user-defined)r   )r   _r   r!   r   HTTP_200_OK)r"   r#   datar%   r%   r&   r'   7   s    zDateChoicesView.listN)r(   r)   r*   r'   r%   r%   r%   r&   r+   6   s   r+   c               @   s   e Zd Zdd ZdS )DepartmentsViewc       	         s   |j }|jjj}d|}t|d }|stjj	|d
dddd}g }i xd|D ]\}|d }|r|krvg |< | |d |d |g d qV||d |d dd	 qVW  fd
d tt fdd| t|| tj|tjdS )Nzapp_dept_tree_{})r   idr   Zparent_deptZ	dept_code)r-   r   	parent_idsubsr   )r-   r   r8   c                s6    | d g }|r2x|D ]} | qW || d< d S )Nr-   r9   )get)objZp_subssub)get_subsr9   r%   r&   r=   Y   s
    
z&DepartmentsView.list.<locals>.get_subsc                s    | S )Nr%   )x)r=   r%   r&   <lambda>a       z&DepartmentsView.list.<locals>.<lambda>)r   )r   r   r   r7   formatr   r:   r   ZobjectsfiltervaluesZorder_byappendr'   mapsetr   r!   r   r4   )	r"   r#   r$   Z
company_idZdept_keyZ	dept_treeZdeptsZdeptparentr%   )r=   r9   r&   r'   E   s*    


zDepartmentsView.listN)r(   r)   r*   r'   r%   r%   r%   r&   r6   D   s   r6   c               @   s   e Zd ZeZdd ZdS )Stamp2DatetimeViewc             O   sP   | j |jd}| r>|j}|d}t|}tj|tj	dS tj|j
tjdS )N)r5   stamp)r   )get_serializerquery_paramsis_validvalidated_datar:   r
   r   r!   r   r4   errorsHTTP_400_BAD_REQUEST)r"   r#   argskwargs
serializerrM   rI   dtr%   r%   r&   r'   i   s    
zStamp2DatetimeView.listN)r(   r)   r*   r   serializer_classr'   r%   r%   r%   r&   rH   f   s   rH   c               @   s   e Zd ZeZdd ZdS )Datetime2StampViewc             O   sP   | j |jd}| r>|j}|d}t|}tj|tj	dS tj|j
tjdS )N)r5   rS   )r   )rJ   rK   rL   rM   r:   r   r   r!   r   r4   rN   rO   )r"   r#   rP   rQ   rR   rM   rS   rI   r%   r%   r&   r'   v   s    
zDatetime2StampView.listN)r(   r)   r*   r   rT   r'   r%   r%   r%   r&   rU   s   s   rU   N)Zrest_frameworkr   r   Zdjango.utils.translationr   r3   Zdjango.utils.encodingr   Zdjango.core.cacher   Zmysite.personnel.modelsr   Zmysite.mobile.api_restr   Zmysite.mobile.utilsr	   r
   r   Z"mysite.mobile.api_rest.serializersr   r   Z(mysite.mobile.api_rest.app_customize_mixr   ZGenericViewSetr   r+   r6   rH   rU   r%   r%   r%   r&   <module>   s   $"