o
    mif                     @   s   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
mZ d dlZd dlmZ d dlmZ d d	lmZmZ d
dlmZmZ edd Zdd Zedd ZdS )    N)render)status)JsonResponse)csrf_exempt)check_passwordmake_password)verify_token)User)DriverPartnerSerializerDriverPartnerListSerializer   )DriverPartnersDriverVehiclesc                    s  t | }|d krtdtjddtjdS | jdkrt| j}t  |d  _	|d  _
|d  _td	 _d
 _d _|d  _ddd tdD }d|  _d _    jrt } j|_t|d |_|d |_|d |_|d |_|d |_|d |_|d |_ t|d |_!t|d |_"t|d |_#t|d |_$|  |d rt%j&' fdd |d D  td!tj(ddtj(dS 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nameemailmobile123456   r   r    c                 s   s    | ]}t d V  qdS )$1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZN)randomchoice).0i r   X/media/darth/New Volume E/PROJECTS/DRIVERZZ/DRIVERZZ_ADMIN_APIS/driver_partners/views.py	<genexpr>!   s    z!driverPartners.<locals>.<genexpr>   zUSER-r   genderlicensce_nodate_of_birth
experiencelocationhouse_numberpincodeuniform_typestation_type	trip_typetransmission_typevehicle_modelsc                    s   g | ]	}t  j|d qS )	driver_idvehicle_model)r   idr   r1   userr   r    
<listcomp>7   s    z"driverPartners.<locals>.<listcomp>z Driver partner added Succesfullyz-Something went wrong. Please try again later.Tmanydriver_partnersr   )-r   r   r   HTTP_401_UNAUTHORIZEDmethodjsonloadsbodyr	   r   r   r   r   password	user_typeis_staff	is_activejoinrangeusernameis_superusersaver2   r   user_idintr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r   objectsbulk_createHTTP_200_OKHTTP_400_BAD_REQUESTallr
   data)requestrI   request_datarF   driver_partner
serializerr   r4   r    driverPartners   sR   













rU   c                 C   s0   t j }t|dd}t|jtjddtjdS )NTr7   r9   Fr   )r   rK   rO   r   r   rP   r   rM   )rQ   rS   rT   r   r   r    driverPartnersListF   s   
rV   c                    s  | j dkrt| j}|d rtjj|d d |d  j_|d  j_	|d  j_
t|d  j_t|d  _|d	  _|d
  _|d  _|d  _|d  _|d  _t|d  _t|d  _t|d  _t|d  _ j     tjj jjd  |d rtj fd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rz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   r2   )r2   r   r   r   r   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   )r0   r.   c                    s   g | ]
}t  jj|d qS r/   )r   r5   r2   r3   rS   r   r    r6   g   s    z%editDriverPartner.<locals>.<listcomp>z!Driver details edited Succesfullyr   Fr   zDriver id is requiredr7   )rS   r   zDriver partner doesn't exists.zDriver partner id is required)&r<   r=   r>   r?   r   rK   getr5   r   r   r   rJ   rC   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   rH   r   filterr2   deleterL   r   r   rM   rN   GETr
   rP   DoesNotExist)rQ   rR   rT   r   rW   r    editDriverPartnerL   sJ   







r]   )r   django.shortcutsr   rest_frameworkr   django.httpr   django.views.decorators.csrfr   django.contrib.auth.hashersr   r   r=   authentication.authr   authentication.modelsr	   driver_partners.serializerr
   r   modelsr   r   rU   rV   r]   r   r   r   r    <module>   s     
5