
    lXf]                         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	Z	d dl
mZ ddlmZ dd	lmZ d d
lmZ ed             Zd ZdS )    N)render)status)JsonResponse)csrf_exempt)verify_token   )Trips)TripSerializer)Userc                    t          |           }|d k    r/t          ddt          t          j        idt          j                  S | j        dk    r?t          j        | j                  }	 t          j	        
                    |d                   }n# t          j        $ r t                      }|d         |_        d|_        d	|_        d	|_        d
                    d t#          d          D                       }d|z   |_        d|_        |                                 Y nw xY wt+                      }|j        |_        |d         |_        |d         |_        |d         |_        |d         |_        |d         |_        |d         |_        t=          |d                   |_        t=          |d                   |_         |d         |_!        |d         |_"        |d         |_#        |d         |_$        |d         |_%        |d         |_&        |d         |_'        |d         |_(        |d         |_)        |d          |_*        |d!         |_+        |                                 t          d"t          j,        d#dt          j,                  S t*          j	        -                                }t]          |d$%          }t          |j/        t          j,        d&dt          j,                  S )'NmessagezUser not loginFsafer   POSTmobile)r   r   r    c              3   >   K   | ]}t          j        d           V  dS )$1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZN)randomchoice).0is     =C:\Users\hp\python\driverzz\driverzz-admin-api\trips\views.py	<genexpr>ztrips.<locals>.<genexpr>    s.      #l#l^_FM2X$Y$Y#l#l#l#l#l#l       zUSER-   vehicle_model_idvehicle_type_idtransmission_type_idvehicle_model_namevehicle_type_nametransmission_type_name	trip_typestation_typepickup_addresspickup_latitudepickup_longitudedestination_addressdestination_latitudedestination_longitude
start_dateend_date
start_timeend_timeinstructionszTrip Created successfullyr   r   Tmany)tripsr   )0r   r   r   HTTP_401_UNAUTHORIZEDmethodjsonloadsbodyr   objectsgetDoesNotExistr   	is_activeis_staffis_superuserjoinrangeusername	user_typesaver	   iduser_idr   r   r    r!   r"   r#   intr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   HTTP_200_OKallr
   data)requestrF   request_datauserrB   trip
serializers          r   r4   r4      s   7##G$Y)96&B^_fktz  uQ  R  R  R  	R >V##:gl33L|''h1G'HH$ 	 	 	vv*84!" !$%!77#l#lchijckck#l#l#lmm '( 2!"			 77D7DL$01C$DD!#/0A#BD (45K(LD%&23G&HD#%12E%FD"*67O*PD' k!:;;DN #L$@ A AD"./?"@D#/0A#BD $01C$DD!'34I'JD$(45K(LD%)56M)ND&*<8DO(4DM*<8DO(4DM ,^ <DIIKKK,GQWQc d dkpy  zL  M  M  M  M =$$&&D'4888J:?VEW X X^clrl~s   +&B BD%$D%c                    | j         dk    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 t          $ r3}t          d
t          j        d	dt          j                  cY d }~S d }~ww xY w	 t          j        | j                  }t          j                            |t                              }|d         |_        |d         |_        |d         |_        |d         |_        |d         |_        |d         |_        t/          |d                   |_        |d         |_        |d         |_        |d         |_        |d         |_        |d         |_        |d         |_        |d         |_        |d         |_         |d         |_!        |d         |_"        |d         |_#        |$                                 t          dt          j	        d	dt          j	                  S # t          j
        $ r, t          dt          j        d	dt          j                  cY S t          $ r3}t          d
t          j        d	dt          j                  cY d }~S d }~ww xY w)NGETrE   )rE   Fr2   )rN   r   r   zInvalid trip id.r1   z-Something went wrong. Please try again later.r   r   r    r!   r"   r#   r$   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   zTrip Edited successfully)%r6   r	   r:   r;   rQ   r
   r   rJ   r   rH   r<   HTTP_400_BAD_REQUEST	Exceptionr7   r8   r9   rE   r   r   r    r!   r"   r#   rG   r$   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   rD   )rK   rN   rO   erL   s        r   editTriprU   C   s   ~	s=$$'+//$*?*?$@@D'U;;;J&BT U U\ajpj|}}}}! 	V 	V 	V,>Hc d dkpy  zU  V  V  V  V  V  V 	s 	s 	s,[ek  fA  !B  !B  IN  W]  Wr  s  s  s  s  s  s  s  s  s	s	s:gl33L=$$,r*:$;;D$01C$DD!#/0A#BD (45K(LD%&23G&HD#%12E%FD"*67O*PD' k!:;;DN"./?"@D#/0A#BD $01C$DD!'34I'JD$(45K(LD%)56M)ND&*<8DO(4DM*<8DO(4DM ,^ <DIIKKK,FPVPb c cjox~  yK  L  L  L  L! 	V 	V 	V,>Hc d dkpy  zU  V  V  V  V  V  V 	s 	s 	s,[ek  fA  !B  !B  IN  W]  Wr  s  s  s  s  s  s  s  s  s	ssI   A6B 8C:>	C:(C5/C:5C:>E7I6 68K,0	K,9(K'!K,'K,)r   django.shortcutsr   rest_frameworkr   django.httpr   django.views.decorators.csrfr   r7   authentication.authr   modelsr	   serializersr
   authentication.modelsr   r4   rU    r   r   <module>r_      s     # # # # # # ! ! ! ! ! ! $ $ $ $ $ $ 4 4 4 4 4 4  , , , , , ,       ' ' ' ' ' ' & & & & & & 1@ 1@ 1@h&s &s &s &s &sr   