U
    m2a`                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZ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mZ d d	lmZ d
dlmZ d dlmZ d dlmZ edd Zedd Zedd Zedd Zdd Zdd Zdd Z dS )    N)urlparse)renderredirect)Token)login_required)settings)View)TemplateView)	Paginator   )NewCustomerOperationForm)OperationCustomer)OperationCutomerFilterc                 C   s   t | di S )Nz
index.html)r   request r   ,/var/www/html/iltdigicom/adminpanel/views.pyindex   s    r   c                 C   s\   t | j tjjdd}t| j|d}t|jd}| jdd}|	|}t
| d||dS )	NE)state)queryset   pager   bulksms/operations.html)page_objfilter)printGETr   objectsr   r   r
   qsgetget_pager   )r   ZallcustomeroperationsZcustomeroperation_filtered_list	paginatorpage_numberr   r   r   r   customersoperations    s    

r$   c                 C   s  | j dkrtd| jdd  td| jd  td| j d}| jD ]<}|dksF|dkr\qF|dkrl|d }|| d | j|  }qFtd| | jdd }| jdd }|d k	rtjd	 | }|dkr|d | }nH|d k	rtj| }|dkr|d
 | }n tjd }|dkr|d
 | }td| tjj	| j
d\}}ddd|j d}tj||d}	t|	j}
td|
 t|
d }t|jdkrt|jdkr|jd
 |j }n8t|jdkr|j}n t|jdkrd
|j }nd}t|
d }t|jdkr&t|jdkr&|jd
 |j }n8t|jdkr>|j}n t|jdkrZd
|j }nd}t| j}|
d |||
d |d}t| d|S d S )Nr   pQUERY_STRING r   &=zquery string = z%/api/bulksms/customeroperations?page=?z/api/bulksms/customeroperationszurl = userapplication/jsonToken zContent-TypeAcceptAuthorization)headerszdata = nextr   previousresultscount)
operationsr3   r4   r6   r   r   )methodr   r   r    METAr   APIHOSTr   r   get_or_creater,   keyrequestsjsonloadscontentr   lenpathqueryr   r   )r   query_stringparamZ	page_pathr   urltoken_request_headersrespdataparsedZ	next_pathZ	prev_pathZopfiltercontextr   r   r   r7   :   st    






  
r7   c           
      C   s   | j dkrt| j}| r|j}i }|d |d< |d |d< |d dkrX|d |d< n|d dkrp|d |d< t|d	 |d	< |d
 |d
< tjj| j	d\}}t
jd }ddd|j d}tj|||d}t|j}	tdS nt }t| dd|iS )NPOSToperationcustomer_nameoperationcustomer_typeCZoperationcustomer_valueoperationcustomer_creditDoperationcustomer_debitoperationcustomer_datecustomerr+   z"/api/bulksms/newcustomeroperationsr-   r.   r/   )r>   r2   zadminpanel:ctransactionszbulksms/newoperation.htmlform)r8   r   rN   is_validcleaned_datastrr   r   r;   r,   r   r:   r<   r=   postr>   r?   r@   r   r   )
r   ZmyformZ	form_dataoperationcustomerrG   rH   rF   rI   rJ   rK   r   r   r   newoperation   s0    



r]   c                 C   s   | j dkrt| di S d S NrN   r'   r8   r   r   r   r   r   editoperation   s    
r`   c                 C   s   | j dkrt| di S d S r^   r_   r   r   r   r   disableoperation   s    
ra   c                 C   s   | j dkrt| di S d S r^   r_   r   r   r   r   enableoperation   s    
rb   )!osr>   r=   urllib.parser   django.shortcutsr   r   rest_framework.authtoken.modelsr   django.contrib.auth.decoratorsr   django.confr   Zdjango.viewsr   django.views.generic.baser	   django.core.paginatorr
   formsr   Zbulksms.modelsr   bulksms.api.filtersr   r   r$   r7   r]   r`   ra   rb   r   r   r   r   <module>   s0   


S
