
    0iD                         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ZddlmZ d	 Ze
d
             Ze
d             Ze
d             Zd ZdS )    )renderget_object_or_404)JsonResponse)FileSystemStorage)settings)require_POSTN   )	Tiqueterac                 d    t           j                                        }t          | dd|i          S )Nzgestion_tq.html
tiqueteras)r
   objectsallr   )requestr   s     2/var/www/html/Desarrollo/vibra/gestion_tq/views.pygestion_tq_homer   
   s.    "&&((J',|Z.HIII    c                    t          t          |          }| j                            d|j                  |_        | j                            d|j                  |_        | j                            d          pd |_        | j                            d|j                  |_        | j                            d          pd |_        | j                            d          pd |_	        | j                            d|j
                  |_
        d	| j        v r|j        rct          j                            t           j        d
|j                  }t          j                            |          rt          j        |           | j        d	         }t)          t          j                            t           j        d
                    }|                    |j        |          }||_        |                                 t/          dd|j        |j        |j        |j        |j        |j        |j        |j	        |j
        |j        r
d|j         ndd
d          S )Npknombredetallefecha_limitetipoantiguedad_minantiguedad_maxcondicionesimagentqlocationTz Tiquet actualizado correctamente
/media/tq/ 
idr   r   r   r   rutar   r   r   	full_rutasuccessmessagedata)r   r
   POSTgetr   r   r   r   r   r   r   FILESr%   ospathjoinr   
MEDIA_ROOTexistsremover   savenamer   r$   )r   r   	tiqueteraold_image_pathimagefsfilenames          r   update_tiqueterar;      s   !)333I |'')2BCCI((I4EFFI$\--n==EI\%%fin==IN&|//0@AAITI&|//0@AAITI#L,,]I<QRRI 7=  > 	*W\\(*=tY^TTNw~~n-- *	.)))h'X5H$(O(OPPP775:u--!	NN5,& (%2NN'6'6$0:C.P6in666b
 
    r   c                    t                      }| j                            dd          |_        | j                            dd          |_        | j                            d          pd |_        | j                            dd          |_        | j                            d          pd |_        | j                            d          pd |_        | j                            d	d          |_	        d
| j
        v rg| j
        d
         }t          t          j                            t          j        d                    }|                    |j        |          }||_        |                                 t)          dd|j        |j        |j        |j        |j        |j        |j        |j        |j	        |j        r
d|j         ndd
d          S )Nr   r"   r   r   r   r   r   r   r   r   r   r   TzTiquet creado correctamenter!   r#   r'   )r
   r+   r,   r   r   r   r   r   r   r   r-   r   r.   r/   r0   r   r1   r4   r5   r%   r   r$   )r   r6   r8   r9   r:   s        r   create_tiqueterar=   ;   s    I |''"55I((B77I$\--n==EI\%%fa00IN&|//0@AAITI&|//0@AAITI#L,,]B??I 7=  h'X5H$(O(OPPP775:u--!	NN0,& (%2NN'6'6$0:C.P6in666b
 
    r   c                 N   t          t          |          }|j        rct          j                            t          j        d|j                  }t          j                            |          rt          j	        |           |
                                 t          ddd          S )Nr   r   TzTiquet eliminado correctamente)r(   r)   )r   r
   r%   r.   r/   r0   r   r1   r2   r3   deleter   )r   r   r6   
image_paths       r   delete_tiqueterarA   c   s    !)333I ~ "W\\("5tY^LL
7>>*%% 	"Ij!!!3    r   c                    dd l }ddlm}  |d          }d|d<   |                    d                    d                     |                    |          }|                    g d	           t          j        	                                }|D ]_}d
}|j
        dk    rd}n|j
        dk    rd}|                    |j        |j        |j        |j        ||j        |j        |j        g           `|S )Nr   )HttpResponseztext/csv; charset=utf-8)content_typez%attachment; filename="tiqueteras.csv"zContent-Dispositionu   ﻿utf8)IDNombreDetalleu   Fecha LímiteTipou   Antigüedad Minu   Antigüedad MaxCondicionesGeneralr	   Especial   u   Comodín)csvdjango.httprC   writeencodewriterwriterowr
   r   r   r   r$   r   r   r   r   r   r   )r   rN   rC   responserR   r   ttipo_displays           r   export_tiqueteras_csvrW   t   s"   JJJ((((((|)BCCCH&MH"# NN9##F++,,,ZZ!!F
OO}}}~~~ "&&((J   6Q;;%LLVq[[%LDHINM	
 		 		 		 		 Or   )django.shortcutsr   r   rO   r   django.core.files.storager   django.confr   django.views.decorators.httpr   r.   modelsr
   r   r;   r=   rA   rW    r   r   <module>r^      s    6 6 6 6 6 6 6 6 $ $ $ $ $ $ 7 7 7 7 7 7             5 5 5 5 5 5 				      J J J * * *X % % %N    " " " " "r   