
    8hD              
       x   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mZ d dl mZmZmZ d d	lmZ d d
lZd d
lZd d
lZd d
lZ eddg      Zej1                  d       ee      fdedefd       Zej1                  d       eej4                         ee      fdedefd       Zej9                  d       ee      fdedefd       Zej=                  d       ee      fdedefd       ZejA                  d       eej4                         ed
       ee      fdedededefd       Z!y
)    )	APIRouterDepends)get_db)Session)	FileClass)DemarcationClass)Patent)DemarcationListDemarcation)
UploadFileFileHTTPException)datetimeNz/demarcationsDemarcations)prefixtags/demarcationdbc                 R    t        |      j                  | j                        }d|iS Nmessage)r   get_allpage)r   r   datas      G/var/www/jisbackend.com/public_html/app/backend/routers/demarcations.pyindexr      s(    B''(8(89Dt    z/store	form_datac           	         d}t        |       D ]  }|j                  d      st        | |      }|s%t        j                         j                  d      }t        j                         j                  d d }t        j                  j                  |j                        d   }d}|r	| d| | n| d| }	|dk(  r#| d|	 }
t        |      j                  ||
      }n|dk(  r#| d|	 }t        |      j                  ||      }n|dk(  r#| d|	 }t        |      j                  ||      }nw|d	k(  r#| d|	 }t        |      j                  ||      }nO|d
k(  r#| d|	 }t        |      j                  ||      }n'|dk(  r"| d|	 }t        |      j                  ||      }|dz  } t        |      j!                  | 
       y )N   file_%Y_%m_%d_%H_%M_%S   r   _               )dir
startswithgetattrr   nowstrftimeuuiduuid4hexospathsplitextfilenamer   uploadr   store)r   r   i	attr_namefile	timestamp	unique_idfile_extensionfile_category_nameunique_filenameremote_path1r   remote_path2remote_path3remote_path4remote_path5remote_path6s                    r   r8   r8      s   
 	
A^ 	(9i0D$LLN334GH	 JJL,,Ra0	!#!1!1$--!@!C%2"P^YKqN;K"Lgpfqqrs|r}d~6&8%9?:K#LL'm224FG!V&8%9?:K#LL'm224FG!V&8%9?:K#LL'm224FG!V&8%9?:K#LL'm224FG!V&8%9?:K#LL'm224FG!V&8%9?:K#LL'm224FGQ;> Ry,lT`bnp|}r   z/delete/{id}idc                 >    t        |      j                  |       }d|iS r   )r   delete)rG   r   r   s      r   rI   rI   B   s"    r"))"-Gwr   z
/edit/{id}c                     	 t        |      j                  |       }|st        dd      d|iS # t        $ r}t        ddt	        |             d }~ww xY w)N  u   Demarcación no encontradastatus_codedetailr     zError al obtener el iva: )r   getr   	Exceptionstr)rG   r   demarcation_dataes       r   editrU   H   sm    Z+B/33B7  C8TUU +,, Z6OPSTUPVx4XYYZs   ,/ 	AAAz/update/{id}supportc                    	 t        |      j                  |       }|st        dd      t        j                  |      }|d   d   }|r| nd }|}|rt        j                         j                  d      }t        j                         j                  d d }	d|j                  v r|j                  j                  d      d	   nd
}
|
r
| d|	 d|
 n| d|	 }| }t        |      j                  ||       |rt        |      j                  |       t        |      j!                  | ||       ddiS # t"        $ r}t        ddt%        |             d }~ww xY w)NrK   zIva no encontradorL   patent_datarV   r#   r$   . r%   r   z Patente actualizada exitosamenterO   zError al actualizar el iva: )PatentClassrP   r   jsonloadsr   r.   r/   r0   r1   r2   r6   splitr   r7   rI   updaterQ   rR   )rG   r   rV   r   rX   previous_file_nameremote_path_previousnew_file_namer<   r=   r>   remote_path_newrT   s                r   r`   r`   X   sq   "]!"o))"-C8KLLjj- )7	B:L"4!5RV* //0CDI

((!,I@CwGWGW@WW--33C8<]_NKYyk9+Q~6FGbkallmnwmx_yM!.O bM  /: $"$$%9: 	Br9m<=>> ]6RSVWXSYRZ4[\\]s   D/D2 2	E;EE)"fastapir   r   app.backend.db.databaser   sqlalchemy.ormr   app.backend.classes.file_classr   %app.backend.classes.demarcation_classr   app.backend.schemasr	   r
   r   r   r   r   r   r0   r]   r3   base64demarcationspostr   as_formr8   rI   intrP   rU   putr`    r   r   <module>rr      s   & * " 4 B & < 3 3    	 
	
 36=fo  G  
 8$[%8%89&/%~%~%~ %~N ^$!(  c  w   % 
 , ' ZS Zg Z  Z .!  /t*&/	(](](] (] 		(] "(]r   