Sindbad~EG File Manager
from sqlalchemy import create_engine, MetaData, Table, insert, select,update,delete,text
from sqlalchemy.sql import and_, or_
from core import app
import json
engine = create_engine(app.config['DATABASE_URI'],pool_pre_ping=True,pool_recycle=3600,future=True)
class MCDetailModel():
def __init__(self):
try:
self.meta = MetaData()
self.delegates = Table("delegates", self.meta, autoload_with=engine)
self.mc_delegates = Table("mc_delegates", self.meta, autoload_with=engine)
except Exception as e:
print(e)
def checkConfData(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+"' ;")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def delegateDataByUUID(self,conf_id,conf_key,user_uuid):
with engine.connect() as conn:
stmt = text("select d.*, s.state_name as mc_state_name from delegates d left join states s on s.state_id = d.mc_state_id and s.country_id = 101 "
+ " where d.conference_id = "+str(conf_id)+" and d.user_uuid = '"+user_uuid+"' and d.delegate_no is not null and d.delegate_no > 0 ;")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def getStates(self,country_id):
with engine.connect() as conn:
stmt = text("select * from states s where s.country_id = "+str(country_id)+" ;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results if results else None
def updateData(self,data,user_uuid,email,conf_id,conf_key):
with engine.connect() as conn:
try:
update_stmt = self.delegates.update().where(self.delegates.c.user_uuid.in_([user_uuid])).values(data)
conn.execute(update_stmt)
conn.commit()
return "success"
except Exception as e:
return str(e)
# ------------------------ March 24, 2023 --------
def delegateDataByDelegateNo(self,conf_id,conf_key,delegate_no):
with engine.connect() as conn:
stmt = text("select d.*, s.state_name as mc_state_name from delegates d left join states s on s.state_id = d.mc_state_id and s.country_id = 101 "
+ " where d.conference_id = "+str(conf_id)+" and d.delegate_no = "+str(delegate_no)+" and d.delegate_no is not null and d.delegate_no > 0 limit 1 ;")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def updateMCData(self,data,delegate_no,email,conf_id,conf_key,mc_number,state_name,curr_dt,del_table_name):
with engine.connect() as conn:
try:
update_stmt = self.delegates.update().where(
and_(
self.delegates.c.delegate_no == delegate_no,
self.delegates.c.conference_id == conf_id
)
).values(data)
conn.execute(update_stmt)
conn.commit()
update_del_conf_table = text("UPDATE "+del_table_name+" set mc_number= '" + mc_number+ "' , state = '"+ state_name+"' ,updated_at = '"+curr_dt+"' where delegate_no = " +str(delegate_no)+ " and conf_id = "+str(conf_id)+" ;" )
conn.execute(update_del_conf_table)
conn.commit()
return "success"
except Exception as e:
return str(e)
def updateMCDataNew(self,data_for_update,delegate_no,conf_id,update_stmt):
with engine.connect() as conn:
try:
stmt = self.delegates.update().where(
and_(
self.delegates.c.delegate_no == delegate_no,
self.delegates.c.conference_id == conf_id
)
).values(data_for_update)
conn.execute(stmt)
conn.commit()
update_del_conf_table = text(update_stmt)
conn.execute(update_del_conf_table)
conn.commit()
return "success"
except Exception as e:
return str(e)
def getMCState(self,mc_state_id):
with engine.connect() as conn:
stmt = text("SELECT state_name from states where state_id = "+str(mc_state_id)+" ; ")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def insert_delegate_in_mc_delegates(self,conf_id,delegate_no,curr_dt):
with engine.connect() as conn:
try:
stmt = text("insert into mc_delegates (delegate_no,prefix,full_name,email,mobile,mc_number,mc_state_id,role,reg_type_id,conference_id,created_at) select delegate_no,prefix,full_name,email,mobile,mc_number,mc_state_id,role,reg_type_id,conference_id,'"+curr_dt+"' from delegates where conference_id ="+str(conf_id)+" and delegate_no = "+str(delegate_no)+" and delegate_no is not null;")
conn.execute(stmt)
conn.commit()
return "success"
except Exception as e:
return str(e)
def check_delegates_email(self,conf_id,email,delegate_no):
with engine.connect() as conn:
stmt = text("select * from delegates where conference_id = "+str(conf_id)+" and email = '"+str(email)+"' and delegate_no <> "+str(delegate_no)+" and role not in ('ACC.DELEGATE') and delegate_no is not null ;")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def check_delegates_mobile(self,conf_id,mobile,delegate_no):
with engine.connect() as conn:
stmt = text("select * from delegates where conference_id = "+str(conf_id)+" and mobile = '"+str(mobile)+"' and delegate_no <> "+str(delegate_no)+" and role not in ('ACC.DELEGATE') and delegate_no is not null ;")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists