B
    ADb                 @   s   d dl mZmZ d dlmZ d dlmZmZmZ d dl	m
Z
mZmZ G dd dejZG dd deZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZdS )    )viewsets
pagination)Response)LeaveOvertime	ManualLog)StaffLeaveSerializerStaffOvertimeSerializerStaffManualLogSerializerc               @   s   e Zd Zdej_ejZdS )BaseStaffViewSetZ	page_sizeN)__name__
__module____qualname__r   ZPageNumberPaginationZpage_size_query_paramZpagination_class r   r   1G:\easytimepro\master/mysite/att\api\views_ext.pyr      s   r   c               @   s"   e Zd Zej ZeZdd Z	dS )StaffLeaveViewSetc       	      O   s`   t jj|jd}| }| |}|dk	r:| j|dd}n| j|dd}dd||jd}t|S )z
            Gets the exceptions that has a workflow instance asociated and in at least one of its nodes
            the employee has the role required to approve or rejec it
        )employeeNT)manyr    )codemsgcountdata)	r   objectsfilteruserr   paginate_querysetget_serializerr   r   )	selfrequestargskwargsqueryset
page_countpage
serializercontextr   r   r   list   s    

zStaffLeaveViewSet.listN)
r   r   r   r   r   allr"   r   serializer_classr'   r   r   r   r   r      s   
r   c               @   s"   e Zd Zej ZeZdd Z	dS )StaffOvertimeViewSetc       	      O   s`   t jj|jd}| }| |}|dk	r:| j|dd}n| j|dd}dd||jd}t|S )z
            Gets the exceptions that has a workflow instance asociated and in at least one of its nodes
            the employee has the role required to approve or rejec it
        )r   NT)r   r   r   )r   r   r   r   )	r   r   r   r   r   r   r   r   r   )	r   r   r    r!   r"   r#   r$   r%   r&   r   r   r   r'   0   s    

zStaffOvertimeViewSet.listN)
r   r   r   r   r   r(   r"   r	   r)   r'   r   r   r   r   r*   ,   s   
r*   c               @   s"   e Zd Zej ZeZdd Z	dS )StaffManualLogViewSetc       	      O   s`   t jj|jd}| }| |}|d k	r:| j|dd}n| j|dd}dd||jd}t|S )N)r   T)r   r   r   )r   r   r   r   )	r   r   r   r   r   r   r   r   r   )	r   r   r    r!   r"   r#   r$   r%   r&   r   r   r   r'   P   s    

zStaffManualLogViewSet.listN)
r   r   r   r   r   r(   r"   r
   r)   r'   r   r   r   r   r+   H   s   
r+   c               @   s"   e Zd Zej ZeZdd Z	dS )StaffLeaveApproveSetc       	      O   s   yt jj|jj d }W n   t jj|jd}Y nX | }| 	|}|dk	rf| j
|dd}n| j
|dd}dd||jd}t|S )	z
            Gets the exceptions that has a workflow instance asociated and in at least one of its nodes
            the employee has the role required to approve or rejec it
        )9workflowinstance__nodeinstance__node_engine__approver__in)r   NT)r   r   r   )r   r   r   r   )r   r   r   r   	flow_roler(   distinctexcluder   r   r   r   r   )	r   r   r    r!   r"   r#   r$   r%   r&   r   r   r   r'   f   s    

zStaffLeaveApproveSet.listN)
r   r   r   r   r   r(   r"   r   r)   r'   r   r   r   r   r,   b   s   
r,   c               @   s"   e Zd Zej ZeZdd Z	dS )StaffOvertimeApproveSetc       	      O   s   yt jj|jj d }W n   t jj|jd}Y nX | }| 	|}|dk	rf| j
|dd}n| j
|dd}dd||jd}t|S )	z
            Gets the exceptions that has a workflow instance asociated and in at least one of its nodes
            the employee has the role required to approve or rejec it
        )r-   )r   NT)r   r   r   )r   r   r   r   )r   r   r   r   r.   r(   r/   r0   r   r   r   r   r   )	r   r   r    r!   r"   r#   r$   r%   r&   r   r   r   r'      s    

zStaffOvertimeApproveSet.listN)
r   r   r   r   r   r(   r"   r	   r)   r'   r   r   r   r   r1      s   
r1   c               @   s"   e Zd Zej ZeZdd Z	dS )StaffManualLogApproveSetc       	      O   s   yt jj|jj d }W n   t jj|jd}Y nX | }| 	|}|d k	rf| j
|dd}n| j
|dd}dd||jd}t|S )N)r-   )r   T)r   r   r   )r   r   r   r   )r   r   r   r   r.   r(   r/   r0   r   r   r   r   r   )	r   r   r    r!   r"   r#   r$   r%   r&   r   r   r   r'      s    

zStaffManualLogApproveSet.listN)
r   r   r   r   r   r(   r"   r
   r)   r'   r   r   r   r   r2      s   
r2   N)Zrest_frameworkr   r   Zrest_framework.responser   Zmysite.att.modelsr   r   r   Zmysite.att.api.serializer_extr   r	   r
   ZModelViewSetr   r   r*   r+   r,   r1   r2   r   r   r   r   <module>   s   