a
    Z3dw                    @   s  d dl mZ d dlmZ d dlmZ d dlT d dlZd dlmZ d dl	T d dl
mZ ddlT d dlT d dlT d dlZd d	lmZmZmZ d d
lmZ d dl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  d dl!m"Z" d dl#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+ dd Z,dd Z-G dd deZ.G dd deZ/G dd deZ0G dd  d eZ1G d!d" d"eZ2G d#d$ d$eZ3G d%d& d&eZ4G d'd( d(eZ5G d)d* d*eZ6G d+d, d,eZ7G d-d. d.eZ8G d/d0 d0eZ9G d1d2 d2eZ:G d3d4 d4eZ;G d5d6 d6eZ<G d7d8 d8eZ=G d9d: d:eZ>G d;d< d<eZ?G d=d> d>eZ@G d?d@ d@eZAG dAdB dBeZBG dCdD dDeZCG dEdF dFeZDG dGdH dHeZEG dIdJ dJeZFG dKdL dLeZGG dMdN dNeZHG dOdP dPeZIG dQdR dReZJG dSdT dTeZKG dUdV dVeZLG dWdX dXeZMG dYdZ dZeZNG d[d\ d\eZOG d]d^ d^eZPG d_d` d`eZQG dadb dbeZRG dcdd ddeZSG dedf dfeZTG dgdh dheZUG didj djeZVG dkdl dleZWG dmdn dneZXG dodp dpeZYG dqdr dreZZG dsdt dteZ[G dudv dveZ\G dwdx dxeZ]G dydz dzeZ^G d{d| d|eZ_G d}d~ d~eZ`G dd deZaG dd deZbG dd deZcG dd deZdG dd deZeG dd deZfG dd deZgG dd deZhG dd deZiG dd deZjG dd deZkG dd deZlG dd deZmG dd deZnG dd deZoG dd deZpG dd deZqdS )    )APIView)Responsestatus)*N)datetime)settings   )	PaginatorPageNotAnInteger	EmptyPage)Q)date)	timesince)mail)render_to_string)BytesIO)pisa)HttpResponse)get_template)Context)timezonec              	   C   s  g }i }d}d}d}t jj| d }|sBd|d< d|d< t|S tjj|dd}|D ]}	|jr&|	jj|jjkr&td	 |j	d
krt
|jd }
t
|	jt
|
 }t
|	jt
| }|t|	jt||j	t||jd nBt
|	jt
|j }|j}|t|	jt||j	t||jd |jrV|	jjj|jjkrV|j	d
krt
|jd }
|t
|	j7 }|t
|
 }|t
| }t|t||j	t||jdg}qV|t
|	j7 }|t
|j }|j}t|t||j	t||jdg}qV||d< d|d< d|d< |S )Nr   idi  status_codezInvalid coupon codestatus_messageFcustomerisPaidsecond
Percentaged   amountBeforeCouponamountAfterCoupondiscountTypediscount	coupon_iddata   Coupon data)StoreCouponsobjectsfilterfirstr   Cartproductr   printcoupon_typefloatcoupon_discounttotalAmountappendstr	coupon_onstorestore_id)r'   customer_idallDataresponsediscountedAmount
tempAmounttotal_ammountcouponObjectcartObjcartpercent rE   +/var/www/html/Beni/beni/panel_apis/views.pycouponapply    sv    




rG   c           	      C   s  g }i }t jj| d }|s4ttjddtjdS tjj|d }|jr
|j	j
j|jjkr
|jdkrt|jd }t|jt| }t|jt| }|t|jt||jt||jd nBt|jt|j }|j}|t|jt||jt||jd |jd	kr|jj|jjkr|jdkrt|jd }t|jt| }t|jt| }|t|jt||jt||jd nBt|jt|j }|j}|t|jt||jt||jd ||d
< d|d< d|d< |S )Nr   Invalid coupon idr   r   r   service_request_idr    r!   r"   Servicer(   r)   r   r*   r   )r+   r,   r-   r.   r   r   HTTP_400_BAD_REQUESTServiceInvoicer0   rK   	serviceIdr   servicer2   r3   r4   total_amountr6   r7   r8   r9   r:   )	r'   
invoice_idr<   r=   rA   
invoiceObjrD   r>   r?   rE   rE   rF   servicecouponapply_   sd    


rT   c                   @   s   e Zd Zdd ZdS )getContentPagesc                 C   s   |j d }|jd }|s.ttjddtjdS tjj|dd }|r|dkr~tjj|dd }|r|j	|j
|j|jd	}n.tjj|dd }|r|j|j|j|jd	}ttjd
|dS ttjddtjdS d S )NlanguagetypezPlease pass the typerI   r   T)	page_typer   ar)Z
page_titlecontentrX   r   Successr   r   r(   No data found)headersquery_paramsr   r   rM   ContentPagesr,   r-   r.   arabic_page_titlearabic_contentrX   english_page_titleenglish_contentHTTP_200_OK)selfrequestrV   rW   data_objr<   rE   rE   rF   get   s.    

zgetContentPages.getN__name__
__module____qualname__ri   rE   rE   rE   rF   rU      s   rU   c                   @   s   e Zd Zdd ZdS )HelpSupportUserc              
   C   s   |j d}|s&ttjddtjdS ztjj|d}W n: tyr } z"ttjddtjdW  Y d }~S d }~0 0 t	|j
d}| r|j
d}|j
d	}tjj|||jd
 ttjdddS t|jtjdS d S )NHTTP_AUTHORIZATIONzsession_token is requiredrI   r   tokenInvalid session tokenr(   titledescription)rt   ru   user_idz Help & Support Send Successfully r\   )METAri   r   r   rM   Userr,   	ExceptionHTTP_401_UNAUTHORIZEDZHelpAndSupportSerializerr(   is_validHelpSupportcreater   re   errors)rf   rg   session_tokenuser_obje
serializerrt   ru   rE   rE   rF   post   s    ,zHelpSupportUser.postNrk   rl   rm   r   rE   rE   rE   rF   rn      s   rn   c                   @   s   e Zd Zdd ZdS )getFaqc                 C   s   |j d }|dkrRtjjddd}|rg }|D ]}|j|jd}|| q2n>tjjddd}|rg }|D ]}|j|j	d}|| qrt
tjd|dS )	NrV   rY   r	   r   -id)rt   rZ   zFetched FAQ Successfullyr\   )r^   Faqr,   r-   order_byarabic_titlerb   r6   english_titlerd   r   r   re   )rf   rg   rV   rh   r<   Zdata_faqallrE   rE   rF   ri      s&    
z
getFaq.getNrj   rE   rE   rE   rF   r      s   r   c                   @   s   e Zd Zdd ZdS )getContactDetailsc              
   C   s   |j d }tj  }|r|dkrP|j|j|j|j|j	|j
|j|j|jd	}n*|j|j|j|j|j	|j
|j|j|jd	}ttjd|dS ttjddtjdS d S )	NrV   rY   )	whatsapp_numberphone_numberru   emailinstagram_urlfacebook_urltwitter_urlyoutube_urladdressr[   r\   r]   rI   r   )r^   Contactmanager,   r   r.   r   r   contact_description_arr   r   r   r   r   r   contact_descriptionr   r   re   rM   )rf   rg   rV   rh   r<   rE   rE   rF   ri      s4    
zgetContactDetails.getNrj   rE   rE   rE   rF   r      s   r   c                   @   s   e Zd Zdd ZdS )getCategoriesc                 C   sn   |j d }|dkr8tjjdddd}t|ddj}n$tjjdddd}t|ddj}tt	j
d|d	S )
NrV   rY   Tr	   end_date__isnullr   r   )manyr[   r\   )r^   MainCategoriesr,   r-   r   ZGetCategoriesDataArabicr(   ZGetCategoriesDataEnglishr   r   re   )rf   rg   rV   main_objZget_catrE   rE   rF   ri      s    
zgetCategories.getNrj   rE   rE   rE   rF   r      s   r   c                   @   s   e Zd Zdd ZdS )	getStonesc                 C   s  |j d}|r tjj|d}nd}|jd }tjjddd}|dkrzg }|D ](}|j|j|j	|j
|jd	}|| qNn2g }|D ](}|j|j|j	|j|jd	}|| qtjjdddt d
}	g }
|dkrV|	D ]|}tjj|j|d }|rd}nd}||j|j|jj|jj|j|jj|j|j|jt|j |j!|j"j#|j$d}|
| qn|	D ]}tjj|j|d }|rd}nd}||j|j%|jj&|jj&|j'|jj(|j|j|jt|j |j!|j"j)|j"j*|j$d}|
| qZt+jjddddd,dd d }|dkrHg }|D ].}|j|j#|j-|j.|j/|j)d}|| qn8g }|D ].}|j|j*|j-|j0|j/|j)d}|| qPt1tj2d||
|dS )Nro   rp   r   rV   Tr	   r   rY   )r   Z
stone_name
stone_iconZstone_descriptionr   is_offer_appliedr   r   today_deal_start_date
product_iduserFis_favouriter   product_namemaincategorysubcategoryru   brandpriceratingsprice_discountimagesr:   
store_nameoffer_discountr   r   r   r   r   ru   r   r   r   r   r   r:   is_vipr   r   falser   is_profile_completedr   r   z-ratings   r:   r   
store_iconstore_descriptionstore_ratingsr   r[   )r   r   r(   	todayDatabest_seller)3rx   ri   ry   r,   r^   Stonesr-   r   stone_name_arabicr   stone_content_arabicr   r6   stone_name_englishstone_content_englishProductsr   today
Favouritesr.   product_name_arabicr   category_name_arabicr   description_arabicr   brand_name_arabicr   ratingr   astliteral_evalr   r:   r9   store_name_arabicr   product_name_englishcategory_name_englishdescription_englishbrand_name_englishr   store_name_englishStoresr   
store_logostore_description_arabicr   store_description_englishr   re   )rf   rg   r   r   rV   
stones_objall_datair(   product_objr   r0   favourite_obj	favouritealldata	store_objr   rE   rE   rF   ri     s    



"
zgetStones.getNrj   rE   rE   rE   rF   r     s   r   c                   @   s   e Zd Zdd ZdS )	getBrandsc                 C   s   |j d }tjjddd}|dkrRg }|D ]$}|j|j|j|jd}|| q*n.g }|D ]$}|j	|j|j
|jd}|| qZttjd|dS )	NrV   Tr	   r   rY   )
brand_name
brand_iconZbrand_descriptionr   r[   r\   )r^   Brandsr,   r-   r   r   brand_content_arabicr   r6   r   brand_content_englishr   re   )rf   rg   rV   
brands_objr   r   r(   rE   rE   rF   ri   y  s(    
zgetBrands.getNrj   rE   rE   rE   rF   r   x  s   r   c                   @   s   e Zd Zdd ZdS )getServicesc                 C   s   |j d }|dkrVtjjddd}g }|D ](}|j|j|j|j|jd}|	| q*nBtjjddd}g }|D ](}|j|j
|j|j|jd}|	| qnttjd|dS )	NrV   rY   Tr	   r   )
service_idservice_nameservice_iconservice_contentr   r[   r\   )r^   Servicesr,   r-   r   arabic_service_namer   arabic_service_contentr   r6   english_service_nameenglish_service_contentr   re   )rf   rg   rV   service_objr   r   r(   rE   rE   rF   ri     s.    
zgetServices.getNrj   rE   rE   rE   rF   r     s   r   c                   @   s   e Zd Zdd ZdS )storeRequestsc                 C   s  zDt |jd}| r
tjj|jddd }|rRtt	j
ddt	j
dW S tjj|jddd }|rtt	j
d	dt	j
dW S tjj|jd
|jd|jd|jd|jd|jd|jd|jd|jdd	}|jd}|stt	j
ddt	j
dW S |jdr\t|jd}ttjd | }t||_|  td|jd
|jd|jd|jd|jd|jd|jd|jd|jdd	}d}	|}
tj}d}tj|	|
||g|d tjjdd tt	jddW S |j}i }| D ]\}}|} q2qtt	j
|dW S W nH ty } z.t| tt	jt|dt	jdW  Y d }~S d }~0 0 d S )Nrs   r   r   )r   is_superuserz)This email already exist in our database.rI   r   )r   r   z3Your request from this email has been already send.
first_name	last_namer   isd_codemobile_number	id_number	bank_namebank_account_number)	r   r   r   r   r   r   r   r   r   
id_picturezId picture is required/zstore_request_email.htmlzStore Requestadmin123@yopmail.comhtml_messagez+A new store salon request has been received)messagezStore request send successfully)ZStoreRequestSerializerr(   r|   ry   r,   r-   ri   r.   r   r   rM   StoreRequestsr~   ZuploadTheIdpicturer7   r   BASE_URLr   saver   EMAIL_HOST_USERr   	send_mailAdminNotificationsre   r   itemsrz   r1   HTTP_500_INTERNAL_SERVER_ERROR)rf   rg   r   check_emailZcheck_reservereq_objr   fileUrlr   subjectplain_message
from_emailtodefault_errors	new_error
field_namefield_errorsr   rE   rE   rF   r     sZ    










f
zstoreRequests.postNr   rE   rE   rE   rF   r     s   r   c                   @   s   e Zd Zdd ZdS )getAllStoresc                 C   s   |j d }tjjddddd}|dkr^g }|D ],}|j|j|j|j|j|j	d}|
| q.n6g }|D ],}|j|j|j|j|j|j	d}|
| qfttjd|dS )	NrV   Tr   r   rY   r   r[   r\   )r^   r   r,   r-   r   r   r   r   r   r   r6   r   r   r   r   re   )rf   rg   rV   r   r   r   r(   rE   rE   rF   ri     s0    
zgetAllStores.getNrj   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )searchGetCategoriesc                 C   s  |j d }|dkrtjjddd}g }|D ],}|j|j|j|j|j|j	d}|
| q*tjjdd}g }|D ] }|j|j|jd}|
| qntjjddd}	g }
|	D ] }|j|j|jd	}|

| qntjjddd}g }|D ],}|j|j|j|j|j|j	d}|
| qtjjdd}g }|D ]"}|j|j|jd}|
| q,tjjddd}	g }
|	D ]"}|j|j|jd	}|

| qlttjd
|||
dS )NrV   rY   T)r   r   r   )r   )brand_idr   r   r   )category_idcategory_namecategory_iconr[   )r   r   storesbrandsmain_categories)r^   r   r,   r-   r   r   r   r   r   r   r6   r   r   r   r   r   r   r  r   r   r   r   r   r   re   )rf   rg   rV   r   r   r   r(   r   Zall_data_brandsr   Zall_data_mainrE   rE   rF   ri     sr    
zsearchGetCategories.getNrj   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )getStoreDetailsc                 C   sX  |j d}|r tjj|d}nd}|jd }|jd}|jd}|s`ttjddtjd	S |jd
}|sttjddtjd	S |sttjddtjd	S t	jj
|d }|sttjddtjd	S tjj
|dd}	tjj
|dd}
tjj
|dd }t|
|}z||}
W n< ty6   |d}
Y n  tyT   ||j}
Y n0 g }g }|dkrJ|j|j|j|j|j|j|j|jd}|	D ].}|jj|jj|jj|jjd}| | q|
D ]}t!jj
|j|d }|rd}nd}||j|j"|j#j$|j%j$|j&|j'j(|j)|j*|j+t,-|j.|j/|j0|j1jd}| | qn|j|j2|j3|j|j|j|j|jd}|	D ].}|jj|jj4|jj|jj5d}| | qt|
D ]}t!jj
|j|d }|rd}nd}||j|j6|j#j7|j%j7|j8|j'j9|j)|j*|j+t,-|j.|j/|j0|j1jd}| | qttj:d||||rB|nd|jt;|
|d	S )Nro   rp   r   rV   r:   pagePage Number id is requiredrI   r   page_per_dataPage per data id is requiredzStore id is requiredr   No store foundTr9   r   r:   r   r	   rY   )r:   r   r   r   store_bannerr   r   store_numberr   r   r   r   r   F)r   r   r   r   r   ru   r   r   r   r   r   r:   r   r   r[   )	r   r   product_data
store_dataserviceDatar  
page_countper_pagetotal)<rx   ri   ry   r,   r^   r(   r   r   rM   r   r-   r.   storeServicesr   countr
   r  r   r   	num_pagesr   r   r   r   r%  r   r   r&  rO   r   r   r   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r:   r   r9   r   r   r   r   r   r   r   r   re   len)rf   rg   r   r   rV   r:   r  r   r   r   r   total_count	paginatorr<   r*  r)  rP   servicedatar0   r   r   productdatarE   rE   rF   r   O  s    





zgetStoreDetails.postNr   rE   rE   rE   rF   r  N  s   r  c                   @   s   e Zd Zdd ZdS )getCategoryProductsc                 C   s  |j d}|r tjj|d}nd}|jd }|jd}|sTttjddtjdS |jd	}|jd
}|sttjddtjdS |jd}|sttjddtjdS |r|rt	jj
||ddd}	nt	jj
|ddd}	t|	|}
z|
|}	W n< ty   |
d}	Y n  ty0   |
|
j}	Y n0 g }|dkr|	D ]}tjj
|j|d }|rjd}nd}||j|j|jj|jj|j|jj|j|j|jt|j|j |j!j"|j!j#|j$d}|%| qDn|	D ]}tjj
|j|d }|rd}nd}||j|j&|jj'|jj'|j(|jj)|j|j|jt|j|j |j!j"|j!j*|j$d}|%| qttj+d||rn|nd|
jt,|	dS )Nro   rp   r   rV   maincategory_idzMaincategory id is requiredrI   r   subcategory_idr  r  r   r!  T)r7  r8  r   r   )r7  r   r   r	   rY   r   Fr   r   r   r   r   ru   r   r   r   r   r   r:   r   r   r   r[   r   r   r(   r  r+  r,  -rx   ri   ry   r,   r^   r(   r   r   rM   r   r-   r
   r  r   r   r0  r   r   r.   r   r   r   r   r   r   r   r   r   r   r   r   r   r:   r9   r   r   r   r6   r   r   r   r   r   re   r1  )rf   rg   r   r   rV   r7  r8  r  r   r   r3  r<   r0   r   r   r   rE   rE   rF   r     s    




zgetCategoryProducts.postNr   rE   rE   rE   rF   r6    s   r6  c                   @   s   e Zd Zdd ZdS )getStoneProductsc                 C   sb  |j d}|r tjj|d}nd}|jd }|jd}|sTttjddtjdS |jd	}|jd
}|sttjddtjdS |jd}|sttjddtjdS t	jj
|ddd}	t|	|}
z|
|}	W n: ty   |
d}	Y n  ty   |
|
j}	Y n0 g }|dkr|	D ]}tjj
|j|d }|rJd}nd}||j|j|jj|jj|j|jj|j|j|jt|j|j |j!j"|j!j#|j$d}|%| q$n|	D ]}tjj
|j|d }|rd}nd}||j|j&|jj'|jj'|j(|jj)|j|j|jt|j|j |j!j"|j!j*|j$d}|%| qttj+d||rN|nd|
jt,|	dS )Nro   rp   r   rV   stone_idzStone id is requiredrI   r   r8  r  r  r   r!  T)r=  r   r   r	   rY   r   Fr9  r[   r:  r;  )rf   rg   r   r   rV   r=  r8  r  r   r   r3  r<   r0   r   r   r   rE   rE   rF   r   .  s    




zgetStoneProducts.postNr   rE   rE   rE   rF   r<  -  s   r<  c                   @   s   e Zd Zdd ZdS )getProductDetailsc           
      C   s  |j d}|r tjj|d}nd}|jd }|jd}|sTttjddtjdS t	jj
|d	d
 }|sttjddtjdS tjj
|j|d }|rd	}nd}|dkr||j|j|jj|jj|j|jj|j|j|j|j|j|j|jt|j|j|j j!|j j"|j#|j$d}	nd||j|j%|jj&|jj&|j'|jj(|j|j|j|j|j|j|jt|j|j|j j!|j j)|j#|j$d}	ttj*d|	dS )Nro   rp   r   rV   r   zProduct id is requiredrI   r   Tr   r   zProduct not foundr   FrY   )r   r   r   r   r   ru   r   
model_namer   sizeweightcolorr   r   r   r:   r   r   r   quantity)r   r   r   r   r   ru   r   r@  rA  r   rB  rC  r   r   r   r:   r   r   r   rD  r[   r\   )+rx   ri   ry   r,   r^   r(   r   r   rM   r   r-   r.   r   r   r   r   r   r   r   r   r   r@  r   rA  rB  rC  r   r   r   r   r   r:   r9   r   r   r   rD  r   r   r   r   r   re   )
rf   rg   r   r   rV   r   r   r   r   r   rE   rE   rF   r     sv    



zgetProductDetails.postNr   rE   rE   rE   rF   r>    s   r>  c                   @   s   e Zd Zdd ZdS )searchProductc                 C   sj  |j d}|r tjj|d}nd}|jd }|jd}|sTttjddtjdS |jd	}|szttjd
dtjdS |jd}|sttjddtjdS |jd}|rBg }	|dkr|	 D ]&}
|dkr|rt
jjt|
dt|
dB t|
dB t|
dB ddd}n|dkrf|rft
jjt|
dt|
dB t|
dB t|
dB ddd}n4t
jjt|
dt|
dB t|
dB t|
dB dd}t||}z||}W q ty   |d}Y q ty   ||j}Y q0 q|D ]}tjj|j|d }|rd}nd}||j|j|jj|jj|j|jj|j|j|jt !|j"|j#|j$j%|j$j&|j'd}|	(| qn|	 D ](}
|dkr|rt
jjt|
dt|
dB t|
dB t|
dB ddd}n|dkr(|r(t
jjt|
dt|
dB t|
dB t|
dB ddd}n4t
jjt|
dt|
dB t|
dB t|
dB dd}t||}z||}W n< ty   |d}Y n  ty   ||j}Y n0 q|D ]}tjj|j|d }|rd}nd}||j|j)|jj*|jj*|j+|jj,|j|j|jt !|j"|j#|j$j%|j$j-|j'd}|	(| qttj.d |	|rV|nd|jt/|d!S )"Nro   rp   r   rV   searchzSearch field is requiredrI   r   r  r  r   r!  	sort_datarY   highest_price)Zproduct_name_arabic__icontains)Z-maincategory__category_name_arabic__icontains)Z#brand__brand_name_arabic__icontains)Z#store__store_name_arabic__icontainsTz-pricelowest_pricer   r	   r   Fr9  )Zproduct_name_english__icontains)Z.maincategory__category_name_english__icontains)Z$brand__brand_name_english__icontains)Z$store__store_name_english__icontainsr[   r:  )0rx   ri   ry   r,   r^   r(   r   r   rM   splitr   r-   r   r   r
   r  r   r   r0  r   r   r.   r   r   r   r   r   r   r   r   r   r   r   r   r   r:   r9   r   r   r   r6   r   r   r   r   r   re   r1  )rf   rg   r   r   rV   rF  r  r   rG  r<   sr   r3  r0   r   r   r   rE   rE   rF   r     s    

<<4

<<4

zsearchProduct.postNr   rE   rE   rE   rF   rE    s   rE  c                   @   s   e Zd Zdd ZdS )addRemoveFavouritec           	   
   C   s  |j d}|s&ttjddtjdS ztjj|d}W n: tyr } z"ttjddtjdW  Y d }~S d }~0 0 |j	d}|sttjddtjdS t
jj|d	d
 }|sttjddtjdS tjj||dd\}}| s|  ttjddS |  ttjddS d S )Nro   session token is requiredrI   r   rp   rr   r   Product Id is requiredTr?  No product foundr	   )r0   r   r   zRemoved from favourite listzAdded to favourite list.)rx   ri   r   r   rM   ry   r,   rz   r{   r(   r   r-   r.   r   get_or_createdeletere   r  )	rf   rg   r   r   r   r   r   Zfavourite_postcreatedrE   rE   rF   r   =  s&    ,zaddRemoveFavourite.postNr   rE   rE   rE   rF   rL  <  s   rL  c                   @   s   e Zd Zdd ZdS )storeFavouriteListingc           
      C   s  |j d }|jd}|s0ttjddtjdS ztjj|d}W n: ty| } z"ttj	ddtj	dW  Y d }~S d }~0 0 t
jj|jd}g }|d	kr|D ]b}d
|jj|jj|jj|jj|jj|jjt|jj|jj|jjj|jjj|jjd}	||	 qnh|D ]b}|jj|jj|jj|jj|jj|jjt|jj|jj|jjj|jjj|jjd}	||	 q
ttjd|dS )NrV   ro   rM  rI   r   rp   rr   rv   rY   T)r   r   r   ru   r   r   r   r   r:   r   r   r   )r   r   ru   r   r   r   r   r:   r   r   r   zFetched successfullyr\   ) r^   rx   ri   r   r   rM   ry   r,   rz   r{   r   r-   r   r0   r   r   r   r   r   r   r   r   r:   r9   r   r   r   r6   r   r   r   re   )
rf   rg   rV   r   r   r   r   r<   r(  r   rE   rE   rF   ri   T  sR    
,
zstoreFavouriteListing.getNrj   rE   rE   rE   rF   rS  S  s   rS  c                   @   s   e Zd Zdd ZdS )	addToCartc              
   C   s^  z|j d }|jd}|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 t
|jd}| rtjj|jd	d
d }|sttjddtjdW S i }|jd}	|jr|j}
n|j}
t|
t|	 }tjj|j|dd }td| |sJtd tjj||jd}|	|_||_|  tjj|jd }|}tjj|jdd}td| g }|dkr|D ]V}|jjr|jj}n|jj}|jj|jj|jjt|jj |j|d}|!| qnp|D ]j}|jjr$|jj}td| n|jj}td| |jj|jj"|jj#t|jj |j|d}|!| qdd tjj|jddD }dd tjj|jddD }t$|}t$|}d}ttj%d||||d W S |j&}i }|' D ]\}}|} qqttj|dW S W nH tyX } z.t| ttj(t)|dtj(dW  Y d }~S d }~0 0 d S )!NrV   ro   rM  rI   r   rp   rr   rs   r   Tr?  z Invalid product idrD  F)r;   r0   r   cartItemzif cart)r0   r;   )r;   r;   r   cart_objrY   r   product_descriptionr   product_imageproduct_countproduct_amountzif product_amountzelse product_amountr   r   rZ  r[  r\  r]  c                 S   s   g | ]}t |jqS rE   r3   r5   .0ZusercartrE   rE   rF   
<listcomp>      z"addToCart.post.<locals>.<listcomp>c                 S   s   g | ]}t |jqS rE   r_  r`  rE   rE   rF   rb    rc  r   zCart Updatedr   r   r(   the_subtotalrQ   
tax_amount)*r^   rx   ri   r   r   rM   ry   r,   rz   r{   ZAddToCartSerializerr(   r|   r   r-   r.   r   r   r3   r/   r   r1   r~   productCountr5   r  r/  r0   r   r   r   r   r   r6   r   r   sumre   r   r  r  r7   )rf   rg   rV   r   r   r   r   Z
productObjr<   Z
totalcountZselling_priceZtotalamountrV  Z	totalItemZtotalCartItemrX  rC   r]  r   TotalAmountSubtotalfinalSubtotal
finalTotal	taxAmountr  r  r  r  rE   rE   rF   r     s    
.








zaddToCart.postNr   rE   rE   rE   rF   rU    s   rU  c                   @   s   e Zd Zdd ZdS )getCartc              
   C   s   z|j d }|jd}|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 t
jj|jdd	}tj  }g }|d
kr|D ]R}	|	jjr|	jj}
n|	jj}
|	jj|	jj|	jjt|	jj|	j|
d}|| qn\|D ]V}	|	jjr*|	jj}
n|	jj}
|	jj|	jj|	jjt|	jj|	j|
d}|| q|j}dd t
jj|jdd	D }dd t
jj|jdd	D }t|}t|}|}d}ttjd|||||dW S  ty } z&ttjt |dtjdW  Y d }~S d }~0 0 d S )NrV   ro   rM  rI   r   rp   rr   FrW  rY   rY  r^  c                 S   s   g | ]}t |jqS rE   r_  r`  rE   rE   rF   rb  	  rc  zgetCart.get.<locals>.<listcomp>c                 S   s   g | ]}t |jqS rE   r_  r`  rE   rE   rF   rb  
  rc  r   r[   )r   r   r(   re  rQ   rf  	vat_value)!r^   rx   ri   r   r   rM   ry   r,   rz   r{   r/   r-   r   CommissionSectionr   r.   r0   r   r   r   r   r   r   r   rg  r6   r   r   vat_percentagerh  re   r  r7   )rf   rg   rV   r   r   r   rX  ro  r<   rC   r]  r   ri  rj  rk  rl  
last_totalrm  rE   rE   rF   ri     s^    
.



	zgetCart.getNrj   rE   rE   rE   rF   rn    s   rn  c                   @   s   e Zd Zdd ZdS )
removeCartc              
   C   s  z,|j d }|jd}|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 |j
d}|sttjd	dtjdW S tjj|jd
|d}td| |sttjddtjdW S |  tjj|jd
d}g }|dkrn|D ]V}	|	jjr,|	jj}
n|	jj}
|	jj|	jj|	jjt|	jj|	j|
d}|| qn\|D ]V}	|	jjr|	jj}
n|	jj}
|	jj|	jj|	jjt|	jj|	j|
d}|| qrdd tjj|jd
dD }dd tjj|jd
dD }t|}t|}d}ttjd||||dW S  tyz } z2tt| ttjt|dtjdW  Y d }~S d }~0 0 d S )NrV   ro   rM  rI   r   rp   rr   r   rN  F)r;   r   r   rX  zProduct not found in your cartrW  rY   rY  r^  c                 S   s   g | ]}t |jqS rE   r_  r`  rE   rE   rF   rb  H  rc  z#removeCart.post.<locals>.<listcomp>c                 S   s   g | ]}t |jqS rE   r_  r`  rE   rE   rF   rb  I  rc  r   z"Removed successfully from the cartrd  ) r^   rx   ri   r   r   rM   ry   r,   rz   r{   r(   r/   r-   r   r1   rQ  r0   r   r   r   r   r   r   r   rg  r6   r   r   rh  re   r7   r  )rf   rg   rV   r   r   r   r   rX  r<   rC   r]  r   ri  rj  rk  rl  rm  rE   rE   rF   r     sj    
.





zremoveCart.postNr   rE   rE   rE   rF   rs    s   rs  c                   @   s   e Zd Zdd ZdS )checkoutInfoc              
   C   s  z|j d }|jd}|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 t
j  }|jr|j}nd}tjj|jd	d
}dd tjj|jd	d
D }	dd tjj|jd	d
D }
|j}d}d}|d}|rrt||j}|d dkrR|d d d }|d d d }t|}n
t|W S t|	| }d}|}nt|
}d	}|}||||dt|	|d}ttjd|dW S  ty } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )NrV   ro   rM  rI   r   rp   rr           FrW  c                 S   s   g | ]}t |jqS rE   r_  r`  rE   rE   rF   rb  d  rc  z%checkoutInfo.post.<locals>.<listcomp>c                 S   s   g | ]}t |jqS rE   r_  r`  rE   rE   rF   rb  e  rc  rw   r'   r   r)   r(   r   r&   T)rm  isCouponSelectedcoupounDiscountcouponIdZshipping_chargesrk  rl  r[   r\   )r^   rx   ri   r   r   rM   ry   r,   rz   r{   rp  r   r.   rq  r/   r-   r   r(   rG   r3   rh  re   r  r7   )rf   rg   rV   r   r   r   vat_objro  rX  rQ   rj  r(   r>   couponr'   functionResponsediscountOnItemZsubtotal_amountrv  rr  r<   rE   rE   rF   r   S  sX    
.



zcheckoutInfo.postNr   rE   rE   rE   rF   rt  R  s   rt  c                   @   s   e Zd Zdd ZdS )addCustomerCardc              
   C   s  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 |j	d}|sttjddtjdW S t
jj|jd	 }|jst |_|  |jr|j}tjt_tjj||d
}|rtjj|dd }	|	rd}
nd}
tjj|j|d |d |d |d |d |
d}|j|j|j|j|j|j|jd}ttjd|dW S ttjddtjdW S nttjddtjdW S W nH ty  } z.t | ttj!t"|dtj!dW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   card_idzCard Id is requiredrT  )sourceT)r;   	isdefaultFr   	exp_monthexp_yearr   Zlast4)r;   r~  r  r  theCustomerStripe
last_digitr  )cardCustomerID	lastDigitexpMonthexpYearcardIDcardObjectIDr  r[   r\   zOops! Something went wrong)#rx   ri   r   r   rM   ry   r,   rz   r{   r(   Buyerr-   r   r.   stripe_customer_idZcreateCustomerOnStriper  r   STRIPE_SECRET_KEYstripeapi_keyCustomerZcreate_sourceCustomerCardr~   r  r  r  r  r~  r  re   r1   r  r7   )rf   rg   r   r   r   r~  customerObjZ
customerIdZ
createCardZalreadyAdefaultCardPresentZ
theDefaultcardObjr   rE   rE   rF   r     sN    .0
zaddCustomerCard.postNr   rE   rE   rE   rF   r}    s   r}  c                   @   s   e Zd Zdd ZdS )getCardListc           
   
   C   sZ  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }tjj
|jd}g }|D ]X}i }	|j|	d	< |j|	d
< |j|	d< |j|	d< |j|	d< |j|	d< |j|	d< ||	 qttjd|dW S  tyT } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r   r  r  r  r  r  r  r  r[   r\   )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r  r  r  r  r  r~  r  r6   re   r  r7   )
rf   rg   r   r   r   r  ZtheCardsr<   ZcardcontextrE   rE   rF   ri     s0    .






zgetCardList.getNrj   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )
removeCardc           	   
   C   s  zh|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 |j	d}|sttjddtjdW S t
jj|jd }tjj|j|d	 }td
| | sttjddtjdW S |jdkrttjddtjdW S tjt_tjt|jt|}td| |d dkrZ|  ttjddW S  ty } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   r~  rT  r   r~  r  Invalid card IdTz"You can not delete a default card.Z	Card_InfodeletedzCard deleted successfully)rx   ri   r   r   rM   ry   r,   rz   r{   r(   r  r-   r   r.   r  r1   r  r   r  r  r  r  Zdelete_sourcer7   r  rQ  re   r  )	rf   rg   r   r   r   r~  r  r  ZcardInforE   rE   rF   r     s:    .

zremoveCard.postNr   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )setDefaultCardc           	   
   C   st  z,|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 |j	d}|sttjddtjdW S t
jj|jd	 }tjj||d
 }|sttjddtjdW S tjj|dd }|rd|_|  d|_|  ttjddW S  tyn } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   r~  zcard Id is requiredrT  r  r  T)r   r  Fr[   )rx   ri   r   r   rM   ry   r,   rz   r{   r(   r  r-   r   r.   r  r  r  re   r  r7   )	rf   rg   r   r   r   r~  r  r  ZoldDefaultCardrE   rE   rF   r     s0    .zsetDefaultCard.postNr   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )
placeOrderc              
   C   s6  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 |j	d}|sttjddtjdW S t
