Sindbad~EG File Manager
from sqlalchemy import create_engine, MetaData, Table, insert, null, select,update,delete,text
from sqlalchemy.sql import and_, or_
from sqlalchemy import asc, desc
from core import app
import json
engine = create_engine(app.config['DATABASE_URI'], pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
class SignUpModel():
def __init__(self):
try:
self.meta = MetaData()
except Exception as e:
print(e)
def checkConfUUID(self,conf_id,conf_uuid):
with engine.connect() as conn:
stmt = text("select * from conference where conf_id = "+str(conf_id)+" and conf_uuid = '"+conf_uuid+"' limit 1;")
results = conn.execute(stmt)
result = results.first()
conn.close()
return dict(result._mapping) if result else None
def usp_save_signed_data(self,conf_id,delegate_no,signed_by,comments,conf_schema,user_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_conf_save_signed_data",[conf_id,delegate_no,signed_by,comments,conf_schema,user_id])
if cursor.description :
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
connection.close()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
connection.close()
return None
def usp_save_scan_signed_data(self,conf_id,delegate_no,signed_by,comments,user_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_conf_scan_signed_data",[conf_id,delegate_no,signed_by,comments,user_id])
if cursor.description :
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
connection.close()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
connection.close()
return None
def usp_search_regdesk(self,conf_schema,search_data,is_delegate,conf_id):
print(conf_schema,search_data,is_delegate,conf_id)
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_conf_search_regdesk",[conf_schema,search_data,is_delegate,conf_id])
if cursor.description :
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
connection.close()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
connection.close()
return None
def getCount(self ,conf_id,schema_name) :
with engine.connect() as conn:
stmt = text ("SELECT (select count(*) as total_signed_on from " +schema_name+ ".delegates where conference_id ="+str(conf_id)+" and signed_on is not null limit 1 ) as total_signed_on , "+
" (select count(*) as total_count from " +schema_name+ ".delegates where conference_id ="+str(conf_id)+" and role not in ('TRADE','VOLUNTEER','SUPPORT FABRICATTION','AUDIO VISUAL','IT-SUPPORT')) as total_count from " +schema_name+ ".delegates limit 1 ;")
results = conn.execute(stmt).first()
conn.close()
if results :
return dict(results._mapping)
else:
return None
# unsignup delegate number start
def getsigned_data(self,conf_id,conf_schema):
with engine.connect() as conn:
stmt =text("select * from "+conf_schema+".delegates where conference_id = "+str(conf_id)+" and del_status_id=2 and signed_on is not null; ")
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
if results :
return results
else:
return None
# Multiple result set
def unsignupdata_andbackup(self,main_db,conf_id,delegate_no,conf_schema,reason):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_conf_unsignup_data",[main_db,conf_id,delegate_no,conf_schema,reason])
while 1:
names = [c[0] for c in cursor.description]
set_ = []
while 1:
row_raw = cursor.fetchone()
if row_raw is None:
break
row = dict(zip(names, row_raw))
set_.append(row)
sets.append(list(set_))
if cursor.nextset() is None:
break
# nextset() doesn't seem to be sufficiant to tell the end.
if cursor.description is None:
break
finally:
# Return the connection to the pool (won't actually close).
connection.commit()
connection.close()
return sets
# unsignup delegate number end
def UnsignupButScannedList(self,conf_id,del_nos,del_table_name,kc_entry_table,fc_entry_table,fcbackup_table,is_bulk_signup,is_view_bulk_signup_data,is_manual_signup):
print("usp_conf_badge_not_collected_but_attended_list")
print(conf_id,del_nos,del_table_name,kc_entry_table,fc_entry_table,fcbackup_table,is_bulk_signup,is_view_bulk_signup_data,is_manual_signup)
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_conf_badge_not_collected_but_attended_list",[conf_id,del_nos,del_table_name,kc_entry_table,fc_entry_table,fcbackup_table,is_bulk_signup,is_view_bulk_signup_data,is_manual_signup])
if cursor.description :
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
connection.close()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
connection.close()
return None
def get_uuid_delegates_table(self,del_table_name,uuid,conf_id):
with engine.connect() as conn:
stmt = text("select d.* from "+del_table_name+" d "
+ " where d.conference_id = "+str(conf_id)+" "
+ " and d.user_uuid = '"+uuid+"' ")
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_delegate_no_delegates_table(self,del_table_name,delegate_no,conf_id):
with engine.connect() as conn:
stmt = text("select d.* from "+del_table_name+" d "
+ " where d.conference_id = "+str(conf_id)+" "
+ " and d.delegate_no = '"+delegate_no+"' ")
result = conn.execute(stmt).first()
conn.close()
return dict(result._mapping) if result else None
def get_signup_count(self,del_table_name,conf_id):
with engine.connect() as conn:
stmt = text("select count(*) as count from "+del_table_name+" d "
+ " where d.conference_id = "+str(conf_id)+" "
+ " and d.signed_on is not null ")
result = conn.execute(stmt).first()
conn.close()
count = dict(result._mapping).get('count') if result else None
return count
def getdelegate_data(self,conf_id,conf_schema,del_nos):
try:
with engine.connect() as conn:
stmt =text("select * from "+conf_schema+".delegates where conference_id = "+str(conf_id)+" and del_status_id=2 and delegate_no in ("+del_nos+") order by delegate_no asc; ")
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
if results :
return results
else:
return None
except Exception as ex:
print(f"An unexpected error occurred: {ex}")
return None
def updatedelegate_signup(self,conf_id,conf_schema,del_nos,dt_string):
with engine.connect() as conn:
stmt_1 = text("set sql_safe_updates = 0;")
stmt = text("update "+conf_schema+".delegates set is_present = 1 ,is_present_at= '"+dt_string+"',signed_on='"+dt_string+"',signed_by= 'Delegate' , comments='bulk signup' where signed_on is null and conference_id = "+str(conf_id)+" and delegate_no in ("+del_nos+") ;")
result_1 = conn.execute(stmt_1)
result = conn.execute(stmt)
conn.commit()
conn.close()
if result:
return 'success',result.rowcount
else :
return 'fail',0
def usp_conf_save_qr_scanned_data(self,conf_id,delegate_no):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_conf_save_qr_scanned_data",[conf_id,delegate_no])
if cursor.description :
columns = [column[0] for column in cursor.description]
results = []
for row in cursor.fetchall():
results.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
connection.close()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
connection.close()
return None
def get_tshirt_count(self,del_table_name,conf_id):
with engine.connect() as conn:
stmt = text("select count(*) as count from "+del_table_name+" d "
+ " where d.conference_id = "+str(conf_id)+" "
+ " and d.tshirt_collected_at is not null ")
result = conn.execute(stmt).first()
conn.close()
count = dict(result._mapping).get('count') if result else None
return count
def get_overall_signup_count(self,del_table_name,conf_id):
try:
with engine.connect() as conn:
stmt =text("select d.role,count(d.delegate_no) as count_delegate_no from "+del_table_name+" d inner join badge_role b on b.b_role_id = d.role_id where d.signed_on is not null and b.is_display_count = 1 and d.conference_id = "+str(conf_id)+" and b.conf_id = "+str(conf_id)+" group by d.role; ")
# stmt = text("select d.badge_role as role,count(d.delegate_no) as count_delegate_no from "+del_table_name+" d where d.signed_on is not null and d.conference_id = "+str(conf_id)+" and d.del_status_id=2 group by d.badge_role; ")
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
if results :
return results
else:
return None
except Exception as ex:
print(f"An unexpected error occurred: {ex}")
return str(ex)
def get_overall_signup_data(self,del_table_name,conf_id,role):
try:
with engine.connect() as conn:
stmt =text("select d.counter,d.batch,d.delegate_no,case when d.prefix is null then d.full_name else concat(d.prefix,' ',d.full_name) end as full_name,email,mobile,case when d.badge_role is not null then d.badge_role else d.role end as role,d.signed_on from "+del_table_name+" d inner join badge_role b on b.b_role_id = d.role_id where d.signed_on is not null and b.is_display_count = 1 and d.conference_id = "+str(conf_id)+" and b.conf_id = "+str(conf_id)+" and d.role = '"+str(role)+"'; ")
result = conn.execute(stmt).all()
conn.close()
results = [dict(r._mapping) for r in result] if result else None
if results :
return results
else:
return None
except Exception as ex:
print(f"An unexpected error occurred: {ex}")
return str(ex)
def get_signup_count_by_role(self,del_table_name,conf_id,role):
with engine.connect() as conn:
stmt = text("select count(*) as count from "+del_table_name+" d "
+ " where d.conference_id = "+str(conf_id)+" "
+ " and d.signed_on is not null and d.role='"+str(role)+"'")
result = conn.execute(stmt).first()
count = dict(result._mapping).get('count') if result else None
conn.close()
return count
def getCounterSetWise(self,conf_schema,conf_id):
try:
with engine.connect() as conn:
stmt = text("select counter,batch from "+conf_schema+".delegates where conference_id = "+str(conf_id)+" and del_status_id = 2 and counter is not null group by counter,batch order by counter ; ")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
if results :
return results
else:
return None
except Exception as ex:
print(f"An unexpected error occurred: {ex}")
return None
def getDelegateDetails(self,conf_id,conf_schema,counter,set_for_badge):
try:
with engine.connect() as conn:
set_condition = ''
if counter:
set_condition = set_condition + " and counter = "+str(counter)
if set_for_badge:
set_condition = set_condition + " and batch = '"+str(set_for_badge)+"'"
stmt = text("select * from "+conf_schema+".delegates where conference_id = "+str(conf_id)+" and del_status_id = 2 "+str(set_condition)+" order by counter,batch,delegate_no ; ")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
if results :
return results
else:
return None
except Exception as ex:
print(f"An unexpected error occurred: {ex}")
return None
def getDelegateNosDetails(self,conf_id,conf_schema,delegate_nos):
try:
with engine.connect() as conn:
stmt = text("select * from "+conf_schema+".delegates where conference_id = "+str(conf_id)+" and del_status_id = 2 and delegate_no in ("+str(delegate_nos)+") order by counter,batch,delegate_no ; ")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
if results :
return results
else:
return None
except Exception as ex:
print(f"An unexpected error occurred: {ex}")
return None
def updatedelegate_unsignup(self,conf_id,conf_schema,del_nos,dt_string):
with engine.connect() as conn:
stmt_1 = text("set sql_safe_updates = 0;")
stmt = text("update "+conf_schema+".delegates set is_present = null ,is_present_at= null,signed_on=null ,signed_by= null , comments='bulk unsignup' where conference_id = "+str(conf_id)+" and delegate_no in ("+del_nos+") ;")
result_1 = conn.execute(stmt_1)
result = conn.execute(stmt)
conn.commit()
if result:
return 'success',result.rowcount
else :
return 'fail',0
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists