o
    Mf(                     @   s   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	d
 Zedd Zedd ZdS )    )render)status)JsonResponse)csrf_exemptN)verify_token)CancelReasons)CancelReasonsSerializerc                 C   s   t | }|d krtdtjddtjdS | jdkr>t| j}t }|d |_	t
|d |_|  tdtjddtjdS tj }t|d	d
}t|jtjddtjd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
serializer r#   W/media/darth/New Volume E/PROJECTS/DRIVERZZ/DRIVERZZ_ADMIN_APIS/cancel_reasons/views.pycancelReasons   s   


r%   c                 C   s  | j dkr@t| j}|d r4tjj|d d}|d |_t|d |_	|
  tdtjddtjd	S td
tjddtjd	S | jdr|ztjj| jdd}t|dd}t|jtjddtjd	W S  tjy{   tdtjddtjd	 Y S w tdtjddtjd	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"   r#   r#   r$   editCancelReason!   s$   

r,   c                 C   s   t | }|d krtdtjddtjdS zt| j}tjj	|d d
  tdtjdW S  tjyD   tdtjddtjd Y S 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    r#   r#   r$   deleteCancelReason;   s   r.   )django.shortcutsr   rest_frameworkr   django.httpr   django.views.decorators.csrfr   r   authentication.authr   cancel_reasons.modelsr   cancel_reasons.serializerr   r%   r,   r.   r#   r#   r#   r$   <module>   s    