jj|d	 }tj  }|jr|j}nd
}tjj|jdd }	t|	 d}
d}d}tjj|dd }td| |s6tjj|t d}td ||_|	|_|  td dd tjj|jddD }td| t|}td d}|j	dr6t|j	d|j}|d dkr*|d d d }t|}tjj|j	dd	 }|sttjddtjdW S ||_d|_|| }n
t|W S n
|}d|_|}|}d||_ ||_!||_"||_#|  tjj|jdd}|D ]}|j$|_$|  qi }|%|j$t&|t&tt|dt&tt|dt&|jd  ttj'd!|d"W S  ty0 } z&ttj(t&|dtj(dW  Y d }~S d }~0 0 d S )#Nro   rM  rI   r   rp   rr   
address_idzAddress Id is requiredr   ru  FrW  r   r   orderPackObjects)r   orderIdZsucesssZsucesss1c                 S   s   g | ]}t |jqS rE   r_  r`  rE   rE   rF   rb  :  rc  z#placeOrder.post.<locals>.<listcomp>subTotalAmountZsucesss2r'   r   r)   r(   r&   zInvalid Coupon CodeTz{:.2f}z.2f)r  subTotalrw  Totalrv  r[   r\   ))rx   ri   r   r   rM   ry   r,   rz   r{   r(   	Addressesr-   r.   rp  r   rq  r/   r   r1   	orderPackr~   gernateOrderIddeliveryAddressproductDetailr  rh  rG   r3   r+   rx  rv  formatcouponDiscountr  vatPercentager5   r  updater7   re   r  )rf   rg   r   r   r   r  Z
addressObjry  ro  cartPackObjZtotalDiscountrl  rk  r  r  r  rw  r{  r|  Z	couponObjZfinalGrandTotalrr  ZcartPackObj2r<   rE   rE   rF   r     s    .


zplaceOrder.postNr   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )orderPayc              
   C   s|  z4|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 |j	d}t
d| |sttjddtjdW S tjj|jd	 }t
d
| tjj||d }t
d| tjj|dd }|sttjddtjdW S t|j|j|j}	t
d|	 |	d dkrt
d tjj||t|j|	d d |	d d d}
tjj|dd}t
d| |D ]}|rd|_|  qd|_t }||_|  tjjd|jj j!jdd t"jjddd|d ttj#d|	d d W S t
d! ttj|	d" dW S W n@ tyv } z&ttj$t|dtj$dW  Y d }~S d }~0 0 d S )#Nro   rM  rI   r   rp   rr   r~  zCard ID is requiredrT  z
----------r  zcard-objFr   Invalid orderthePaymentObjr   Tz==2==r(   Zbalance_transactionZreceipt_url)r   r  amounttxnID
recieptUrlcartPackYou got a new order request.r   r:   is_read!Your order is placed successfullyu   تم وضع طلبك بنجاحorder)r   message_arabicnotification_typer   "Payment has been done successfullyr\   z==3==r   )%rx   ri   r   r   rM   ry   r,   rz   r{   r(   r1   r  r-   r   r.   r  r  ZpaymentWithExistingCardr  r~  r5   CustomerTransactionr~   r7   r/   r   r  r   r   	orderDateStoreNotificationsr  r0   r9   CustomerNotificationsre   r  )rf   rg   r   r   r   r~  r  r  orderPackObjr  CustTransactionr  r   rE   rE   rF   r   m  sR    .



,
zorderPay.postNr   rE   rE   rE   rF   r  l  s   r  c                   @   s   e Zd Zdd ZdS )orderPayMoysaarc           
   
   C   s  z||j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }tjj
|dd	 }|sttjd
dtjdW S tjj||t|j|jd|jdd}tjj
|dd	}td| |D ]}|r
d|_|  q
d|_t }	|	|_|  tjjd|jjjjdd tjjdd|d ttjddW S  ty } z&ttj t|dtj dW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  Fr   r  reciept_url
mayosar_idr   r  r  r  	mayosarIDr  Tr  r  r  r  r   r  r   r  )!rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r  r  r~   r7   r5   r(   r/   r1   r   r  r   r   r  r  r  r0   r9   r  re   r  )
rf   rg   r   r   r   r  r  r  r  r   rE   rE   rF   r     s8    .,
zorderPayMoysaar.postNr   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )orderPayWalletc           
   
   C   s  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }tjj
|dd	 }|sttjd
dtjdW S tjj||t|jddd t|jt|j }t	jj
|jdj|d tjjd|t|jdd||jd tjj
|dd	}td| |D ]}|rHd|_|  qHd|_t }	|	|_|  tjjd|jj j!jdd t"jjdd|d ttj#ddW S  ty } z&ttj$t|dtj$dW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  Fr   r  walletr  r   wallet_amountSubtractionOrder PlacedPurchase)rW   buyerr  reasontranscation_typebalanceorder_idr  Tr  r  r  r  r  r  )%rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r  r  r~   r7   r5   r3   r  r  Walletr  r/   r1   r   r  r   r   r  r  r  r0   r9   r  re   r  )
rf   rg   r   r   r   r  r  r  r  r   rE   rE   rF   r     s>    ."
zorderPayWallet.postNr   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )orderPayServicec           
   
   C   s  zZ|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|jd}|sttjd	dtjdW S tjj
|d
d }td| |sttjddtjdW S tjj||t|j|jd|jdd}tjj
d
|djdd}	tjj
|djdd ttjddW S  ty } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  service_invoice_idService invoice Id is requiredFservice_request_id_idis_paidr  zInvalid Service orderr  r  r   servicePackr  r  r  r  rK   Tr  r   payment_statusr  )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r(   rN   r1   CustomerTransactionServicer~   r7   rQ   r  ServiceRequestsre   r  )
rf   rg   r   r   r   r  r  r  r  r  rE   rE   rF   r     s,    .
,zorderPayService.postNr   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )orderPayServiceWalletc              
   C   s  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|jd}|sttjd	dtjdW S tjj
|d
d }td| |sttjddtjdW S tjj||t|jddd}t|jt|j }	t	jj
|jdj|	d tjjd|t|jdd|	|d tjj
d
|djdd}
tjj
|djdd ttjddW S  ty } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r  r  Fr  r  r  r  r  r   r  r  r  r  )rW   r  r  r  r  r  r   r  Tr  r  r  )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r(   rN   r1   r  r~   r7   rQ   r3   r  r  r  r  re   r  )rf   rg   r   r   r   r  r  r  r  r  r  rE   rE   rF   r     s2    .
 zorderPayServiceWallet.postNr   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )cutomerOrderListingc           
   
   C   s  z@|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|ddd	}g }|D ]}tjj
||jdd
 }i }	|j|	d< |j|	d< |j|	d< ||	d< |j|	d< |j|	d< t|j d|	d< t|jjj|	d< |j|	d< ||	 qttjd|dW S  ty } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   Tr   r   r   r  r   ZIdr  r5   Z	orderItemr  delivery_statusPendingZorderStatusZ
orderImageZisRatedr[   r\   )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r/   r  r/  r   r5   r  r  r1   r   r   r  r0   r   is_ratedr6   re   r  r7   )
rf   rg   r   r   r   ZorderListPackr<   ZtheOrder
totalCountr  rE   rE   rF   ri     s6    .






zcutomerOrderListing.getNrj   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )customerOrderDetailc              
   C   s  zJ|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 |j	d}t
d| |sttjddtjdW S tjj||d	d
 }t
d| tjj||d	d
 }t
d| |sttjddtjdW S i }t|jj	|d< |j|d< |j|d< ||d< |j|d< |j|d< |j|d< |j|d< |j|d< d|d< |j|d< |j|d< |jjj|d< tjj||d	d
}	t
d|	 g }
i }|	D ]n}t
d| |jj|jjt !|jj|jj"j|jj"j#d}t$|j}|}|j%|d< t&|d|d< |
'| q||
d }ttj(d!|d"W S  ty } z&ttj)t*|dtj)dW  Y d }~S d }~0 0 d S )#Nro   rM  rI   r   rp   rr   r  zOrder Id is requiredTr  Z	theordersr  zOrder list emptyZ
deliver_toZ
order_dateZorder_itemsZdelivery_chargesZ	sub_totalr-  r  r&   r  Zorder_statusr   ZtaxrC   cartData)r   r   r[  r:   r   r\  z.1frQ   )summaryr  r[   r\   )+rx   ri   r   r   rM   ry   r,   rz   r{   r(   r1   r  r-   r.   r/   r/  ZGetAddressDatar  r  r  shippingCharger  r5   r  r  r  r  r  r0   r   r   r   r   r   r9   r   r3   rg  r  r6   re   r  r7   )rf   rg   r   r   r   r  Z	theOrdersr  ZsummaryDetailr  r<   ZtheSerialObjectrC   ZproductDatar-  r(   rE   rE   rF   r   =  sn    .















zcustomerOrderDetail.postNr   rE   rE   rE   rF   r  <  s   r  c                   @   s   e Zd Zdd ZdS )	getOffersc                 C   s  z|j d}|r$tjj|d}nd}|jd }tjjdddddd	d
 }g }|dkr|D ](}t	d |d |d
 d}|
| qbn&|D ] }|d |d	 d}|
| qtjjdddddd j}	| jjd}
| jjd}| jjd}| jjd}| jjd}t	d| t	d| t	d| t	d| |dkr6t }|rj|t|dtj |r|t||fdtj |
dkrt	d tjj|ddddd}n~|
dkrt	d tjj|ddddd}nP|
dkrt	d tjj|ddddd}n"t	d tjj|ddddd }n|
dkrbt	d! tjjddddd}nx|
dkrt	d" tjjddddd}nL|
dkrt	d# tjjddddd}n t	d$ tjjddddd }| jjd%}|sttjd&d'tjd(W S | jjd)}|s2ttjd*d'tjd(W S t||}z||}W n< tyh   |d}Y n  ty   ||j}Y n0 g }|dkr|D ]}tjj|j|d+ }|rd}nd,}||j|j|jj|j j|j!|j"j#|j$|j|j%t&'|j(|j)|j*j+|j,d-}|
| qn|D ]}tjj|j|d+ }|rHd}nd,}||j|j-|jj.|j j.|j/|j"j0|j$|j%|jt&'|j(|j)|j*j1|j*j2|j,d.}|
| q"ttj3d/||r|nd|jt4|||	d0W S  t5y } z&ttj6t7|d'tj6d(W  Y d }~S d }~0 0 d S )1Nro   rp   r   rV   r	   Tr   r   r   maincategory__id#maincategory__category_name_englishZ"maincategory__category_name_arabicrY   z---------------------------r  r  -price_discountrG  r  price_start	price_endfilter_datayes)r7  )price_discount__rangeZdiscount_percentageZdissssssssssssz-offer_discountrH  ZhigssssssssssssrI  Zlowsssssssssssssssr   Znorrrrrrrrrrrr   zdissssssssssss 2zhigssssssssssss 3zlowsssssssssssssss 4znorrrrrrrrrrr 5r  r  rI   r   r   r!  r   F)r   r   r   r   r   ru   r   r   r   r   r   r:   r   r   r   r[   )r   r   r(   r  r+  r,  main_categoryrH  )8rx   ri   ry   r,   r^   r   r-   valuesdistinctr1   r6   r   r   rg   r_   r   addANDr   r   rM   r
   r  r   r   r0  r   r   r.   r   r   r   r   r   r   r   r   r   r   r   r   r:   r9   r   r   r   r   r   r   r   r   re   r1  rz   r  r7   )rf   rg   r   r   rV   Zproduct_obj_catr  r0   r   rH  rG  r  r  r  r  lookupsr   r  r   r3  r<   r   r   r   rE   rE   rF   ri     s    
 














.zgetOffers.getNrj   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd Zdd ZdS )filterOfferSectionc              
   C   s2  z|j d}|r"tjj|d}nd}|jd }tjjdddddd	 }t	d
| g }|dkr|D ] }|d |d	 d}|
| qhn&|D ] }|d |d	 d}|
| qtjjdddddd j}	t	|	 ttjd||	dW S  ty, }
 z&ttjt|
dtjdW  Y d }
~
S d }
~
0 0 d S )Nro   rp   r   rV   r	   Tr  r  r  r   rY   r  r  r[   )r   r   r(   rH  rI   r   )rx   ri   ry   r,   r^   r   r-   r  r  r1   r6   r   r   r   r   re   rz   r  r7   )rf   rg   r   r   rV   r   r  r0   r   rH  r   rE   rE   rF   ri     s2    

zfilterOfferSection.getc                 C   s  z|j d}|r$tjj|d}nd}|jd }tjjdddd}|jd}|rhtjjddd|d	}|jd
}|jd}|rtjj||fdddd}|r|rtjj||f|dddd}|jd}	|	stt	j
ddt	j
dW S |jd}
|
stt	j
ddt	j
dW S t||
}z||	}W n< tyF   |d}Y n  tyd   ||j}Y n0 g }|dkr|D ]}tjj|j|d }|rd}nd}||j|j|jj|jj|j|jj|j|j|jt|j|j |j!j"|j!j#|j$d}|%| qxn|D ]}tjj|j|d }|r,d}nd}||j|j&|jj'|jj'|j(|jj)|j|j|jt|j|j |j!j"|j!j*|j$d}|%| qtt	j+d||	r|	nd|jt,|dW S  t-y } z&tt	j.t/|dt	j.dW  Y d }~S d }~0 0 d S )Nro   rp   r   rV   r	   Tr  r  )r   r   r   r7  r  r  )r  r   r   r   )r  r7  r   r   r   r  r  rI   r   r   r!  rY   r   Fr   r[   r:  )0rx   ri   ry   r,   r^   r   r-   r(   r   r   rM   r
   r  r   r   r0  r   r   r.   r   r   r   r   r   r   r   r   r   r   r   r   r   r:   r9   r   r   r   r6   r   r   r   r   r   re   r1  rz   r  r7   )rf   rg   r   r   rV   r   r  r  r  r  r   r3  r<   r0   r   r   r   r   rE   rE   rF   r   8  s    




*zfilterOfferSection.postNrk   rl   rm   ri   r   rE   rE   rE   rF   r    s    r  c                   @   s   e Zd Zdd ZdS )getServiceProvidersc           
      C   s  |j d}|r tjj|d}nd}|jd }| jjd}|sVttj	ddtj	dS t
jj|d	d
}|sttj	ddtj	dS g }|dkr|D ]2}|jj|jj|jj|jj|jjd}	||	 qn8|D ]2}|jj|jj|jj|jj|jjd}	||	 qttjd|dS )Nro   rp   r   rV   r   Service Id is requiredrI   r   T)rO   r   r"  rY   )r:   r   r   r   r   )r:   r   r   r   r   r[   r\   )rx   ri   ry   r,   r^   rg   r_   r   r   rM   r.  r-   r9   r   r   r   r   r   r6   r   r   re   )
rf   rg   r   r   rV   r   
stores_objr<   r9   r   rE   rE   rF   ri     s<    
zgetServiceProviders.getNrj   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd Zdd ZdS )stonePolishingRequestc              
   C   sn  z&|j d}|jd }|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 | j
jd}|sttjd	dtjdW S tjj|d
dd}g }|dkr|D ]}	|	j|	jd}
||
 qn$|D ]}	|	j|	jd}
||
  qttjd|dW S  tyh } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rV   rM  rI   r   rp   rr   r:   Store Id is requiredTr	   r:   r   r   rY   r=  
stone_typer[   r\   )rx   ri   r^   r   r   rM   ry   r,   rz   r{   rg   r_   	StoneTyper-   r   stone_type_arabicr6   stone_type_englishre   r  r7   )rf   rg   r   rV   r   r   r:   r   r<   stonesr   rE   rE   rF   ri     s8    
.zstonePolishingRequest.getc              
   C   s  zj|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|jd}|sttjd	dtjdW S |jd
}|sttjddtjdW S |jd}td| |sttjddtjdW S tjj
||ddd }	|jd}
|
sVttjddtjdW S |jd}|sttjddtjdW S |jd}|sttjddtjdW S |jd}|sttjddtjdW S tjj
|d }t  tjj|||||	|
||d}|jdrJt|jd}ttjd | }t||_|  tjjd|dd ttjd dW S  ty } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )!Nro   rM  rI   r   rp   rr   rT  r   r  r:   r  r  ZStttttttttttttttttttttttttttttStone type is requiredTr	   )r   r:   r   r   rA  Size is requiredr  zAmount is requirednoteszNotes is requiredshapezShape is requiredr   )r:   rO   r   r  r  rA  r  r  imager   z0You got a new order request for stone polishing.r  "Service request send successfullly)rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r(   r1   r	  r   r  r~   uploadServiceRequestr7   r   r  r  r  r  re   r  )rf   rg   r   r   r   r  r   r:   r=  r  rA  r  r  r  service_obj_idr   r  rE   rE   rF   r     sX    .

zstonePolishingRequest.postNr   rE   rE   rE   rF   r    s   %r  c                   @   s   e Zd Zdd Zdd ZdS )extractionRequestc                 C   s   d S NrE   rf   rg   rE   rE   rF   ri   	  s    zextractionRequest.getc              
   C   s2  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|jd}|sttjd	dtjdW S |jd
}|sttjddtjdW S |jd}|s
ttjddtjdW S |jd}	|	s4ttjddtjdW S |jd}
|
s^ttjddtjdW S tjj
|d }tjj|||||	|
d}|jdrt|jd}ttjd | }t||_|  tjjd|dd ttjddW S  ty, } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r   r  r:   r  number_of_stonezNumber of stone is requiredweight_of_each_stonezWeight of stone is requiredr  r   )r:   rO   r   number_of_stonesweight_of_stoner  r  r   z3You got a new order request for extraction request.Tr  r  )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r(   r   r  r~   r  r7   r   r  r  r  r  re   r  )rf   rg   r   r   r   r  r   r:   r  r  r  r  r   r  rE   rE   rF   r   	  sF    .
zextractionRequest.postNr   rE   rE   rE   rF   r  	  s   r  c                   @   s   e Zd Zdd Zdd ZdS )accessoriesMaintenanceRequestc              
   C   sn  z&|j d}|jd }|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 | j
jd}|sttjd	dtjdW S tjj|d
d
d}g }|dkr|D ]}	|	j|	jd}
||
 qn$|D ]}	|	j|	jd}
||
  qttjd|dW S  tyh } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rV   rM  rI   r   rp   rr   r:   zStore ID  is requiredTr:   r   r   rY   r   service_typer[   r\   rx   ri   r^   r   r   rM   ry   r,   rz   r{   rg   r_   ServiceTyper-   r   service_type_arabicr6   service_type_englishre   r  r7   rf   rg   r   rV   r   r   r:   Zservice_type_objr<   rP   r   rE   rE   rF   ri   7	  s8    
.z!accessoriesMaintenanceRequest.getc              
   C   s<  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S |jd	}|sttjd
dtjdW S |jd}| sttjddtjdW S |jd}|s(ttjddtjdW S tjj
||ddd }	|jd}
|
sjttjddtjdW S tjj
|d }tjj||||	|
d}|jdrt|jd}ttjd | }t||_|  tjjd|dd ttjddW S  ty6 } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  No customer foundr   r  r:   r  r  Service type is requiredTr   r:   r   r   r  zNote is requiredr   r:   rO   r   r  r  r  r   z9You got a new order request for accessories maintainance.r  r  rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r(   r!  r   r  r~   r  r7   r   r  r  r  r  re   r  )rf   rg   r   r   r   r  r   r:   service_type_idr  r  r  r   r  rE   rE   rF   r   Y	  sF    .
z"accessoriesMaintenanceRequest.postNr   rE   rE   rE   rF   r  6	  s   "r  c                   @   s   e Zd Zdd Zdd ZdS )watchesMaintenanceRequestc              
   C   sn  z&|j d}|jd }|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 | j
jd}|sttjddtjdW S tjj|d	d	d
}g }|dkr|D ]}	|	j|	jd}
||
 qn$|D ]}	|	j|	jd}
||
  qttjd|dW S  tyh } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rV   rM  rI   r   rp   rr   r:   Tr  rY   r  r[   r\   r   r$  rE   rE   rF   ri   	  s8    
.zwatchesMaintenanceRequest.getc              
   C   s<  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S |jd	}|sttjd
dtjdW S |jd}| sttjddtjdW S |jd}|s(ttjddtjdW S tjj
||ddd }	|jd}
|
sjttjddtjdW S tjj
|d }tjj||||	|
d}|jdrt|jd}ttjd | }t||_|  tjjd|dd ttjddW S  ty6 } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r%  r   r  r:   r  r  r&  Tr'  r  r   r(  r  r   z3You got a new order request for watch maintainance.r  r  r)  )rf   rg   r   r   r   r  r   r:   r  r*  r  r  r   r  rE   rE   rF   r   	  sF    .
zwatchesMaintenanceRequest.postNr   rE   rE   rE   rF   r+  ~	  s   !r+  c                   @   s   e Zd Zdd Zdd ZdS )detailingAccessoriesRequestc              
   C   s  z|j d}|jd }|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 | j
jd}|sttjddtjdW S tjj|d	d	d
}|dkr.g }|D ]}	|	j|	jd}
||
 qtjj|d	dd}g }|D ]}|j|jd}
||
 qnbg }|D ]}	|	j|	jd}
||
 q6tjj|d	dd}g }|D ]}|j|jd}
||
 qpttjd||dW S  ty } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rV   rM  rI   r   rp   rr   r:   Tr  rY   )r   service_modelr	   r  r  r[   )r   r   service_dataZ
stone_data)rx   ri   r^   r   r   rM   ry   r,   rz   r{   rg   r_   ServiceModelr-   r   service_model_arabicr6   r	  r
  service_model_englishr  re   r  r7   )rf   rg   r   rV   r   r   r:   r-  r.  rP   r   r   Z	stoneDatar  rE   rE   rF   ri   	  sZ    
.
zdetailingAccessoriesRequest.getc              
   C   s  z`|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S |jd	}|sttjd
dtjdW S |jd}| sttjddtjdW S |jd}|s(ttjddtjdW S tjj
|ddd }|jd}	|	shttjddtjdW S tjj
|	ddd }
|jd}|sttjddtjdW S |jd}|sttjddtjdW S tjj
|d }tjj||||||
|d}|jdr@t|jd}ttjd | }t||_|  tjjd|dd ttjddW S  ty } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r%  r   r  r:   r  r-  zService model is requiredTr	   )r   r   r   r  r  r  r&  rA  r  r   )r:   rO   r   r-  r  r  rA  r  r   z6You got a new order request for detailing accessories.r  r  )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r(   r/  r	  r   r  r~   r  r7   r   r  r  r  r  re   r  )rf   rg   r   r   r   r  r   r:   r-  stone_type_idZstone_type_objr  rA  r  r   r  rE   rE   rF   r   	  sT    .
z detailingAccessoriesRequest.postNr   rE   rE   rE   rF   r,  	  s   5r,  c                   @   s   e Zd Zdd Zdd ZdS )giftArrangementRequestc              
   C   s  z|j d }|jd}|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 | j
jd}|sttjd	dtjdW S tjjd
d
d}g }|dk r|D ]$}	|	j|	j|	j|	jd}
||
 qn,|D ]&}	|	j|	j|	j|	jd}
||
  qtjjd
d
d}g }|dkrr|D ]&}|j|j|j|jd}|| qHn,|D ]&}|j|j|j|jd}|| qvttjd||dW S  ty } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )NrV   ro   rM  rI   r   rp   rr   r:   r  T)r   r   rY   )box_idZbox_name	box_imagebox_cost)packaging_idZpackaging_namepackaging_imagepackaging_costr[   )r   r   ZgiftdataZpackagingdata)r^   rx   ri   r   r   rM   ry   r,   rz   r{   rg   r_   GiftBoxTyper-   r   box_name_arabicr5  r6  r6   box_name_englishGiftPackingTypepackaging_name_arabicr8  r9  packaging_name_englishre   r  r7   )rf   rg   rV   r   r   r   r:   ZgiftobjZgiftDataZgiftr   ZpackagingobjZpackagingDataZpackingZalldata2rE   rE   rF   ri   +
  sb    
.

zgiftArrangementRequest.getc              
   C   sf  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S |jd	}|sttjd
dtjdW S tjj
|d }|jd}|sttjddtjdW S |jd}	|	s:ttjddtjdW S tjj
|	ddd }
|jd}|szttjddtjdW S tjj
|ddd }|jd}|sttjddtjdW S |jd}|sttjddtjdW S tjj||||
|||d tjjd|dd ttjddW S  ty` } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r%  r   r  r   r:   r  box_typezBox type is requiredT)r   r   r   r7  zPackaging ID is requiredgift_sentencezGift sentence is requiredr  znotes is required)rO   r:   r   gift_boxgift_packaginggift_card_sentencer  z/You got a new order request for gift arrangemntr  zRequest send succesfully)rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r(   r   r:  r=  r  r~   r  re   r  r7   )rf   rg   r   r   r   r  r   r  r:   r4  r@  r7  Zpackaging_typerA  r  rE   rE   rF   r   g
  sJ    .zgiftArrangementRequest.postNr   rE   rE   rE   rF   r3  *
  s   <r3  c                   @   s   e Zd Zdd ZdS )serviceAppliedListc                 C   s0  z|j d }|jd}|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 t
jj|jd }|sttjd	dtjdW S tjj|d
d}t| g }|dkr\|D ]t}	|	j r|	j}
nd }
|	jdkrd}n|	jdkr d}nd}|	j|	jj|	jj|	j|
|	j||	j|	jd	}|| qn||D ]v}	|	jrt|	j}
nd }
|	jdkrd}n|	jdkrd}nd}|	j|	jj|	jj|	j|	j|
||	j|	jd	}|| q`ttjd|dW S  ty* } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )NrV   ro   rM  rI   r   rp   rr   rT  r%  r  r   rY   r   r  r	   AcceptedDeclined)	
request_idr   r   request_dater  invoice_generatedr   r  r  )	rH  r   r   rI  rJ  r  r   r  r  r[   r\   ) r^   rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r  r   r1   r  service_statusr9   r   rO   r   
start_daterJ  r  r  r6   r   re   r  r7   )rf   rg   rV   r   r   r   r  r   r<   rP   r  status_infor   rE   rE   rF   ri   
  sv    
.
zserviceAppliedList.getNrj   rE   rE   rE   rF   rE  
  s   rE  c                   @   s   e Zd Zdd ZdS )servicesAppliedDetailsc                 C   sh  z |j d }|jd}|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 t
