
    si                     &   d dl mZ d dlmZmZ d dlmZ 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 d dlmZ d dlmZ d dlmZ ddl  G d de      Z  G d de      Z!d Z"d Z#e ed      ed                      Z$y)    )messages)login_requiredpermission_required)	QueryDict)redirectrender)method_decorator)gettext_lazy)csrf_exemptstatus)IsAuthenticated)Response)APIView)Company)FaceDetectionSetupForm)hx_request_required   )*c                       e Zd ZegZd Zd Zd Z e e	dd      d      d	        Z
 e e	d
d      d      d        Z e e	dd      d      d        Zy)FaceDetectionConfigAPIViewc                     	 |j                   j                  j                         }|S # t        $ r}t        j                  |      d }~ww xY wNuseremployee_getget_company	ExceptionserializersValidationErrorselfrequestcompanyes       7/var/www/python-projects/worksol/facedetection/views.pyr   z&FaceDetectionConfigAPIView.get_company   E    	1ll//;;=GN 	1--a00	1   %( 	AAAc                     | j                  |      }	 t        j                  j                  |      }|S # t        $ r}t
        j                  |      d }~ww xY wN)
company_id)r   FaceDetectionobjectsget_or_creater   r   r    r"   r#   r$   facedetectionr%   s        r&   get_facedetectionz,FaceDetectionConfigAPIView.get_facedetection   sW    ""7+	1)11??7?SM   	1--a00	1   !5 	AAAc                     t        | j                  |      d         }t        |j                  t        j
                        S )Nr   r   )FaceDetectionSerializerr1   r   datar   HTTP_200_OK)r"   r#   
serializers      r&   getzFaceDetectionConfigAPIView.get&   s3    ,T-C-CG-LQ-OP

0B0BCC    zfacedetection.add_facedetectionT)raise_exceptiondispatch)namec                    |j                   }t        |t              r|j                         }| j	                  |      j
                  |d<   t        |      }|j                         r5|j                          t        |j                   t        j                        S t        |j                  t        j                        S )Nr+   r5   r   )r5   
isinstancer   dictr   idr4   is_validsaver   r   HTTP_201_CREATEDerrorsHTTP_400_BAD_REQUESTr"   r#   r5   r7   s       r&   postzFaceDetectionConfigAPIView.post*   s    
 ||dI&99;D!--g699\,$7
 OOJOOF4K4KLL
))&2M2MNNr9   z"facedetection.change_facedetectionc                 ,   |j                   }t        | j                  |      d   |      }|j                         r5|j	                          t        |j                   t        j                        S t        |j                  t        j                        S )Nr   r>   r   )
r5   r4   r1   rB   rC   r   r   r6   rE   rF   rG   s       r&   putzFaceDetectionConfigAPIView.put9   st    
 ||,""7+A.T

  OOJOOF4F4FGG
))&2M2MNNr9   z"facedetection.delete_facedetectionc                 z    | j                  |      j                          t        ddit        j                        S )Nmessagez"Facedetection deleted successfullyr   )r1   deleter   r   r6   )r"   r#   s     r&   rM   z!FaceDetectionConfigAPIView.deleteG   s9    
 	w'..0<=fFXFX
 	
r9   N)__name__
__module____qualname__r   permission_classesr   r1   r8   r	   r   rH   rJ   rM    r9   r&   r   r      s    )*11D =tT	O		O @RVWO	O @RVW
	
r9   r   c                   L     e Zd ZegZ ee       fd       Zd Zd Z	d Z
 xZS )#EmployeeFaceDetectionGetPostAPIViewc                 "    t        |   |i |S r   )superr;   )r"   argskwargs	__class__s      r&   r;   z,EmployeeFaceDetectionGetPostAPIView.dispatchU   s    w000r9   c                     	 |j                   j                  j                         }|S # t        $ r}t        j                  |      d }~ww xY wr   r   r!   s       r&   r   z/EmployeeFaceDetectionGetPostAPIView.get_companyY   r'   r(   c                     | j                  |      }	 t        j                  j                  |      }|S # t        $ r}t
        j                  |      d }~ww xY wr*   r   r,   r-   r8   r   r   r    r/   s        r&   r1   z5EmployeeFaceDetectionGetPostAPIView.get_facedetection`   sW    ""7+	1)11555IM   	1--a00	1r2   c                    | j                  |      j                  r|j                  j                  j                  }|j
                  }t        |t              r|j                         }||d<   t        |      }|j                         r5|j                          t        |j
                  t        j                        S t        |j                  t        j                         S t"        j%                  d      )Nemployee_idr>   r   zFacedetection not yet started..)r1   startr   r   rA   r5   r?   r   r@   EmployeeFaceDetectionSerializerrB   rC   r   r   rD   rE   rF   r   r    )r"   r#   r^   r5   r7   s        r&   rH   z(EmployeeFaceDetectionGetPostAPIView.posth   s    !!'*00!,,3366K<<D$	*yy{"-D8dCJ""$!
8O8OPPJ--f6Q6QRR))*KLLr9   )rN   rO   rP   r   rQ   r	   r   r;   r   r1   rH   __classcell__)rY   s   @r&   rT   rT   R   s3    )*k"1 #111Mr9   rT   c                     	 | j                   j                  d      }|dk(  ry t        j                  j                  |      }|S # t        $ r}t
        j                  |      d }~ww xY w)Nselected_companyall)rA   )sessionr8   r   r-   r   r   r    )r#   rc   r$   r%   s       r&   r   r   w   sf    -"??../ABu$//%%)9%: -))!,,-s    A !A 	A(A##A(c                     t        |       }	 t        j                  j                  |      }|S # t        $ r}t
        j                  |      d }~ww xY wr*   r\   )r#   r$   locationr%   s       r&   r1   r1      sP    '"G- ((,,,@ -))!,,-s   !/ 	AAAzgeofencing.add_localbackupc                    	 t        t        |             }| j                  dk(  r	 t        | j                  t        |             }|j	                         rR|j                  d      }t        |       |_        |j                          t        j                  | t        d             nt        j                  | d       t        | dd|i      S #  t               }Y xY w#  t        | j                        }Y xY w)	N)instancePOSTF)commitz*facedetection config created successfully.z	Not validzface_config.htmlform)r   r1   methodrj   rB   rC   r   r+   r   success_infor   )r#   rl   r0   s      r&   face_detection_configrq      s    (%/@/IJ ~~	8)'8'AD
 ==? II & M (37';M$ Wa(T&UVMM';/'-~>>'(%'	8)',,7Ds   C  C CC8N)%django.contribr   django.contrib.auth.decoratorsr   r   django.httpr   django.shortcutsr   r   django.utils.decoratorsr	   django.utils.translationr
   ro   django.views.decorators.csrfr   rest_frameworkr   rest_framework.permissionsr   rest_framework.responser   rest_framework.viewsr   base.modelsr   facedetection.formsr   horilla.decoratorsr   r   r   rT   r   r1   rq   rR   r9   r&   <module>r      s    # N ! - 4 6 4 ! 6 , (  6 2 ;
 ;
|"M' "MJ-- 12?  3 ?r9   