Sindbad~EG File Manager
from flask import session
from flask import request, Blueprint, jsonify
from sqlalchemy import create_engine, select, MetaData, Table,text
from sqlalchemy.sql import and_, or_
from core import app
engine = create_engine(app.config['DATABASE_URI'],pool_pre_ping=True,pool_recycle=3600,future=True)
engine_fk = create_engine(app.config['DATABASE_URI_FK'],pool_pre_ping=True,pool_recycle=3600,future=True)
engine_conf = create_engine(app.config['DATABASE_URI_CONF'],pool_pre_ping=True,pool_recycle=3600,future=True)
class BadgeModel():
def __init__(self):
try:
self.meta = MetaData()
self.badge_role = Table("badge_role",self.meta, autoload_with= engine)
self.states = Table("states", self.meta,autoload_with=engine)
self.conference = Table("conference",self.meta, autoload_with= engine)
self.delegates = Table("delegates",self.meta, autoload_with= engine)
self.badge_setting = Table("badge_setting",self.meta, autoload_with= engine_conf)
except Exception as e:
print(e)
def GetConf(self,conf_id,conf_key):
with engine.connect() as conn:
stmt = text("select * from conference where conf_id = "+str(conf_id)+" and conf_key = '"+conf_key+"' limit 1;")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
def get_states(self):
with engine.connect() as conn:
# stmt = select([self.states])
stmt_2 = text("select * from states;")
result = conn.execute(stmt_2).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def checkUsername(self,username,conf_id):
with engine.connect() as conn:
stmt = text("select * from conference where conf_id = "+str(conf_id)+" and username = '"+username+"' limit 1;")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
def AllRegUsers(self,conf_id,del_table_name) :
with engine.connect() as conn:
# stmt = text("select d.delegate_id,d.delegate_no,concat(ifnull(concat(d.prefix,' '),''),ifnull(d.full_name,'')) as full_name,d.email,d.mobile,d.city,d.state_id,d.counter,d.batch,d.role ,s.state_name from "+del_table_name+" d left join states s on s.state_id = d.state_id inner join conference c on c.society_id = d.society_id where c.conf_id = " +str(conf_id)+" and d.delegate_no > 0 order by delegate_no asc;")
stmt = text("select d.delegate_id,d.delegate_no,d.full_name as full_name,d.email,d.mobile,d.city,d.state, d.counter,d.batch,d.role,d.company_name from "+del_table_name+" d where d.delegate_no > 0 order by delegate_no asc;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def AllDelegageIds(self,conf_id,del_table_name) :
with engine.connect() as conn:
#stmt = text("select d.delegate_no from delegates d left join states s on s.state_id = d.state_id inner join conference c on c.society_id = d.society_id where c.conf_id = " +str(conf_id)+" and d.delegate_no > 0 order by delegate_no asc;")
stmt = text("select distinct (d.delegate_no) from "+del_table_name+" d where d.delegate_no is not null and d.delegate_no > 0 order by delegate_no asc;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def updateCouterBatch(self,update_query):
with engine.connect() as conn:
try:
stmt = text(update_query)
safe_update = text("SET SQL_SAFE_UPDATES = 0 ")
result = conn.execute(safe_update)
results = conn.execute(stmt)
conn.commit()
return "success"
except Exception as e:
return str(e)
# Multiple result set store proc function
def GetBatchCounterRole(self,conf_id,del_table_name):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_counter_batch_role",[conf_id,del_table_name])
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
def dataForBadgePrint(self,conf_id,role,counter,batch,del_no_from,del_no_to,del_table_name,is_commitment = None):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_delegate_badge_data",[conf_id,role,counter,batch,del_no_from,del_no_to,del_table_name,is_commitment])
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()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
return None
def dataForBadgePrintDelNos(self,conf_id,role,counter,batch,del_nos,del_table_name,is_kit):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_delegate_badge_data_customids_withkit",[conf_id,role,counter,batch,del_nos,del_table_name,is_kit])
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()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
return None
def EditRegisteredData(self,conf_id,delegate_id,del_table_name):
with engine.connect() as conn:
# stmt = text("select d.delegate_id,d.delegate_no,concat(ifnull(concat(d.prefix,' '),''),ifnull(d.full_name,'')) as full_name,d.email,d.city,d.state_id,s.state_name from delegates d left join states s on d.state_id=s.state_id where d.delegate_id = "+str(delegate_id)+" and conference_id="+str(conf_id)+" ;")
stmt = text("select d.* from "+del_table_name+" d where d.delegate_id = "+str(delegate_id)+" ;")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
def UpdateDelegates(self,update_stmt,delegate_id,conf_id):
with engine.connect() as conn:
safe_update = text("SET SQL_SAFE_UPDATES = 0 ; ")
result_1 = conn.execute(safe_update)
stmt = text(update_stmt)
# stmt = self.delegates.update().where(self.delegates.c.delegate_id.in_([delegate_id])).values(data)
result = conn.execute(stmt)
conn.commit()
if result:
return result
else :
return None
def check_email_for_update(self,email,delegate_id,del_table_name):
with engine.connect() as conn:
stmt = text("select count(*) as email_count from "+del_table_name+" where email = " + "'" + email + "'" + "and delegate_id !=" + str( delegate_id) + ";")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
# Nov 03 2022
def delegateMoveToConfDelegate(self,conference_id,conf_del_table,max_del_no,current_dt):
with engine.connect() as conn:
check_no_records_stmt = text("SELECT count(*) as no_of_records from delegates where delegate_no > 0 and conference_id = "+str(conference_id)+" and delegate_no is not null and delegate_no not in (select delegate_no from "+conf_del_table+") ")
# check_no_records_stmt = text("SELECT count(*) as no_of_records from delegates where delegate_no > "+str(max_del_no)+ " and conference_id = "+str(conference_id)+ " and delegate_no is not null")
# check_no_records_stmt = text("SELECT count(*) as no_of_records from delegates where delegate_no > 0 and delegate_no is not null and delegate_no not in (select delegate_no from "+conf_del_table+") ")
results = conn.execute(check_no_records_stmt).all()
result = [dict(r._mapping) for r in results] if results else None
if result :
no_of_records = result[0]['no_of_records']
if no_of_records > 0 :
#stmt = text("insert into "+conf_del_table+" (delegate_no ,conf_id,full_name,email,mobile,city,membership_no,created_at,state,role,company_name) "
# + " select delegate_no,conference_id,concat(ifnull(concat(prefix,' '),''),ifnull(full_name,'')) as full_name ,email,mobile,city,"
# +" membership_no , '"+current_dt+"' , s.state_name,role,d_company_name from delegates left join states s on delegates.state_id = s.state_id where conference_id = "+str(conference_id)+" and delegate_no is not null and delegate_no > "+str(max_del_no)+" and delegate_no not in ( select delegate_no from "+conf_del_table+" );")
#### stmt update on Jan 05, 2023 for prevent duplicate record insert
stmt = text("insert into "+conf_del_table+" (user_id,delegate_no ,conf_id,full_name,email,mobile,city,membership_no,mc_number,created_at,state,role,company_name,reg_remarks) "
+ " select user_id, delegate_no,conference_id,concat(ifnull(concat(prefix,' '),''),ifnull(full_name,'')) as full_name ,email,mobile,city,"
+" membership_no ,mc_number, '"+current_dt+"' , s.state_name,role,d_company_name,reg_remarks from delegates left join states s on delegates.mc_state_id = s.state_id where conference_id = "+str(conference_id)+" and delegate_no is not null and delegate_no > 0 and delegate_no not in ( select delegate_no from "+conf_del_table+" );")
result = conn.execute(stmt)
conn.commit()
return str(no_of_records) +" records are successfully moved."
else :
return "There is no new records exists."
else :
return "There is no new records exists."
def getMaxDelegateNo(self,conf_del_table):
with engine.connect() as conn:
stmt = text("select max(delegate_no) as delegate_no from "+conf_del_table+" where delegate_no > 5000 limit 1;")
# stmt = text("select max(delegate_no) as delegate_no from "+conf_del_table+" where delegate_no < 3000 limit 1;")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
# nov 07 2022
def getRole(self,conf_id):
with engine.connect() as conn:
stmt = text("select * from badge_role where conf_id = "+str(conf_id)+";")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
#nov 17 22 Siva &*****************************************************************
def insertEmptyRecords(self,insert_query):
with engine.connect() as conn:
try:
stmt = text(insert_query)
results = conn.execute(stmt)
conn.commit()
return "success"
except Exception as e:
return str(e)
# Nov 22 ,2022 updated by Ganesan J on
#sessionMap(conf_id,del_id_int,session_table,del_ses_table)
def sessionMap(self,conf_id,del_id_int,session_table,del_ses_table) :
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_delegate_session_map",[conf_id,del_id_int,session_table,del_ses_table])
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()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
return None
# Nov 23 update is_exhibitor s
def updateExhibitor(self,update_query):
with engine.connect() as conn:
try:
stmt = text(update_query)
safe_update = text("SET SQL_SAFE_UPDATES = 0 ")
result = conn.execute(safe_update)
results = conn.execute(stmt)
conn.commit()
return "success"
except Exception as e:
return str(e)
# Dec 05,2022
# Role Option start -----------------------
def deleteBadgeRole(self,b_role_id):
with engine.connect() as conn:
stmt = self.badge_role.delete().where(self.badge_role.c.b_role_id.in_([b_role_id]))
result = conn.execute(stmt)
conn.commit()
return result
def insertBadgeRole(self,data):
with engine.connect() as conn:
result = conn.execute(self.badge_role.insert(), data)
conn.commit()
return result
def updateBadgeRole(self,b_role_id,data):
with engine.connect() as conn:
# stmt = text("update badge_role set b_role = '"+role+"' where b_role_id = "+str(b_role_id)+" ;")
stmt = self.badge_role.update().where(self.badge_role.c.b_role_id.in_([b_role_id])).values(data)
result = conn.execute(stmt)
conn.commit()
if result:
return 'success'
else :
return 'fail'
#Role option End--------------------------
################### For Digital Batch ###############
# Created by : Priyavarthana
# 2022-12-07
def check_email_mobile(self,del_table_name,email_mobile,conf_id):
with engine.connect() as conn:
stmt = text("select * from "+del_table_name+" where conf_id = "+str(conf_id)+" and (email =:email_mobile or mobile= '"+email_mobile+"' ) order by role desc;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def update_delegate(self,del_table_name,delegate_id,updated_at,otp_verify_on):
with engine.connect() as conn:
stmt = text("update "+del_table_name+" set updated_at= '"+str(updated_at)+"', otp_verify_on= '"+str(otp_verify_on)+"', otp = null where delegate_id =" + str( delegate_id) + ";")
result = conn.execute(stmt)
conn.commit()
if result:
return 'success'
else :
return 'fail'
def getDelegateByID(self,del_table_name,delegate_id):
with engine.connect() as conn:
stmt = text("select * from "+del_table_name+" where delegate_id= "+str(delegate_id)+";")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
################### END For Digital Batch ###############
# Dec 23,2022 Siva Balan
def get_role_count(self,conf_id,del_table_name):
with engine.connect() as conn:
stmt = text("SELECT role,count(delegate_no) as del_count from "+del_table_name+" group by role order by role;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def usp_delegates_session_map(self,role,session_id,del_table_name,del_session_table_name):
connection = engine_fk.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_insert_delegate_sessions_map",[role,session_id,del_table_name,del_session_table_name])
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()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
return None
def usp_delegates_session_map_kc(self,role,session_id,del_table_name,del_session_table_name):
connection = engine_fk.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_insert_delegate_sessions_map_kc",[role,session_id,del_table_name,del_session_table_name])
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()
if results :
return results
else :
return None
else :
cursor.close()
connection.commit()
return None
# Dec 24,2022 Siva Balan
def delete_sessiondata(self,role,session_id,del_table_name,del_session_table_name):
with engine_fk.connect() as conn:
stmt = text("Delete from "+del_session_table_name+" where delegate_no in (select delegate_no from "+del_table_name+" where role = ('"+role+"') )and session_id=" + str( session_id) + ";")
safe_update = text("SET SQL_SAFE_UPDATES = 0 ")
results= conn.execute(safe_update)
result = conn.execute(stmt)
conn.commit()
return result
def get_uuid_delegates(self,del_table_name,uuid,conf_id):
with engine.connect() as conn:
stmt = text("select t.* from delegates_boa23 t "
+ " inner join delegates d on t.delegate_no = d.delegate_no and d.conference_id = "+str(conf_id)+" "
+ " inner join users u on u.user_id = d.user_id or u.user_id = d.parent_user_id "
+ " where u.user_uuid = '"+uuid+"' ")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def get_delegate_by_del_no(self,del_table_name,del_no,conf_id):
with engine.connect() as conn:
stmt = text("select t.* from "+del_table_name+" t "
+ " inner join delegates d on t.delegate_no = d.delegate_no and d.conference_id = "+str(conf_id)+" "
+ " inner join users u on u.user_id = d.user_id or u.user_id = d.parent_user_id "
+ " where t.delegate_no = "+str(del_no)+" ")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def update_delegate_otp(self,del_table_name,delegate_id,updated_at,otp):
with engine.connect() as conn:
stmt = text("update "+del_table_name+" set updated_at= '"+str(updated_at)+"', otp= '"+str(otp)+"' where delegate_id =" + str( delegate_id) + ";")
result = conn.execute(stmt)
conn.commit()
if result:
return 'success'
else :
return 'fail'
# Badge setting adjustment option start -- Santhosh August 21, 2023
def Get_badge_size(self,conf_id,Delegate_badge_type):
with engine_conf.connect() as conn:
stmt = text("select * from badge_setting where conf_id = "+str(conf_id)+" and badge_type = '"+Delegate_badge_type+"' limit 1;")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
def badgeSettingsData(self,conf_id):
with engine_conf.connect() as conn:
stmt = text("select * from badge_setting where conf_id = "+str(conf_id)+";")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def insert_badge_data(self,data):
try:
with engine_conf.connect() as conn:
result = conn.execute(self.badge_setting.insert(), data)
conn.commit()
return "success"
except Exception as e:
return str(e)
def update_badge_data(self,bs_id,conf_id,data_for_save):
with engine_conf.connect() as conn:
try:
stmt = self.badge_setting.update().where(self.badge_setting.c.bs_id.in_([bs_id]),self.badge_setting.c.conf_id.in_([conf_id])).values(data_for_save)
restult_1 = conn.execute(stmt)
conn.commit()
return "success"
except Exception as e:
return str(e)
def deleteBadgeSize(self,bs_id,conf_id):
with engine_conf.connect() as conn:
stmt = self.badge_setting.delete().where(self.badge_setting.c.bs_id.in_([bs_id]))
result = conn.execute(stmt)
conn.commit()
return result
def editBadgeSize(self,conf_id,bs_id):
with engine_conf.connect() as conn:
stmt = text("select * from badge_setting where conf_id = "+str(conf_id)+" and bs_id = "+str(bs_id)+" ;")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
# Badge setting adjustment option start
# empty records min and max start
def GetDelMaxNumberMinNumber(self,del_table_name,role,conf_id):
with engine_conf.connect() as conn:
stmt = text("select ifnull(min(delegate_no),0) as min_del_num ,ifnull(max(delegate_no),0) as max_del_num from "+del_table_name+" where conf_id ="+str(conf_id)+" and role ='"+role+"' ;")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
def get_delegate_already_exists(self,del_table_name,del_no_from,del_no_to,conf_id):
with engine_conf.connect() as conn:
stmt= text("select * FROM "+del_table_name+" WHERE conf_id ="+str(conf_id)+" and delegate_no BETWEEN "+str(del_no_from)+" AND "+str(del_no_to)+" limit 1;")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
# empty records min and max end
def update_file_nameand_path(self,conf_id,bs_id,data_1):
with engine_conf.connect() as conn:
try:
stmt = self.badge_setting.update().where(self.badge_setting.c.bs_id.in_([bs_id]),self.badge_setting.c.conf_id.in_([conf_id])).values(data_1)
restult_1 = conn.execute(stmt)
conn.commit()
return "success"
except Exception as e:
return str(e)
def getfilename_and_path(self,conf_id):
with engine_conf.connect() as conn:
# stmt = text("select * from badge_setting where conf_id = "+str(conf_id)+";")
stmt = text("select bs_id,file_name,file_path from badge_setting where conf_id = "+str(conf_id)+" order by bs_id asc limit 1 ;")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
def insert_file_nameand_path(self,data):
try:
with engine_conf.connect() as conn:
result = conn.execute(self.badge_setting.insert(), data)
conn.commit()
return "success"
except Exception as e:
return str(e)
# Ganesan J Sep 20, 2023
def GetLongestName(self,del_table_name,role,conf_id):
where_con = " "
with engine_fk.connect() as conn:
base_query = " select delegate_no,full_name,role, char_length(full_name) as text_lenght from "+del_table_name+" where (1+1) and full_name is not null and delegate_no is not null "
order_by = " order by char_length(full_name) desc LIMIT 5 "
if role :
where_con = " and role = '"+role+"' "
stmt = text(base_query+ where_con + order_by)
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists