
    Iyfp                         d dl mZ d dlmZ d dlmZ d dlmZ d dlZd dl	m
Z
 d dlmZ d dlmZ ed	             Zed
             Zed             ZdS )    )render)status)JsonResponse)csrf_exemptN)verify_token)CancelReasons)CancelReasonsSerializerc                 d   t          |           }|d k    r)t          dt          j        ddt          j                  S | j        dk    rt          j        | j                  }t                      }|d         |_	        t          |d                   |_        |                                 t          dt          j        ddt          j                  S t          j                                        }t!          |d	
          }t          |j        t          j        ddt          j                  S )NzUser is not loginmessager   Fsafer   POSTtitle
reason_forz Cancel Reason added successfullyTmany)cancel_reasonsr   )r   r   r   HTTP_401_UNAUTHORIZEDmethodjsonloadsbodyr   r   intr   saveHTTP_200_OKobjectsallr	   data)requestuser_idrequest_datacancel_reason
serializers        FC:\Users\hp\python\driverzz\driverzz-admin-api\cancel_reasons\views.pycancelReasonsr&      sC   7##G$':VEabbinw}  xT  U  U  U  	U>V##:gl33L)OOM".w"7M'*<+E'F'FM$   +MX^Xj k krw  AG  AS  T  T  T  T *15577M0TJJJJ:?VM_ ` `glu{  vH  I  I  I  I    c                    | j         dk    rt          j        | j                  }|d         rt          j                            |d                   }|d         |_        t          |d                   |_	        |
                                 t          dt          j        ddt          j        	          S t          d
t          j        ddt          j        	          S | j                            d          r	 t          j                            | j                            d                    }t!          |d          }t          |j        t          j        ddt          j        	          S # t          j        $ r, t          dt          j        ddt          j        	          cY S w xY wt          dt          j        ddt          j        	          S )Nr   idr)   r   r   z"Cancel reason updated successfullyr   Fr   zCancel reason  id is requiredr   )r#   r   zCancel reason doesn't existzCancel reason id is required)r   r   r   r   r   r   getr   r   r   r   r   r   r   HTTP_400_BAD_REQUESTGETr	   r   DoesNotExist)r    r"   r#   r$   s       r%   editCancelReasonr/   !   s/   ~z',// 	a)155<;M5NNM".w"7M'*<+E'F'FM$   ,P[a[m n nuz  DJ  DV  W  W  W  W(GSYSnoov{  EK  E`  a  a  a  
a ;??4   	cf - 5 9 9w{t?T?T 9 U U4]OOO
#jovOa$b$binw}  xJ  K  K  K  K - f f f#/LX^Xs$t$t  |A  JP  Je  f  f  f  f  f  ff  +IU[Up q qx}  GM  Gb  c  c  c  cs   ;A6E2 28F-,F-c                    t          |           }|d k    r)t          dt          j        ddt          j                  S 	 t	          j        | j                  }t          j        	                    |d                   
                                 t          dt          j        d          S # t          j        $ r, t          dt          j        ddt          j                  cY S w xY w)	NzUser not login.r   Fr   r)   r*   z!Cancel reason delete Successfullyz7Cancel reason doesn't exists, Invalid Cancel reason id )r   r   r   r   r   r   r   r   r   r+   deleter   r.   r,   )r    r!   r"   s      r%   deleteCancelReasonr2   ;   s"   7##G$(9FD`aahmv|  wS  T  T  T  	T	}:gl33L!%%<+=%>>EEGGG+NY_Yk l lmmm) 	} 	} 	}+dou  pK  !L  !L  SX  ag  a|  }  }  }  }  }  }	}s    A,B- -8C('C()django.shortcutsr   rest_frameworkr   django.httpr   django.views.decorators.csrfr   r   authentication.authr   cancel_reasons.modelsr   cancel_reasons.serializerr	   r&   r/   r2    r'   r%   <module>r;      s    # # # # # # ! ! ! ! ! ! $ $ $ $ $ $ 4 4 4 4 4 4  , , , , , , / / / / / / = = = = = =
 I I I& c c c2 
} 
} 
} 
} 
}r'   