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,future=True)
class CMEScanModel():
def __init__(self):
try:
self.meta = MetaData()
self.users = Table("users", self.meta, autoload_with=engine)
except Exception as e:
print(e)
def GetConf(self,conf_id,conf_key):
with engine.connect() as conn:
stmt = text("select * from conference c inner join society_applications s on s.conf_id = c.conf_id and app_type_id = 2 inner join mail_setting m on s.mail_setting_id = m.mail_setting_id where c.conf_id = "+str(conf_id)+" and c.conf_key = '"+conf_key+"' limit 1;")
result = conn.execute(stmt)
result = result.first()
conn.close()
return dict(result._mapping) if result else None
def delegateDataForCMEScan(self,conf_id,conf_schema,signup_for_alldays,curr_date):
with engine.connect() as conn:
if int(signup_for_alldays) > 0 :
stmt = text("select d.delegate_id, d.delegate_no,d.role,d.full_name,d.email,d.mobile,d.city,d.membership_no,d.mc_number, d.counter,d.batch,s.signed_by,s.comments,min(s.signed_on) as signed_on, min(s.updated_at) as updated_at,d.conference_id from "+conf_schema+".delegates d "
+" left join "+conf_schema+".cme_signup s on s.delegate_no = d.delegate_no and d.conference_id = s.conf_id and s.signin_date= '"+curr_date+"' "
+ " where d.conference_id = "+str(conf_id)+" and d.delegate_no > 0 and d.delegate_no is not null and d.role not in ('VOLUNTEER','TRADE','EXHIBIOR','CREW','SUPPORT - IT','SUPPORT - AV') group by d.delegate_no order by d.delegate_no asc;")
else :
stmt = text("select d.delegate_id, d.delegate_no,d.role,d.full_name,d.email,d.mobile,d.city,d.membership_no,d.mc_number, d.counter,d.batch,s.signed_by,s.comments,min(s.signed_on) as signed_on, min(s.updated_at) as updated_at,d.conference_id from "+conf_schema+".delegates d "
+" left join "+conf_schema+".cme_signup s on s.delegate_no = d.delegate_no and d.conference_id = s.conf_id "
+ " where d.conference_id = "+str(conf_id)+" and d.delegate_no > 0 and d.delegate_no is not null and d.role not in ('VOLUNTEER','TRADE','EXHIBIOR','CREW','SUPPORT - IT','SUPPORT - AV') group by d.delegate_no order by d.delegate_no asc;")
stmt_2 = text(" SET sql_mode ='' ;")
conn.execute(stmt_2)
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
def usp_search_cme_points(self,search_data,is_delegate,conf_id,signup_for_alldays,curr_date,conf_schema):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_conf_search_data_regdesk",[search_data,is_delegate,conf_id,signup_for_alldays,curr_date])
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 updateAndGetSignedCount(self,conf_id,delegate_no,curr_dt,signed_by,comments,curr_date,signup_for_alldays,conf_schema):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
# cursor = connection.cursor()
cursor.callproc("usp_conf_update_android_sync_data",[conf_id,delegate_no,curr_dt,signed_by,comments,curr_date,signup_for_alldays])
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
cursor.close()
connection.commit()
finally:
# Return the connection to the pool (won't actually close).
connection.close()
return sets
def syncAllDataWithSignedCount(self,conf_id,date_1,signup_for_alldays,conf_schema):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
#call usp_android_sync_with_signed_count(1, 'delegates_demo','2023-03-07',1,'numerotech_primary_db_conf.signup_demo');
# signup_for_alldays,signup_table,curr_date
cursor.callproc("usp_android_sync_with_signed_count",[conf_id,date_1,signup_for_alldays])
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
cursor.close()
connection.commit()
finally:
# Return the connection to the pool (won't actually close).
connection.close()
return sets
def getDelegateDataCMEScan(self,conference_id,delegate_no):
with engine.connect() as conn:
stmt = text("select * from delegates where conference_id ="+str(conference_id)+" and delegate_no ="+str(delegate_no)+" limit 1;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
conn.close()
if results :
return results
else:
return None
def get_mcstates_of_india(self,country_id):
with engine.connect() as conn:
stmt = text("select country_id,state_id,state_name from states where country_id = "+str(country_id)+" order by state_name asc;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
conn.close()
if results :
return results
else:
return None
def updateDelegatedata_cme(self,del_table_name,prefix,full_name,email,mobile,mc_state_id,mc_number,delegate_no,conf_id):
sets = []
try:
connection = engine_conf.raw_connection()
cursor = connection.cursor()
# cursor = connection.cursor()
cursor.callproc("usp_update_delegatedata_from_cmescan",[del_table_name,prefix,full_name,email,mobile,mc_state_id,mc_number,delegate_no,conf_id])
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
cursor.close()
connection.commit()
finally:
# Return the connection to the pool (won't actually close).
connection.close()
return sets
def count_email(self,user_id,email,society_id):
with engine.connect() as conn:
stmt = text("select count(*) as count from users where user_id <> "+str(user_id)+" and email= '"+email+"' and society_id="+str(society_id)+";")
results = conn.execute(stmt).first()
conn.close()
if results :
return dict(results._mapping)
else:
return None
def update_member(self,user_id,datas):
with engine.connect() as conn:
try:
stmt = self.users.update().where(self.users.c.user_id.in_([user_id])).values(datas)
result = conn.execute(stmt)
conn.commit()
conn.close()
return result
except Exception as e:
conn.close()
return str(e)
def update_badge_scan_signup(self,conf_id,delegate_no,curr_dt,signed_by,comments,curr_date,signup_for_alldays,conf_schema):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
# cursor = connection.cursor()
cursor.callproc("usp_conf_update_cme_scan_signup",[conf_id,delegate_no,curr_dt,signed_by,comments,curr_date,signup_for_alldays,conf_schema])
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
cursor.close()
connection.commit()
finally:
# Return the connection to the pool (won't actually close).
connection.close()
return sets
def get_cme_dashboard_data(self,conf_id,conf_schema):
with engine.connect() as conn:
stmt = text("select * from "+conf_schema+".cme_signup where conf_id = "+str(conf_id)+" group by signin_date;")
# stmt = text("select s.delegate_no,d.full_name,d.email,d.mobile,d.membership_no,d.role,d.mc_number,date_format(s.signin_date, '%d-%m-%Y') as signin_date,s.signed_by,s.signed_on,s.comments from "+conf_schema+".delegates d inner join "+conf_schema+".cme_signup s on d.conference_id = s.conf_id and d.delegate_no = s.delegate_no ;")
results_1 = conn.execute(stmt).all()
results = [dict(r._mapping) for r in results_1] if results_1 else None
conn.close()
return results
def get_cme_dashboard_view_data(self,conf_id,conf_schema):
with engine.connect() as conn:
stmt = text("select s.delegate_no,d.full_name,d.email,d.mobile,d.membership_no,d.role,d.mc_number,date_format(s.signin_date, '%d-%m-%Y') as signin_date,s.signed_by,s.signed_on,s.comments from "+conf_schema+".delegates d inner join "+conf_schema+".cme_signup s on d.conference_id = s.conf_id and d.delegate_no = s.delegate_no ;")
results_1 = conn.execute(stmt).all()
results = [dict(r._mapping) for r in results_1] if results_1 else None
conn.close()
return results
def getCMEScandelegateRecord(self,conf_id,conf_date,conf_schema):
with engine.connect() as conn:
if conf_date and "All" in conf_date :
stmt = text("select s.delegate_no,d.full_name,d.email,d.mobile,d.membership_no,d.role,d.mc_number,st.state_name as mc_state,date_format(s.signin_date, '%d-%m-%Y') as signin_date,s.signed_by,s.signed_on,s.comments from "+conf_schema+".delegates d inner join "+conf_schema+".cme_signup s on d.conference_id = s.conf_id and d.delegate_no = s.delegate_no left join states st on st.state_id = d.mc_state_id ;")
else :
stmt = text("select s.delegate_no,d.full_name,d.email,d.mobile,d.membership_no,d.role,d.mc_number,st.state_name as mc_state,date_format(s.signin_date, '%d-%m-%Y') as signin_date,s.signed_by,s.signed_on,s.comments from "+conf_schema+".delegates d inner join "+conf_schema+".cme_signup s on d.conference_id = s.conf_id and d.delegate_no = s.delegate_no left join states st on st.state_id = d.mc_state_id where s.signin_date = '"+conf_date+"';")
results_1 = conn.execute(stmt).all()
results = [dict(r._mapping) for r in results_1] if results_1 else None
conn.close()
return results
def getCMEScanybydelegaateno(self,conf_id,delegate_no,conf_schema):
with engine.connect() as conn:
stmt = text("select signin_date,signed_on from "+conf_schema+".cme_signup where conf_id = "+str(conf_id)+" and delegate_no = "+delegate_no+";")
results_1 = conn.execute(stmt).all()
results = [dict(r._mapping) for r in results_1] if results_1 else None
conn.close()
return results
def getsigned_data(self,conf_id,del_table_name):
with engine.connect() as conn:
stmt =text("select * from "+del_table_name+" where conf_id = '"+str(conf_id)+"' and signed_on is not null; ")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
conn.close()
if results :
return results
else:
return None
def unsignupdata_andbackup(self,main_db,conf_id,delegate_no,del_table_name,reason):
sets = []
try:
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_unsignup_data",[main_db,conf_id,delegate_no,del_table_name,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
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists