Sindbad~EG File Manager
from sqlalchemy import create_engine, MetaData, Table, insert, func, select,text
from sqlalchemy.sql import and_, or_
from core import app
from .. import engine
# engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
class SurgicalUserModel():
def __init__(self):
try:
self.meta = MetaData()
self.delegates_addons = Table("delegates_addons", self.meta, autoload_with=engine)
self.user_payment = Table("user_payment", self.meta, autoload_with=engine)
self.delegates = Table("delegates", self.meta, autoload_with=engine)
except Exception as e:
print(e)
# def CheckAlreadyReg(self,email,conf_id):
# conn = engine.connect()
# stmt = text("select * from delegates where email= '"+email+"' and conference_id = "+str(conf_id)+";")
# results = conn.execute(stmt)
# conn.close()
# results = [dict(r) for r in results] if results else None
# if results :
# return results[0]
# else:
# return None
# def ss_insert_users(self,data,dt_string,conf_id):
# conn = engine.connect()
# result = conn.execute(self.delegates.insert(), data)
# delegate_id = result.lastrowid
# get_del_no = text("select ifnull(max(delegate_no),0) as max_del_no from delegates where conference_id = "+str(conf_id)+" ;")
# result = conn.execute(get_del_no)
# result_1 = result.fetchone()
# max_del_no = result_1.max_del_no if result_1.max_del_no else 0
# if max_del_no is not None:
# del_no = int(max_del_no) + 1
# stmt_update_del_no = text("update delegates set delegate_no ="+str(del_no)+ " where delegate_id = " +str(delegate_id) + " ;" )
# result_2 = conn.execute(stmt_update_del_no)
# unique_id = "SS24DEL"+str(delegate_id)
# reg_status = 2
# del_addon = {'delegate_id': delegate_id,'unique_id' : unique_id,'reg_status' : reg_status}
# result_3 = conn.execute(self.delegates_addons.insert(), del_addon)
# get_receipt_no = text("select ifnull(max(receipt_no),0) as max_receipt_no from user_payment where conf_id = "+str(conf_id)+" ;")
# results_4 = conn.execute(get_receipt_no)
# result_4 = results_4.fetchone()
# max_receipt_no = result_4.max_receipt_no if result_4.max_receipt_no else 0
# receipt_no = int(max_receipt_no)+1
# prefix = data['prefix'] or None
# name = data['full_name'] or None
# full_name = prefix + " " + name if prefix else name
# email = data['email']
# mobile = data['mobile']
# payment_data = {
# 'delegate_ids': delegate_id,
# 'unique_id' : unique_id,
# 'status' : "success",
# 'conf_id' : conf_id,
# 'society_id' : "13",
# 'receipt_no' : receipt_no,
# 'created_at' : dt_string,
# 'paid_at' : dt_string,
# 'updated_at' : dt_string,
# 'full_name' : full_name,
# 'email' : data['email'],
# 'mobile' : data['mobile'],
# 'app_type' : "DELEGATE"
# }
# result_5 = conn.execute(self.user_payment.insert(),payment_data)
# conn.close()
# return del_no
def CheckAlreadyReg(self,email,conf_id):
with engine.connect() as conn:
stmt = text("select * from delegates where email= '"+email+"' and conference_id = "+str(conf_id)+";")
print(stmt)
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
if results :
return results[0]
else:
return None
# Added Status id
def get_total_previous_reg_count(self,conf_id,curr_dt):
with engine.connect() as conn:
stmt = text("select count(*) as total_previous_count from delegates where conference_id = "+str(conf_id)+" and delegate_no is not null and del_status_id = 2 and date(registered_on) <= '"+str(curr_dt)+"' ;")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
# Added Status id
def get_total__current_reg_count(self,conf_id,curr_dt):
with engine.connect() as conn:
stmt = text("select count(*) as total_current_count from delegates where conference_id = "+str(conf_id)+" and delegate_no is not null and del_status_id = 2 and date(registered_on) = '"+str(curr_dt)+"' ;")
result = conn.execute(stmt).one_or_none()
return dict(result._mapping) if result else None
def ss_insert_users(self,data,dt_string,conf_id):
with engine.connect() as conn:
result = conn.execute(self.delegates.insert(), data)
conn.commit()
delegate_id = result.lastrowid
get_del_no = text("select ifnull(max(delegate_no),0) as max_del_no from delegates where conference_id = "+str(conf_id)+" ;")
result = conn.execute(get_del_no)
result_1 = result.fetchone()
max_del_no = result_1.max_del_no if result_1.max_del_no else 0
if max_del_no is not None:
del_no = int(max_del_no) + 1
stmt_update_del_no = text("update delegates set delegate_no ="+str(del_no)+ " where delegate_id = " +str(delegate_id) + " ;" )
result_2 = conn.execute(stmt_update_del_no)
conn.commit()
unique_id = "SS24DEL"+str(delegate_id)
reg_status = 2
del_addon = {'delegate_id': delegate_id,'unique_id' : unique_id,'reg_status' : reg_status}
result_3 = conn.execute(self.delegates_addons.insert(), del_addon)
conn.commit()
get_receipt_no = text("select ifnull(max(receipt_no),0) as max_receipt_no from user_payment where conf_id = "+str(conf_id)+" ;")
results_4 = conn.execute(get_receipt_no)
result_4 = results_4.fetchone()
max_receipt_no = result_4.max_receipt_no if result_4.max_receipt_no else 0
receipt_no = int(max_receipt_no)+1
prefix = data['prefix'] or None
name = data['full_name'] or None
full_name = prefix + " " + name if prefix else name
email = data['email']
mobile = data['mobile']
payment_data = {
'delegate_ids': delegate_id,
'unique_id' : unique_id,
'status' : "success",
'conf_id' : conf_id,
'society_id' : "13",
'receipt_no' : receipt_no,
'created_at' : dt_string,
'paid_at' : dt_string,
'updated_at' : dt_string,
'full_name' : full_name,
'email' : data['email'],
'mobile' : data['mobile'],
'app_type' : "DELEGATE"
}
result_5 = conn.execute(self.user_payment.insert(),payment_data)
conn.commit()
return del_no
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists