
    \yf_%                     8   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
             Zed             Zed             Zed             Zed             Zed             Zed             Zed             Zed             ZdS )    )render)status)JsonResponse)csrf_exemptN)verify_token)TransmissionTypesSerializerVehicleModelsSerializerVehicleTypesSerializer   )TransmissiontypesVehicleModelsVehicleTypesc                 0   t          |           }|d k    r)t          dt          j        ddt          j                  S | j        dk    rqt          j        | j                  }t                      }|d         |_	        |
                                 t          dt          j        ddt          j                  S t          j                                        }t          |d	          }t          |j        t          j        d
dt          j                  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
serializers        @C:\Users\hp\python\driverzz\driverzz-admin-api\vehicles\views.pyvehicleTypesr*      s0   7##G$(;fFbccjox~  yU  V  V  V  	V >V##:gl33L'>>L ,V 4L,MX^Xj k krw  AG  AS  T  T  T  T (/3355L/4HHHJ*/FL^ _ _fktz  uG  H  H  H  H    c                 ~   | j         dk    rt          j        | j                  }|d         rpt          j                            |d                   }|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   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(   s       r)   editVehicleTyper3      s   ~z',// 	_'/33d9K3LLL ,V 4L,NY_Yk l lsx  BH  BT  U  U  U  U(EQWQlmmty  CI  C^  _  _  _  
_ ;??4   	be+377W[__T=R=R7SS3LuMMM
#Z_fN`$a$ahmv|  wI  J  J  J  J, e e e#/KW]Wr$s$sz  IO  Id  e  e  e  e  e  ee  +HTZTo p pw|  FL  Fa  b  b  b  b   !A6E 8F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)	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&   s      r)   deleteVehicleTyper9   8   s"   7##G$(9FD`aahmv|  wS  T  T  T  	T	{:gl33L $$,t*<$==DDFFF+MX^Xj k klll( 	{ 	{ 	{+bms  nI  !J  !J  QV  _e  _z  {  {  {  {  {  {	{    A,B- -8C('C(c                 0   t          |           }|d k    r)t          dt          j        ddt          j                  S | j        dk    rqt          j        | j                  }t                      }|d         |_	        |
                                 t          dt          j        ddt          j                  S t          j                                        }t          |d	          }t          |j        t          j        d
dt          j                  S )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(   s        r)   vehicleModelsr>   F   s0   7##G$(;fFbccjox~  yU  V  V  V  	V >V##:gl33L)OOM!-f!5M   ,NY_Yk l lsx  BH  BT  U  U  U  U *15577M0TJJJJ:?VM_ ` `glu{  vH  I  I  I  Ir+   c                 ~   | j         dk    rt          j        | j                  }|d         rpt          j                            |d                   }|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   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(   s       r)   editVehicleModelrA   Y   s   ~z',// 	c)155<;M5NNM!-f!5M   ,OZ`Zl m mty  CI  CU  V  V  V  V+IU[Up q qx}  GM  Gb  c  c  c  c ;??4   	dh - 5 9 9w{t?T?T 9 U U4]OOO
#Z_fN`$a$agltz  uG  H  H  H  H - h h h#0NX^Xt$u$u  }B  KQ  Kg  h  h  h  h  h  hh !,JV\Vq!r!ry~  HN  Hc  d  d  d  dr4   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)	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   s      r)   deleteVehicleModelrC   q   s   7##G$(9FD`aahmv|  wS  T  T  T  	T	c:gl33L!%%<+=%>>EEGGG+NY_Yk l lmmm) 	c 	c 	c+IU[Up q qx}  GM  Gb  c  c  c  c  c  c	cr:   c                 "   t          |           }|d k    r)t          dt          j        ddt          j                  S t          j                                        }t          |d          }t          |j        t          j	        dd          S )	Nr6   r   Fr   Tr   )transmission_typesr   )r   )
r   r   r   r   r   r!   r"   r   r#   r    )r$   r%   transmission_typer(   s       r)   transmissionTypesrG      s    7##G$(9FD`aahmv|  wS  T  T  T  	T-599;;01BNNN
:?VM_``glmmmmr+   c                 ~   | j         dk    rt          j        | j                  }|d         rpt          j                            |d                   }|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   r-   r.   r   z&Transmission  Type Edited successfullyr   Fr   z! Transmission type id is requiredr   )rF   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&   rF   r(   s       r)   editTransmissionTyperI      s.   ~z',// 	h 1 9 = =<PTCU = V V%1&%9"""$$$,T_e_q r ry~  HN  HZ  [  [  [  [+NZ`Zu v v  ~C  LR  Lg  h  h  h  h ;??4   	hi#4#<#@#@gkooVZF[F[#@#\#\ 78IPUVVVz"
RXRd#e#elq  {A  {M  N  N  N  N$1 i i i#0Q[a[v$w$w  D  MS  Mh  i  i  i  i  i  ii  +NZ`Zu v v  ~C  LR  Lg  h  h  h  hr4   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dt          j                  S # t          j        $ r, t          dt          j        ddt          j                  cY S w xY 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   s      r)   deleteTransmissionTyperL      s4   W%%G$(<vGcddkpy  zV  W  W  W  	W	e:gl33L$((L,>(??FFHHH+S]c]o p pw|  FL  FX  Y  Y  Y  Y - 	e 	e 	e+MW]Wr s sz  IO  Id  e  e  e  e  e  e	es    A9B: :8C54C5)django.shortcutsr   rest_frameworkr   django.httpr   django.views.decorators.csrfr   r   authentication.authr   vehicles.serializersr   r	   r
   modelsr   r   r   r*   r3   r9   r>   rA   rC   rG   rI   rL    r+   r)   <module>rU      s   # # # # # # ! ! ! ! ! ! $ $ $ $ $ $ 4 4 4 4 4 4  , , , , , , m m m m m m m m m m B B B B B B B B B B H H H$ b b b0 
{ 
{ 
{ I I I$ d d d. 
c 
c 
c n n n h h h. 
e 
e 
e 
e 
er+   