o
    ρf*                     @   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mZ dd	lmZ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   )Daytimes	RateListsAdditionalChargesTaxes)AdditionalChargesSerializerDayTimesSerializerRateListsSerailizerTaxesSerializerc                 C   s   t | }|d krtdtjddtjdS | jdkrgt| j}g }|d D ]/}|d D ](}t }|d |_	|d	 |_
|d
 |_|d |_|d |_|d |_|| q+q%tj| 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 not logged in.messager   Fsafer   POSTratespricesuniform_typestation_type	trip_typedayminutespricezRateList added successfullyTmany)	ratelistsr   )r   r   r   HTTP_401_UNAUTHORIZEDmethodjsonloadsbodyr	   r   r   r   r   durationrateappendobjectsbulk_createHTTP_200_OKallr   data)requestuser_idrequest_data	bulk_listr'   r   	rate_list
serializer r4   N/media/darth/New Volume E/PROJECTS/DRIVERZZ/DRIVERZZ_ADMIN_APIS/rates/views.py	rateLists   s,   







r6   c                 C   sD  | j dkrZt| j}|d rNtjj|d d}t|d |_|d |_	t|d |_
t|d |_t|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   idr7   r   r&   r   r   r   r'   zRateList edited Succesfullyr   Fr   zRatelist id is required.r   zRateList doesn't exist)r"   r#   r$   r%   r	   r)   getintr   r&   r   r   r   r'   saver   r   r+   HTTP_400_BAD_REQUESTGETr   r-   DoesNotExist)r.   r0   r'   r2   r3   r4   r4   r5   editRateList+   s,   


r?   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dtjdW S  tjyH   tdtjddtjd Y S w )	NUser not login.r   Fr   r7   r8   zRate deleted Succesfullyz,Ratelist doesn't exists. Invalid ratelist id)r   r   r   r!   r#   r$   r%   r	   r)   r9   deleter+   r>   r<   r.   r/   r0   r4   r4   r5   deleteRateListH      rD   c                 C   s   t | }|d krtdtjddtjdS | jdkr<t| j}t }|d |_	|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 )Nr   r   Fr   r   titler   z$Additional Charges added SuccesfullyTr   )additional_chargesr   )r   r   r   r!   r"   r#   r$   r%   r
   rF   r   r;   r+   r)   r,   r   r-   )r.   r/   r0   additional_charger3   r4   r4   r5   additionalChargesW      



rI   c                 C   s   t | }|d krtdtjddtjdS | jdkr<t| j}t }|d |_	|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   Fr   r   rF   tax_percentagezTax added successfullyr   Tr   )taxesr   )r   r   r   r!   r"   r#   r$   r%   r   rF   rN   r;   r+   r)   r,   r   r-   r.   r/   r0   taxr3   r4   r4   r5   rO   k   rJ   rO   c                 C   s4  t | }|d krtdtjddtjdS | jdkrRt| j}|d rFtj	j
|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 )NrK   rL   Fr   r   r7   r8   rF   rN   zTax edited successfullyr   Tax id is requiredr   )rQ   r   zTax doesn't existzTax id is required.)r   r   r   r!   r"   r#   r$   r%   r   r)   r9   rF   rN   r;   r+   r<   r=   r   r-   r>   rP   r4   r4   r5   editTax   s*   


rS   c                 C   r@   )	NrA   r   Fr   r7   r8   zTax deleted successfullyrR   )r   r   r   r!   r#   r$   r%   r   r)   r9   rB   r+   r>   r<   rC   r4   r4   r5   	deleteTax   rE   rT   c                 C   sX   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tj	dS )NrA   r   Fr   Tr   )dayTimesr   )
r   r   r   r!   r   r)   r,   r   r-   r+   )r.   r/   dayTimer3   r4   r4   r5   rU      s   
rU   c                 C   sB  t | }|d krtdtjddtjdS | jdkrYt| j}|d rMtj	j
|d d}t|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 )NrK   r   Fr   r   r7   r8   day_type
start_timeend_timez"DayType & Time edited successfullyzDay & Time id is required r   )day_timer   zDay&Time doesn't existzDay&Time id is required.)r   r   r   r!   r"   r#   r$   r%   r   r)   r9   r:   rW   rX   rY   r;   r+   r<   r=   r   r-   r>   )r.   r/   r0   rZ   r3   r4   r4   r5   editDayTime   s,   


r[   )django.shortcutsr   rest_frameworkr   django.httpr   django.views.decorators.csrfr   r#   authentication.authr   modelsr   r	   r
   r   r3   r   r   r   r   r6   r?   rD   rI   rO   rS   rT   rU   r[   r4   r4   r4   r5   <module>   s4    







