o
    Rf$                     @   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mZmZ dd	lmZmZmZ ed
d Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zedd ZdS )    )render)status)JsonResponse)csrf_exemptN)verify_token)TransmissionTypesSerializerVehicleModelsSerializerVehicleTypesSerializer   )TransmissionTypesVehicleModelsVehicleTypesc                 C      t | }|d krtdtjddtjdS | jdkr7t| j}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 )NUser is not loginmessager   Fsafer   POSTnamezVehicle type added successfullyTmany)vehicle_typesr   )r   r   r   HTTP_401_UNAUTHORIZEDmethodjsonloadsbodyr   r   saveHTTP_200_OKobjectsallr	   data)requestuser_idrequest_datavehicle_type
serializer r(   Q/media/darth/New Volume E/PROJECTS/DRIVERZZ/DRIVERZZ_ADMIN_APIS/vehicles/views.pyvehicleTypes      


r*   c                 C     | j dkr9t| j}|d r-tjj|d d}|d |_|  t	dt
jddt
jdS t	d	t
jddt
jdS | jdruztjj| jdd}t|dd
}t	|jt
jddt
jdW S  tjyt   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   z Vehicle type Edited successfullyr   Fr   zVehicle type id is requiredr   )r&   r   zVehicle type doesn't exist)r   r   r   r   r   r    getr   r   r   r   r   HTTP_400_BAD_REQUESTGETr	   r"   DoesNotExist)r#   r%   r&   r'   r(   r(   r)   editVehicleType   "   

r3   c                 C      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 )	NUser not login.r   Fr   r-   r.   z Vehicle Type delete Successfullyz5VehicleTypes doesn't exists, Invalid VehicleTypes id )r   r   r   r   r   r   r   r   r    r/   deleter   r2   r0   r#   r$   r%   r(   r(   r)   deleteVehicleType8      r9   c                 C   r   )Nr   r   Fr   r   r   z Vehicle model added successfullyTr   )vehicle_modelsr   )r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r   r"   )r#   r$   r%   vehicle_modelr'   r(   r(   r)   vehicleModelsF   r+   r=   c                 C   s  | j dkr9t| j}|d r-tjj|d d}|d |_|  t	dt
jddt
jdS t	d	t
jddt
jdS | jdruztjj| jdd}t|dd
}t	|jt
jddt
jdW S  tjyt   t	dt
jddt
jd Y S w t	d	t
jddt
jdS )Nr   r-   r.   r   z!Vehicle model Edited successfullyr   Fr   Vehicle model id is requiredr   )r<   r   z Vehicle model doesn't exist)r   r   r   r   r   r    r/   r   r   r   r   r   r0   r1   r   r"   r2   r   )r#   r%   r<   r'   r(   r(   r)   editVehicleModelY   r4   r?   c                 C   r5   )	Nr6   r   Fr   r-   r.   z!Vehicle Model delete Successfullyr>   )r   r   r   r   r   r   r   r   r    r/   r7   r   r2   r0   r8   r(   r(   r)   deleteVehicleModelq   r:   r@   c                 C   sT   t | }|d krtdtjddtjdS tj }t|dd}t|jtj	dddS )	Nr6   r   Fr   Tr   )transmission_typesr   )r   )
r   r   r   r   r   r    r!   r   r"   r   )r#   r$   transmission_typer'   r(   r(   r)   transmissionTypes   s   
rC   c                 C   r,   )Nr   r-   r.   r   z&Transmission  Type Edited successfullyr   Fr   z! Transmission type id is requiredr   )rB   r   zTransmission type doesn't exist)r   r   r   r   r   r    r/   r   r   r   r   r   r0   r1   r   r"   r2   )r#   r%   rB   r'   r(   r(   r)   editTransmissionType   r4   rD   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dtjdW S  tjyH   tdtjddtjd Y S w )	Nzuser is not login.r   Fr   r-   r.   z&Transmission type deleted successfullyz Transmission type doesn't exist.)r   r   r   r   r   r   r   r   objectr/   r7   r   r2   r0   r8   r(   r(   r)   deleteTransmissionType   s   rF   )django.shortcutsr   rest_frameworkr   django.httpr   django.views.decorators.csrfr   r   authentication.authr   vehicles.serializersr   r   r	   modelsr   r   r   r*   r3   r9   r=   r?   r@   rC   rD   rF   r(   r(   r(   r)   <module>   s4    






	
