
    urihI                        d dl 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  ee
d       G d de             Z ee
d       G d de             Z ee
d       G d de             Zy)    N)JsonResponse)render)status)method_decorator)csrf_exempt)View)verify_token)User_Vehicles   )VehiclesSerializerdispatch)namec                       e Zd Zd Zd Zy)Vehiclesc                 D   t        |      }|d k(  r-t        dt        j                  ddt        j                        S t        j
                  j                  |      }t        |d      }t        |j                  t        j                  ddt        j                        S )	NUser not login.messager   Fsafer   user_idT)many)vehiclesr   )
r	   r   r   HTTP_401_UNAUTHORIZEDr
   objectsfilterr   dataHTTP_200_OK)selfrequestr   r   
serializers        S/mnt/ACDE16A4DE16673C/PROJECTS/DRIVERZZ/DRIVERZZ_DRIVER_APIS/user_vehicles/views.pygetzVehicles.get   s    w'd?+<vGcGc dkpy  zV  zV  W  W$,,33g3FH+H4@JZ__HZHZ [bgpv  qC  qC  D  D    c                    t        |      }|d k(  r-t        dt        j                  ddt        j                        S t	        j
                  |j                        }t               }||_        |d   |_	        |d   |_
        |d   |_        |d   |_        |d	   |_        |d
   |_        |d   |_        |d   |_        |j#                          t        dt        j$                  ddt        j$                        S )Nr   r   Fr   vehicle_modelvehicle_model_namevehicle_typevehicle_type_nametransmission_typetransmission_type_namevehicle_name
vehicle_nozVehicle added successfully.)r	   r   r   r   jsonloadsbodyr
   r   vehicle_model_idr(   vehicle_type_idr*   transmission_type_idr,   r-   r.   saver   r    r!   r   request_datavehicles        r#   postzVehicles.post   s   w'd?+<vGcGc dkpy  zV  zV  W  W::gll3L#oG%GO'3O'DG$)56J)KG&&2>&BG#(45H(IG%+78K+LG(-9:R-SG*#/#?G !-l!;GLLN,IU[UgUg hot  ~D  ~P  ~P  Q  Qr%   N)__name__
__module____qualname__r$   r9    r%   r#   r   r      s    DQr%   r   c                       e Zd Zd Zy)VehicleDeletec                 
   t        |      }|d k(  r-t        dt        j                  ddt        j                        S 	 t	        j
                  |j                        }t        j                  j                  ||d         }|j                          t        dt        j                  ddt        j                        S # t        j                  $ r0 t        dt        j                  ddt        j                        cY S w xY w)	Nr   r   Fr   idr   rA   zVehicle deleted successfully.-Something went wrong. Please try again later.)r	   r   r   r   r/   r0   r1   r
   r   r$   deleter   DoesNotExistHTTP_400_BAD_REQUESTr6   s        r#   r9   zVehicleDelete.post0   s   w'd?,=HdHd elq  {A  {W  {W  X  Xy#zz',,7'//33gLY]L^3_ #0O[a[m[m$nuz  DJ  DV  DV  W  W -- y#0_kq  lG  lG  %H  OT  ]c  ]x  ]x  y  yys   A?B? ?A DDNr:   r;   r<   r9   r=   r%   r#   r?   r?   .   s    yr%   r?   c                       e Zd Zd Zy)VehicleDefaultc                 x   t        |      }|d k(  r-t        dt        j                  ddt        j                        S t        j
                  j                  |      j                  d       	 t        j                  |j                        }t        j
                  j                  ||d   	      }d
|_        |j                          t        dt        j                  ddt        j                        S # t        j                  $ r0 t        dt        j                   ddt        j                         cY S w xY w)Nr   r   Fr   r   r   )
is_defaultrA   rB   r   z,Vehicle set as default vehicle successfully.rC   )r	   r   r   r   r
   r   r   updater/   r0   r1   r$   rK   r5   r   rE   rF   r6   s        r#   r9   zVehicleDefault.postA   sM   w'd?,=HdHd elq  {A  {W  {W  X  X!!(((9@@a@Py#zz',,7'//33G,W[J\3]%&"#0^jpj|j|$}  EJ  SY  Se  Se  f  f -- y#0_kq  lG  lG  %H  OT  ]c  ]x  ]x  y  yys   /BC6 6A D98D9NrG   r=   r%   r#   rI   rI   ?   s    yr%   rI   )r/   django.httpr   django.shortcutsr   rest_frameworkr   django.utils.decoratorsr   django.views.decorators.csrfr   django.viewsr   authentication.authr	   user_vehicles.modelsr
   serializersr   r   r?   rI   r=   r%   r#   <module>rV      s     $ # ! 4 4  , . + +J/Qt Q 0Q@ +J/yD y 0y  +J/yT y 0yr%   