jj|jd }|sttjd	dtjdW S | jjd
}|sttjddtjdW S tjj||d }|sttjddtjdW S |jr8|dkr.|jj}	n|jj}	nd }	|jrL|j}
nd }
|jr`|j}nd }|jrt|j}nd }|jr|j}nd }|jr|j}nd }|jr|j}nd }|jr|j}nd }|jr|dkr|jj}n|jj}nd }|jr|j}nd }|jr,|dkr"|jj }n|jj!}nd }|j"rV|dkrL|j"j#}n|j"j$}nd }|j%rj|j%}nd }|dkr|j&j'}n|j&j(}|dkr|j)j*}n|j)j+}|j,dkrd}n|j,dkrd}nd}|j|j)j||j&j-|j&j-|j&j.||	|
||||||||||||d}ttj/d|dW S  tyb } z&ttj0t1|dtj0dW  Y d }~S d }~0 0 d S )NrV   ro   rM  rI   r   rp   rr   rT  r%  rK   zService request ID is requiredr   r   zService not foundrY   r   r  r	   rF  rG  )rH  r   r   store_addressrP  Zstore_countryr   r  rA  r  r  r  r  r  r  r  r-  rB  rC  rD  rK  r[   r\   )2r^   rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   rg   r_   r  r  r
  r  rA  r  r  r  r  r  r  r  r"  r#  r-  rB  r;  r<  rC  r>  r?  rD  r9   r   r   rO   r   r   rK  r   countryre   r  r7   )rf   rg   rV   r   r   r   r  rK   rP   r  rA  r  r  r  r  r  r  r  r-  rB  rC  rD  r   Zservice_name_apporM  r   rE   rE   rF   ri   
  s    
.















zservicesAppliedDetails.getNrj   rE   rE   rE   rF   rN  
  s   rN  c                   @   s   e Zd Zdd ZdS )marketingRequestc              
   C   s,  z|j d}|r$tjj|d}nd}|jd }|jd}|sZttjddtjdW S |jd	}|sttjd
dtjdW S |jd}|sttjddtjdW S |jd}|sttjddtjdW S |jd}	|	sttjddtjdW S |jd}
|
s$ttjddtjdW S |jd}|sNttjddtjdW S |jd}|sxttjddtjdW S t	jj
|||||	|
||d}|jdrt|jd}ttjd | }t||_|  ttjddW S  ty& } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rp   r   rV   r   zProduct name is requiredrI   r   prduct_descriptionzProduct description is requiredr]  zProduct amount is requiredproduct_pricezProduct price is required
owner_namezOwner name is requiredr   zMobile number is requiredr   zAddress is requiredr   Email is required)r   rS  r]  rT  rU  r   r   r   r  r   r[   )rx   ri   ry   r,   r^   r(   r   r   rM   MarketingRequestr~   r  r7   r   r  r  r  re   rz   r  )rf   rg   r   r   rV   r   rS  r]  rT  rU  r   r   r   Zmark_objr  r   rE   rE   rF   r   p  sN    

zmarketingRequest.postNr   rE   rE   rE   rF   rR  o  s   rR  c                   @   s   e Zd Zdd ZdS )getCustomerNotificationsc              
   C   s  zZ|j d }|jd}|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 t
jj|jd }|sttjd	dtjdW S tjj|jd
d}g }|dkr|D ]0}	|	j|	j|	jt|	jd |	jd}
||
 qn8|D ]2}	|	j|	j|	jt|	jd |	jd}
||
 qttjd|dW S  ty } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )NrV   ro   rM  rI   r   rp   rr   rT  r%  r  r   rY   z ago)r   r   r  rL  r  r[   r\   )r^   rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r  r   r  r  r   rL  r  r6   r   re   r  r7   )rf   rg   rV   r   r   r   r  
notify_objr<   notifyr   rE   rE   rF   ri     sD    
.
zgetCustomerNotifications.getNrj   rE   rE   rE   rF   rX    s   rX  c                   @   s   e Zd Zdd ZdS )clearCustomerNotificationsc           
   
   C   sZ  z|j d }|jd}|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 t
jj|jd }|sttjd	dtjdW S | jjd
}|rtjj|j|d  n$tjj|jd}|D ]}	|	   qttjddW S  tyT } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )NrV   ro   rM  rI   r   rp   rr   rT  r%  notification_idrO  r  r[   )r^   rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   rg   r_   r  rQ  re   r  r7   
rf   rg   rV   r   r   r   r  r\  rY  rZ  rE   rE   rF   ri     s*    
.zclearCustomerNotifications.getNrj   rE   rE   rE   rF   r[    s   r[  c                   @   s   e Zd Zdd ZdS )readCustomerNotificationsc           
   
   C   sn  z&|j d }|jd}|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 t
jj|jd }|sttjd	dtjdW S | jjd
}tjj|jd}| rtjj|j|djdd n"|D ]}	td d|	_|	   qttjddW S  tyh } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )NrV   ro   rM  rI   r   rp   rr   rT  r%  r\  r  rO  T)r  z----------------sssssssr[   )r^   rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   rg   r_   r  r  r1   r  r  re   r  r7   r]  rE   rE   rF   ri     s.    
.zreadCustomerNotifications.getNrj   rE   rE   rE   rF   r^    s   r^  c                   @   s   e Zd Zdd ZdS )getVipStoresc                 C   sd  |j d}|r tjj|d}nd}|jd }tjjdd }|sZtt	j
ddt	j
d	S tjj|jd
d}tjj|jd
d}g }g }	|dkrn|j|j|j|j|j|j|j|jd}
|D ],}|jj|jj|jj|jjd}|	| q|D ]~}tjj|j|d }|rd
}nd}||j|j|jj|jj|j|j j!|j"|j#|j$t%&|j'|j(|j)j|j*d}|| qn|j|j|j+|j,|j|j|j|jd}
|D ].}|jj|jj-|jj|jj.d}|	| q|D ]}tjj|j|d }|rd
}nd}||j|j/|jj0|jj0|j1|j j2|j"|j#|j$t%&|j'|j(|j)j|j*d}|| qtt	j3d||
|	dS )Nro   rp   r   rV   true)r   r"  rI   r   Tr#  r$  rY   )r:   r   r   r   r%  r   r   r&  r'  r   F)r   r   r   r   r   ru   r   r   r   r   r   r:   r   r   )r:   r   r   r   r   r%  r   r&  r[   )r   r   r(  r)  r*  )4rx   ri   ry   r,   r^   r   r-   r.   r   r   rM   r.  r   r   r   r   r   r%  r   r   r&  rO   r   r   r   r6   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r:   r9   r   r   r   r   r   r   r   r   r   re   )rf   rg   r   r   rV   r   r   r   r<   r*  r)  rP   r4  r0   r   r   r5  rE   rE   rF   ri     s    



zgetVipStores.getNrj   rE   rE   rE   rF   r_    s   r_  c                   @   s   e Zd Zdd ZdS )bestSellerStoresc                 C   s   d S r  rE   r  rE   rE   rF   ri   s  s    zbestSellerStores.getNrj   rE   rE   rE   rF   ra  r  s   ra  c                   @   s   e Zd Zdd ZdS )getTodayDealsc                 C   s  z|j d}|r$tjj|d}nd}|jd }tjjdddt d}|sft	t
jdd	t
jd
W S g }|dkr|D ]|}tjj|j|d }|rd}	nd}	|	|j|j|jj|jj|j|jj|j|j|jt|j|j|jj|jd}
| |
 qvn|D ]}tjj|j|d }|r d}	nd}	|	|j|j!|jj"|jj"|j#|jj$|j|j|jt|j|j|jj%|jj&|jd}
| |
 qt	t
j'd|dW S  t(y } z&t	t
j)t*|d	t
j)d
W  Y d }~S d }~0 0 d S )Nro   rp   r   rV   r	   Tr   rO  rI   r   rY   r   Fr   r   r[   r\   )+rx   ri   ry   r,   r^   r   r-   r   r   r   r   rM   r   r   r.   r   r   r   r   r   r   r   r   r   r   r   r   r   r:   r9   r   r   r6   r   r   r   r   r   r   re   rz   r  r7   )rf   rg   r   r   rV   r   r<   r0   r   r   r   r   rE   rE   rF   ri   w  sr    


zgetTodayDeals.getNrj   rE   rE   rE   rF   rb  v  s   rb  c                   @   s   e Zd Zdd ZdS )sendRatingReviewc              
   C   s@  z|j d }|jd}|s6ttjddtjdW S ztjj|d}W n< ty } z$ttj	ddtj	dW  Y d }~W S d }~0 0 t
jj|jd }|sttjd	dtjdW S |j}td
| |jd }td| |D ]}|d }	|d }
|d }|d }|d }td| tjj|djdd tjj|d }tjj|d }tjjt|	|
|||d d}tjj|d}tjj|d }|D ]}|t|j7 }qt|| }tjj|djt|d tjj|djt|d qttjddW S  ty: } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )NrV   ro   rM  rI   r   rp   rr   rT  r%  zdata---Zrating_review_data
data_arrayr   reviewr:   r   r  )r  T)r  r   )r   re  r0   r  r9   r   )r0   )r   )r   zRating send successfully)r^   rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   bodyr1   r(   r  r  r   r   RatingReviewsr~   intr/  r   roundre   r  r7   )rf   rg   rV   r   r   r   r  r(   rd  r   re  r:   r   r  Zproduct_obj_idZstore_obj_idr-  Zsum_objr/  rK  Zfinal_ratingrE   rE   rF   r     sL    
.




zsendRatingReview.postNr   rE   rE   rE   rF   rc    s   rc  c                   @   s   e Zd Zdd ZdS )getChatRoomListc                 C   sn  z&|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S |j}tjj
|d	d
}g }|D ]F}	|	j}
tjj
|
jd }||
j|j|j|j|	j|	j|	jd qttjd|dW S  tyh } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r%  r   -last_message_time)r   r:   nameZpicturelast_message_textlast_message_timer  successr\   )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r(   	chat_roomr   r9   r   r6   r   r   rn  ro  r  re   r  r7   )rf   rg   r   r   r   r  r(   roomsr<   roomchatuserZStoreObjrE   rE   rF   ri     s*    .*zgetChatRoomList.getNrj   rE   rE   rE   rF   rj    s   rj  c                   @   s   e Zd Zdd ZdS )readMessagec              
   C   s&  z|j d}|s*ttjddtjdW S ztjj|d}W n< tyx } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S tjj
|d	d
 }d|_|  ttjddW S  ty  } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r%  rk  rl  r   rp  )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   rq  r   r  r  re   r  r7   )rf   rg   r   r   r   r  rr  rE   rE   rF   r      s"    .zreadMessage.postNr   rE   rE   rE   rF   ru    s   ru  c                   @   s   e Zd Zdd ZdS )getMessagesListc              
   C   s  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S |j}|d	}|sttjd
dtjdW S tjj|d}tjj|jd}	tjj
||	ddtjj
|	|ddB }
g }|
D ]^}|j|kr@d}nd}|jdkrl||j||j|jd n||j||j|jd q*ttjd|dW S  ty } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r%  r:   Store_id is requiredr   )sender_userreceiver_userz-created_atTFtext)r   senderr   rW   rp  r\   )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r_   r   rv   Messager   rx  rW   r6   r   
created_atr  re   r  r7   )rf   rg   r   r   r   r  r(   r:   storeObjrt  messagesr<   r   r{  rE   rE   rF   ri     s:    .
,zgetMessagesList.getNrj   rE   rE   rE   rF   rv    s   rv  c                   @   s   e Zd Zdd ZdS )
addMessagec              
   C   sF  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S |j}|d	}|sttjd
dtjdW S |d}|s ttjddtjdW S tjj|d}	tjj|	jd}
|d}tjj
||
d}|sNtjj||
d |stjj||
|dd tjj||
d}||_t |_|  n^t|}ttjd | }t|}tjj||
|dd tjj||
d}d |_t |_|  ttjddW S  ty@ } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r%  r:   rw  r   zmessage is requiredr   r  r   r9   rz  )rx  ry  r   rW   r   )rx  ry  r  rW   rp  )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r(   r   rv   rq  r~   r|  rn  r   nowro  r  ZuploadThemessagepicturer7   r   r  re   r  )rf   rg   r   r   r   r  r(   r:   r   r~  rt  r  ZchatRoomcrr  Z	image_urlrE   rE   rF   r   ;  sR    .





zaddMessage.postNr   rE   rE   rE   rF   r  :  s   r  c                   @   s   e Zd Zdd ZdS )startChatroomc              
   C   sL  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S |j}|d	}|sttjd
dtjdW S tjj|d}tjj||d ttjddW S  tyF } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r%  r:   rw  r   r  rp  )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r(   rq  rP  re   r  r7   )rf   rg   r   r   r   r  r(   r:   rE   rE   rF   r   n  s(    .
zstartChatroom.postNr   rE   rE   rE   rF   r  m  s   r  c                   @   s   e Zd Zdd ZdS )contactUsAdminc           
      C   s   |j d}|j d}|j d}|s>ttjddtjdS |sXttjddtjdS |srttjddtjdS td	|||d
}d}|}tj}d}	tj	||||	g|d ttj
ddS )N	full_namer   r   zFull name is requiredrI   r   rV  zMessage is requiredzcontact_us.html)r  r   r   z
Contact Usr   r   rp  )r(   ri   r   r   rM   r   r   r  r   r  re   )
rf   rg   r  r   r   r   r  r  r  r  rE   rE   rF   r     s    zcontactUsAdmin.postNr   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )getCouponListc                 C   s(  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S |j}|jd	 }t }tjj
|d
}	tjj
|jdd}
d}g }|dkr|	D ]}|jr4|
D ](}|jj|jjkr,d} q4nd}q
|jdkrp|
D ]*}|jjj|jjkrhd} qpnd}qD|jr|
D ]*}|jjj|jjkrd} qnd}q||j|j|j|j|jd|j|j|jj|d
}||  qn|	D ]}|jr"|
D ](}|jj|jjkrd} q"nd}q|jdkr^|
D ]*}|jjj|jjkrVd} q^nd}q2|jr|
D ]*}|jjj|jjkrd} qnd}qj|j|j |j|j|jd|j|j|jj|d
}|| qttj!d|dW S  ty" } z&ttj"t#|dtj"dW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r%  rV   )Zcoupon_end_date__gtFr   rw   rY   TZProductYthis coupon is a demo for testing our coupon section please wait until we finish our work
r'   Zcoupon_namer2   r4   r8   Zcoupon_descriptioncoupon_start_datecoupon_end_dater:   Zis_applicabler[   r\   )$rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r_   r^   r   r  r+   r/   rv   r0   r8   r9   r:   category_productr   coupon_name_arabicr2   r4   r  r  r6   coupon_name_englishre   r  r7   )rf   rg   r   r   r   r  r(   rV   Zcurrent_date
couponListrB   isApplicabler<   	allcouponZcarts	allCouponrE   rE   rF   ri     s    .

zgetCouponList.getNrj   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )applyCouponc              
   O   s  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S |j}|d	}	|	sttjd
dtjdW S g }
tjj
|	d }|sttjddtjdW S tjj
|jdd}d}d}d}|D ]}|jr|jj|jjkrtd |jdkrt|jd }t|jt| }t|jt| }|
t|jt||jt|d n>t|jt|j }|j}|
t|jt||jt|d |jr.|jjj|jjkr.|jdkrtt|jd }|t|j7 }|t| }|t| }t|t||jt|dg}
n@|t|j7 }|t|j }|j}t|t||jt|dg}
q.ttjd|
dW S  ty
 } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r%  r   coupon id is requiredr   rH   Fr   r   r   r    r!   r#   r$   r%   r&   r[   r\   )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r(   r+   r/   rv   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   re   r  )rf   rg   argskwargsr   r   r   r  r(   r'   r<   rA   rB   r>   r?   r@   rC   rD   rE   rE   rF   r      s    .



zapplyCoupon.postNr   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )removeCouponc              
   O   s\  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S |j}|d	}	|	sttjd
dtjdW S tjj
|d }
|
 r|
j rd|
_|
  ttjddW S  tyV } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r%  r   r  r  Fr[   )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r(   ZcartPackagerv  r  re   r  r7   )rf   rg   r  r  r   r   r   r  r(   r'   r  rE   rE   rF   r   G  s.    .
zremoveCoupon.postNr   rE   rE   rE   rF   r  F  s   r  c                   @   s   e Zd Zdd ZdS )getInvoicePdfc              
   C   s  z|j d }|s(ttjddtjdW S tjj|d }tjj|j	d }t
jj|jdd}tjj|jd }||||d	}td
}|||||d	}	tdd}
d|
d< tj|	dj|
tdgd |
W S  ty } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )NZpack_idzOrder Pack Id is requiredrI   r   r   T)r  r   )orderPack_id)invoicecustomer_obj
orders_objtrans_idzgetinvoice.htmlzapplication/pdf)content_typezattachment; filename="file.pdf"zContent-Disposition)stringzstatic/store/css/invoice.css)Zstylesheets)r_   r   r   rM   r  r,   r-   r.   r  r;   r/   r  r  r   r   renderr   
weasyprintZHTMLZ	write_pdfZCSSrz   r  r7   )rf   rg   r   r  r  r  r  r(   templatehtmlr=   r   rE   rE   rF   ri   c  s"    

zgetInvoicePdf.getNrj   rE   rE   rE   rF   r  b  s   r  c                   @   s   e Zd Zdd ZdS )buyerWalletTranscationc              
   C   sL  z|j d}|s,ttjddtjdW S ztjj|d}W n6 tyt } zttjddW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S tjj
|jd	}g }|D ],}|j|j|j|j|j|jd
}	||	 q|j}
ttjd||
dW S  tyF } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r%  )r  )r   r  r  rW   r  rL  r[   )r   r   r(   r  )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r  r  r  rW   r  rL  r6   r  re   r  r7   )rf   rg   r   r   r   r  
wallet_objZall_Datar  r   r  rE   rE   rF   ri   x  s4    (
zbuyerWalletTranscation.getNrj   rE   rE   rE   rF   r  w  s   r  c                   @   s   e Zd Zdd ZdS )getInvoiceServicePdfc              
   C   s(  z|j d}|s*ttjddtjdW S ztjj|d}W n6 tyr } zttjddW  Y d }~W S d }~0 0 |j	d }|sttjddtjdW S t
jj|d	 }|jj|j|j|j|j|j|jd
}ttjd|dW S  ty" } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   r   r  rJ   )r   invoice_urlinvoice_numbertotal_before_vat
vat_amountrQ   r  r[   r\   )rx   ri   r   r   rM   ry   r,   rz   r{   r_   rN   r-   r.   rK   r   invoice_pdf_urlr  r  r  rQ   r  re   r  r7   )rf   rg   r   r   r   r   r   r   rE   rE   rF   ri     s.    (
	zgetInvoiceServicePdf.getNrj   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )invoiceServiceCheckoutc                 C   s  zp|j d}|s,ttjddtjdW S ztjj|d}W n6 tyt } zttjddW  Y d }~W S d }~0 0 |j	d}|sttjddtjdW S t
jj|d	 }d
}d}|j	d}	|	r.t|	|}
|
d dkr|
d d d }|
d d d }	t|}n
t|
W S t|j| }d}|	}n
|j}d}|jj|j|j|j|j|||||jd
}ttjd|dW S  ty } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rR   invoice_id is requiredrJ   ru  rw   r'   r   r)   r(   r   r&   TF)
r   r  r  r  r  rQ   rv  rw  rx  r  r[   r\   )rx   ri   r   r   rM   ry   r,   rz   r{   r(   rN   r-   r.   rT   r3   rQ   rK   r   r  r  r  r  r  re   r  r7   )rf   rg   r   r   r   rR   r   r>   rz  r'   r{  r|  rQ   rv  r   rE   rE   rF   r     sR    (


zinvoiceServiceCheckout.postNr   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )getCouponListForServicec                 C   s  zl|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S |j}|jd	 }tj }tjj
|d
d}	td|	 d
}
g }|dkr|D ]}|jr2|	D ]*}|jjj|jjkr*d}
 q2nd
}
q|jdkrl|	D ](}|jj|jjkrdd}
 qlnd
}
qB|j|j|j|j|jd|j|j|jj|
d
}||  qn|D ]}|jr|	D ]*}|jjj|jjkrd}
 qnd
}
q|jdkr"|	D ](}|jj|jjkrd}
 q"nd
}
q|j|j|j|j|jd|j|j|jj|
d
}|| qttj d|dW S  ty } z&ttj!t"|dtj!dW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r%  rV   F)Zservice_request_id__customerr  rS   rY   TrL   r  r  r[   r\   )#rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r_   r^   r+   r   rN   r1   rP   rK   rO   r8   r9   r:   r  r2   r4   r  r  r6   r  re   r  r7   )rf   rg   r   r   r   r  r(   rV   r  rS   r  r<   r  r  r  rE   rE   rF   ri     s    .



zgetCouponListForService.getNrj   rE   rE   rE   rF   r    s   r  c                   @   s   e Zd Zdd ZdS )applyServiceCouponc              
   O   s  z|j d}|s,ttjddtjdW S ztjj|d}W n< tyz } z$ttjddtjdW  Y d }~W S d }~0 0 t	jj
|jd }|sttjddtjdW S |j}|d	}	|	sttjd
dtjdW S |d}
|
s ttjddtjdW S g }tjj
|	d }|s4ttjddtjdW S tjj
|
d }|jr|jjj|jjkr|jdkrt|jd }t|jt| }t|jt| }|t|jt||jt|d n>t|jt|j }|j}|t|jt||jt|d |jdkr|jj|jjkr|jdkrt|jd }t|jt| }t|jt| }|t|jt||jt|d n>t|jt|j }|j}|t|jt||jt|d ttjd|dW S  ty } z&ttjt|dtjdW  Y d }~S d }~0 0 d S )Nro   rM  rI   r   rp   rr   rT  r%  r'   r  rR   r  r   rH   rJ   r    r!   r  rL   r[   r\   )rx   ri   r   r   rM   ry   r,   rz   r{   r  r-   r   r.   r(   r+   rN   r0   rK   rO   rP   r2   r3   r4   rQ   r6   r7   r8   r9   r:   re   r  )rf   rg   r  r  r   r   r   r  r(   r'   rR   r<   rA   rS   rD   r>   r?   rE   rE   rF   r   E  s|    .



zapplyServiceCoupon.postNr   rE   rE   rE   rF   r  D  s   r  )rrest_framework.viewsr   rest_framework.responser   rest_frameworkr   Zauth_apis.modelsrandomr   Zadmin_panel.modelsdjango.confr   r   store_apis.modelsZpanel_apis.functionsr   django.core.paginatorr
   r   r   django.db.modelsr   r  r   jsondjango.utils.timesincer   django.corer   django.template.loaderr   ior   Z	xhtml2pdfr   Zpdfkitr  django.httpr   r   django.templater   django.utilsr   rG   rT   rU   rn   r   r   r   r   r   r   r   r  r  r  r6  r<  r>  rE  rL  rS  rU  rn  rs  rt  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r+  r,  r3  rE  rN  rR  rX  r[  r^  r_  ra  rb  rc  rj  ru  rv  r  r  r  r  r  r  r  r  r  r  r  r  rE   rE   rE   rF   <module>   s   ?2"m9!C \[Fn/X:>93"V."&!D x'V*HGeeK 3(tB,$3hG!3[