Sindbad~EG File Manager

Current Path : /home/numerotech/hs.numerotech.com/scan_v1/core/model/__pycache__/
Upload File :
Current File : //home/numerotech/hs.numerotech.com/scan_v1/core/model/__pycache__/BadgeUserModel.cpython-39.pyc

a

7��d�F�@s�ddlmZmZmZmZmZmZmZmZddl	m
Z
mZddlm
Z
ddlZee
jddddd�Zee
jd	dddd�ZGd
d�d�ZdS)�)�
create_engine�MetaData�Table�insert�select�update�delete�text)�and_�or_)�appN�DATABASE_URITi)�
pool_pre_ping�pool_recycle�future�DATABASE_URI_FKc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)S)*�BadgeUserModelc
Cs>zt�|_Wn,ty8}zt|�WYd}~n
d}~00dS)N)r�meta�	Exception�print)�self�e�r�Z/home/numerote/conference.numerotech.com/food_kit_scan_badges/core/model/BadgeUserModel.py�__init__szBadgeUserModel.__init__cCs�d}d}t��}|��}|�d||||g�|jr�dd�|jD�}g}	|��D]}
|	�tt||
���qN|�	�|�
�|	r�dSdSn|�	�|�
�dSdS)NZnumerote_primary_dbZnumerote_foodkitZcreate_table_for_confcSsg|]}|d�qS�rr)�.0�columnrrr�
<listcomp>N�z3BadgeUserModel.createConfTables.<locals>.<listcomp>�success)�	engine_fk�raw_connection�cursor�callproc�description�fetchall�append�dict�zip�close�commit)r�conf_id�conf_key�curr_dtZmain_dbZ
foodkit_db�
connectionr#�columns�results�rowrrr�createConfTablesGs$zBadgeUserModel.createConfTablescCspt���T}td|d�}|�|���}|r>|Wd�SWd�dSWd�n1sb0YdS)Nzrselect delegate_no,full_name,email,mobile,role,city,state,membership_no,mc_number,company_name,counter,batch from z	 limit 1;)�engine�connectr	�execute�keys�rr,�del_table_name�conn�stmtr1rrr�getDelegatesTableColumnbs
z&BadgeUserModel.getDelegatesTableColumnc
Cs�g}z�t��}|��}|�d|||||g�dd�|jD�}	g}
|��}|durRqltt|	|��}|
�|�q@|�t	|
��|�
�dur�q�|jdur,q�q,W|��|��n|��|��0|S)NZ!usp_delegates_bulk_upload_previewcSsg|]}|d�qSrr�r�crrrrurzCBadgeUserModel.insertBulkUploadTempTablePreview.<locals>.<listcomp>)
r4r"r#r$r%�fetchoner(r)r'�list�nextsetr+r*)
rr,�insert_query�columnssr9�del_nos�setsr/r#�names�set_�row_rawr2rrr� insertBulkUploadTempTablePreviewms,

�
z/BadgeUserModel.insertBulkUploadTempTablePreviewc
Cs�t����}zLtd|d|d|d|d�}|�|�}|��WWd�dSty�}	z"t|	�WYd}	~	Wd�Sd}	~	00Wd�n1s�0YdS)N�INSERT INTO � (�)SELECT �" from bulk_upload  where conf_id =�  ;r )r4r5r	r6r+r�str)
rr,rBrCr9�checked_del_nosr:r;r1rrrr�insertBulkUpload�s
(
zBadgeUserModel.insertBulkUploadcCs�t����}z�td�}|�|�|��t|�}|�|�|��td|dt|�d�}|�|���}	|	r|dd�|	D�nd}
|
WWd�Sty�}z"t|�WYd}~Wd�Sd}~00Wd�n1s�0YdS)Nztruncate table bulk_upload�SELECT  z# FROM bulk_upload where conf_id  = z! and   delegate_no is not null  ;cSsg|]}t|j��qSr�r(�_mapping�r�rrrrr�rz5BadgeUserModel.bulkuploadPreview1.<locals>.<listcomp>)r4r5r	r6r+rO�allr)rr,rBrCr9rDr:�stmt_1r;�result_2r1rrrr�bulkuploadPreview1�s


z!BadgeUserModel.bulkuploadPreview1cCs�t����}zdtd|d|dt|�d|d�}|�|���}|rXdd�|D�nd}	|	WWd�Sty�}
z"t|
�WYd}
~
Wd�Sd}
~
00Wd�n1s�0YdS)NrRz FROM z where conf_id  = z and delegate_no in ( z!) and  delegate_no is not null  ;cSsg|]}t|j��qSrrSrUrrrr�rz>BadgeUserModel.bulkuploadDublicatePreview2.<locals>.<listcomp>)r4r5r	rOr6rWr)rr,rBrCr9rDr:rXZ	results_1r1rrrr�bulkuploadDublicatePreview2�s
,z*BadgeUserModel.bulkuploadDublicatePreview2cCsLt����,}z�td|dt|�d|d�}|�|�td|d|d|dt|�d	|d�}|�|�}	td
t|�d|dt|�d
t|�d�}
|�|
�|��|	r�WWd�dSWWd�dSWn<t�y&}z"t|�WYd}~Wd�Sd}~00Wd�n1�s>0YdS)N�DELETE FROM z  where conf_id = z and delegate_no in (�) ;rJrKrLrMz  and delegate_no in (z7insert into badge_role (b_role ,conf_id) (select role, z from � where conf_id = zA and role not in (select b_role from  badge_role where conf_id = z  ) group by role ) ;r )r4r5r	rOr6r+r)rr,rBrCr9rDr:r;rXr1Zstmt_3rrrr�bulkuploadSelected�s0$
4
�����
z!BadgeUserModel.bulkuploadSelectedcCslt���P}tdt|�d|d�}|�|�}|��}|rFt|j�ndWd�S1s^0YdS)Nz)select * from conference where conf_id = z and conf_uuid = 'z'   limit 1;)r4r5r	rOr6�one_or_noner(rT)rr,�	conf_uuidr:r;r1�resultrrr�
checkConfUUID�s


zBadgeUserModel.checkConfUUIDc
Cs�t����}td|dt|�d|d�}|�|�|��td|d|dt|�d|d	�}|�|���}	|	r�d
d�|	D�nd}	|	Wd�S1s�0YdS)Nr\z  where  conf_id = z and delegate_no in  (z ) ;rRz  from r^z and delegate_no   in (z)   ;cSsg|]}t|j��qSrrSrUrrrr�rz<BadgeUserModel.removeAndGetRemainRecords.<locals>.<listcomp>)r4r5r	rOr6r+rW)
rr,r9rDrC�remove_delegate_nosr:r;rXr1rrr�removeAndGetRemainRecords�s
$
,z(BadgeUserModel.removeAndGetRemainRecordsc	Cspt���T}td|dt|�d�}|�|���}|rFdd�|D�nd}|Wd�S1sb0YdS)NrRz#  from bulk_upload where conf_id = rNcSsg|]}t|j��qSrrSrUrrrr�rz8BadgeUserModel.GetAllRecordsFromFile.<locals>.<listcomp>�r4r5r	rOr6rW)	rr,r9rDrCrdr:rXr1rrr�GetAllRecordsFromFile�s

z$BadgeUserModel.GetAllRecordsFromFilecCsdt���H}td|d�}|�|���}|r:dd�|D�nd}|Wd�S1sV0YdS)NzHselect count(*) as scanned_count , se.session_id , fc.session_name from �V se inner join fc_sessions fc on fc.session_id = se.session_id group by se.session_id;cSsg|]}t|j��qSrrSrUrrrr�rz7BadgeUserModel.FcScannedTestRecords.<locals>.<listcomp>�r!r5r	r6rW�rr,�ses_entry_tabler:rXr1rrr�FcScannedTestRecords�s

z#BadgeUserModel.FcScannedTestRecordscCs\t���@}td�}t|�}|�|�|�|�}|��|Wd�S1sN0YdS)NzSET SQL_SAFE_UPDATES = 0)r!r5r	r6r+)r�del_stmtr:�safe_updateZ
del_stmt_1rbrrr�delete_test_record�s


z!BadgeUserModel.delete_test_recordcCsdt���H}td|d�}|�|���}|r:dd�|D�nd}|Wd�S1sV0YdS)NzHselect count(*) as scanned_count , se.session_id , kc.session_name from zV se inner join kc_sessions kc on kc.session_id = se.session_id group by se.session_id;cSsg|]}t|j��qSrrSrUrrrr�rz7BadgeUserModel.KcScannedTestRecords.<locals>.<listcomp>rirjrrr�KcScannedTestRecords�s

z#BadgeUserModel.KcScannedTestRecordscCspt���T}td|dt|�d�}|�|���}|rFdd�|D�nd}|Wd�S1sb0YdS)Nz�select d.delegate_id ,d.full_name,d.email,d.role,d.delegate_no,cd.delegate_id as cd_delegate_id,cd.full_name as cd_full_name,cd.email as cd_email,cd.role as cd_role,cd.delegate_no as cd_delegate_no from delegates d inner join z> cd on cd.delegate_no = d.delegate_no where d.conference_id = z| and d.delegate_no is not null and d.role is not null and d.role <> cd.role and d.email=cd.email order by d.delegate_no asc;cSsg|]}t|j��qSrrSrUrrrrrz;BadgeUserModel.get_data_for_role_update.<locals>.<listcomp>rfr8rrr�get_data_for_role_updates

z'BadgeUserModel.get_data_for_role_updatecCs�t����}td|dt|�dt|�dt|�d|d�}|�|�}|��|rlWd�dSWd�dSWd�n1s�0YdS)	Nzupdate zV cd inner join delegates d on cd. delegate_no  = d.delegate_no and d.conference_id = 'z)' set cd.role = d.role ,cd.updated_at = 'z' where d.conference_id = 'zf' and d.delegate_no is not null and d.role is not null and d.role  <> cd.role and cd.delegate_no  in (r]r �fail�r4r5r	rOr6r+�rr,r9�delegate_no�
updated_atr:r;rbrrr�conf_del_update_in_datas
<
z&BadgeUserModel.conf_del_update_in_datacCs�t����}td|dt|�dt|�dt|�d|d�}|�|�}|��|rlWd�dSWd�dSWd�n1s�0YdS)	Nzupdate  delegates d inner join z@ cd on cd. delegate_no  = d.delegate_no  and d.conference_id = 'z=' and d.email=cd.email set d.role = cd.role ,d.updated_at = 'z' where d.conference_id = zc and d.delegate_no is not null and d.role is not null and d.role  <> cd.role and d.delegate_no in (z)  ;r rrrsrtrrr�del_update_in_datas
<
z!BadgeUserModel.del_update_in_datacCsdt���H}td|d�}|�|���}|r:dd�|D�nd}|Wd�S1sV0YdS)Nz^select count(distinct se.delegate_no) as scanned_count , se.session_id , fc.session_name from rhcSsg|]}t|j��qSrrSrUrrrr rz4BadgeUserModel.getbackupscandata.<locals>.<listcomp>rirjrrr�getbackupscandatas

z BadgeUserModel.getbackupscandatacCsdt���H}td|d�}|�|���}|r:dd�|D�nd}|Wd�S1sV0YdS)Nznselect count(distinct se.delegate_no) as scanned_count , se.session_id , fc.session_name,fc.session_key  from rhcSsg|]}t|j��qSrrSrUrrrr'rz:BadgeUserModel.getbackupscandatabackup.<locals>.<listcomp>ri)rr,�
fc_back_tabler:rXr1rrr�getbackupscandatabackup#s

z&BadgeUserModel.getbackupscandatabackupcCs�g}z�t��}|��}|�d|||g�dd�|jD�}g}|��}	|	durNqhtt||	��}
|�|
�q<|�t	|��|�
�dur�q�|jdur(q�q(W|��|��n|��|��0|S)NZfc_data_backupcSsg|]}|d�qSrrr=rrrr6rz0BadgeUserModel.create_backup.<locals>.<listcomp>)
r!r"r#r$r%r?r(r)r'r@rAr+r*)rr,r-�
session_idrEr/r#rFrGrHr2rrr�
create_backup.s,

�
zBadgeUserModel.create_backupN)�__name__�
__module__�__qualname__rr3r<rIrQrZr[r_rcrergrlrorprqrwrxryr{r}rrrrrs(8#
			
r)�
sqlalchemyrrrrrrrr	Zsqlalchemy.sqlr
r�corer�json�configr4r!rrrrr�<module>s(

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists