o
    eOj@                  
   @   s   d dl 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
mZ d dlmZ e ZdZeddd
edededefddZdS )    N)	APIRouterRequest)selectfuncdesc)render)AsyncSessionFactory)AdminAction       requestpageactionadmin_idc                    sV  |d t  }t 4 I d H |}tt}|r|tj|k}|r5z|tjt|k}W n	 ty4   Y nw |	tt
 | I d H }| }|	|ttjt |I d H }	t|	  }
|	ttj tjI d H }dd | D }W d   I d H  n1 I d H sw   Y  t| d|
|||rt|t  nd|||d	S )Nr   c                 S   s   g | ]}|d  qS )r    ).0rowr   r   @/var/www/www-root/data/www/ai-bot.pdev.uz/admin/routers/audit.py
<listcomp>'   s    zaudit_log.<locals>.<listcomp>zaudit/index.html)actionstotalr   total_pagesaction_typescurrent_actioncurrent_admin)PER_PAGEr   r   r	   whereaction_typeadmin_telegram_idint
ValueErrorexecuter   countselect_fromsubquery
scalar_oneorder_byr   
created_atlimitoffsetlistscalarsalldistinctr   mathceil)r   r   r   r   r*   sessionbasetotal_rr   	actions_rr   types_rr   r   r   r   	audit_log   s>   "

(r6   )r   r   r   )r/   fastapir   r   
sqlalchemyr   r   r   admin.responsesr   bot.database.connectionr   bot.database.modelsr	   routerr   getr    strr6   r   r   r   r   <module>   s    "