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'])
engine = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
engine_conf_db = create_engine(app.config['DATABASE_URI_CONF'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
class OfflineRegistrationModel():
def __init__(self):
try:
self.meta = MetaData()
self.delegates = Table("delegates", self.meta, autoload_with=engine)
self.user_payment = Table("user_payment", self.meta, autoload_with=engine)
self.mandrill_mail_logs = Table("mandrill_mail_logs", self.meta, autoload_with=engine_conf_db)
except Exception as e:
print("table not found",e)
def OR_get_confUserModel(self,conf_id,conf_key):
with engine.connect() as conn:
stmt = text("select sa.*,ms.*,c.* from conference c inner join societies s on s.society_id = c.society_id inner join society_applications sa on sa.conf_id = c.conf_id and sa.app_type_id = 2 left join mail_setting ms on ms.mail_setting_id = sa.mail_setting_id where c.conf_id ='"+str(conf_id)+"' and c.conf_key= '"+conf_key+"' and sa.app_type_id = 2 ;")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
def OR_get_badge_model(self,conf_id):
with engine.connect() as conn:
stmt = text("select * from badge_role where conf_id = '"+str(conf_id)+"' and is_visible > 0 ;")
result = conn.execute(stmt).all()
data = [dict(r._mapping) for r in result] if result else None
return data
def OR_get_payment_types(self,conf_id):
with engine.connect() as conn:
stmt = text ("SELECT * from m_payment_type where is_delegate = 1 and conf_id= "+str(conf_id)+" and is_bo_visible = 1 and is_visible =1;");
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def OR_get_addon_reg_type(self,conf_id):
with engine.connect() as conn:
stmt = text("SELECT * FROM addon_types where is_visible =1 and find_in_set("+str(conf_id)+",show_conf_ids);")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def OR_get_addonsBOModel(self,delegate_id,curr_dt,conf_id,user_type_ids = None,is_custom_addons = None):
with engine.connect() as conn:
user_type_where_con = "";
if user_type_ids:
user_type_where_con += " and (a.user_type_id in ("+user_type_ids+") or a.user_type_id is null )"
if is_custom_addons is None:
user_type_where_con += " and a.is_custom_addon is null or a.is_custom_addon = 0"
stmt = text("select a.*,ut.*,da.delegate_id,da.amount as del_amount,da.delegate_addon_id,da.reg_status from addons a "
+" left join user_types ut on ut.user_type_id = a.user_type_id"
+" left join delegates_addons da on da.addon_id = a.addon_id and da.delegate_id = "+ str(delegate_id)+" "
+" left join addon_types ats on ats.addon_type_id = a.addon_type_id "
+" where ats.is_visible=1 AND '"+curr_dt+"' between a.start_by and a.end_by "
+ user_type_where_con
+" and a.conference_id ="+str(conf_id)+" "
+" order by a.order_by;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def OR_get_states(self):
with engine.connect() as conn:
stmt = text("SELECT * FROM states order by state_name asc;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def OR_get_country(self):
with engine.connect() as conn:
stmt = text("SELECT * FROM countries order by country_name asc;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def OR_get_search_spot_user(self,register_no,conf_id):
with engine.connect() as conn:
stmt = text("select * from self_spot_register where register_id = '"+str(register_id)+"' and conference_id = '"+str(conf_id)+"';")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
def OR_get_states_of_india(self,country_id):
with engine.connect() as conn:
conn = engine.connect()
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
return results
def OR_insert_delegate(self,data):
with engine.connect() as conn:
result = conn.execute(self.delegates.insert(), data)
conn.commit()
return result.lastrowid
def OR_save_delegates_addons(self,delegate_id,inser_dal_addon,delete_del_addon,now):
with engine.connect() as conn:
sql_insert = ""
sql_delete = ""
for d in inser_dal_addon:
sql_insert = sql_insert + "insert into delegates_addons (delegate_id,addon_id,amount,original_amount,reg_status,created_at) values ({},{},{},{},{},'{}');".format(delegate_id,d['addon_id'],d['amount'],d['original_amount'],d['reg_status'],now)
for da_id in delete_del_addon:
sql_delete = sql_delete + "delete from delegates_addons where delegate_addon_id = {};".format(da_id)
if sql_insert:
insert_stmt = text(sql_insert)
result = conn.execute(insert_stmt)
if sql_delete:
delete_stmt = text(sql_delete)
result = conn.execute(delete_stmt)
conn.commit()
return True
# Below code for payment data update -- by ganesan
def OR_usp_del_generate_free_payement(self,unique_id,delegate_ids,user_id,payment_for,payment_method,remarks,full_name,email,mobile,is_generate,created_at,txn_id,society_id,app_type,conf_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_del_generate_free_payement_v3",[unique_id,delegate_ids,user_id,payment_for,payment_method,remarks,full_name,email,mobile,is_generate,created_at,txn_id,society_id,app_type,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()
return results
else :
cursor.close()
connection.commit()
return None
def OR_usp_del_generate_cash_payement(self,unique_id,delegate_ids,user_id,payment_for,payment_method,remarks,full_name,email,mobile,is_generate,created_at,txn_id,society_id,app_type,conf_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_del_generate_cash_payement_v3",[unique_id,delegate_ids,user_id,payment_for,payment_method,remarks,full_name,email,mobile,is_generate,created_at,txn_id,society_id,app_type,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()
return results
else :
cursor.close()
connection.commit()
return None
def OR_freegetDataforPayments(self,unique_id,conf_id): # Function name modified by Ganesan on Dec 12,2022
with engine.connect() as conn:
# stmt = text("select d.user_id,concat(d.prefix ,' ' ,d.full_name) as full_name ,d.email,d.mobile,p.amount,p.am_id,p.is_test,p.payment_for,p.unique_id, c.conf_id,c.conf_key from delegates d inner join user_payment p on p.user_id = d.user_id inner join conference c on d.conference_id = c.conf_id where p.user_id = "+str(user_id)+" or p.unique_id= '"+unique_id+"' ;")
# stmt = text("select full_name ,email,mobile,amount,am_id,is_test,payment_for,unique_id,delegate_ids from user_payment where unique_id = '"+unique_id+"' ;")
# Code updated by getDataforPayments on Dec 12, 2022
stmt = text("select up.full_name ,up.email,up.mobile,up.amount,up.am_id,up.is_test,up.payment_for,up.unique_id,up.delegate_ids,d.role,b.range_1 from user_payment up "
+" inner join delegates_addons da on da.unique_id = up.unique_id "
+ " inner join delegates d on d.delegate_id = da.delegate_id "
+ " left join badge_role b on b.b_role = d.role collate utf8mb4_general_ci and b.conf_id = "+str(conf_id)+" "
+ " where up.unique_id = '"+unique_id+"' ;")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
def OR_updatePayment(self,unique_id,data,dt_string):
with engine.connect() as conn:
if unique_id and "null" not in unique_id :
stmt = self.user_payment.update().where(self.user_payment.c.unique_id.in_([unique_id])).values(data)
stmt2 = text("update delegates d inner join delegates_addons da on da.delegate_id = d.delegate_id inner join user_payment up on up.unique_id = da.unique_id set d.registered_on ='"+str(dt_string)+"' where da.unique_id ='"+unique_id+"';")
result = conn.execute(stmt)
conn.commit()
result = conn.execute(stmt2)
conn.commit()
return "updated"
else :
return "Unique id missing"
def OR_BOdelegate_no_generate(self,unique_id,conf_id,role): # Ganesan anna code
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_del_completed_payment_res_and_gen_del_no_v4",[unique_id,conf_id,role])
if cursor.description :
columns = [column[0] for column in cursor.description]
results_1 = []
for row in cursor.fetchall():
results_1.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
return results_1
else:
cursor.close()
connection.commit()
return None
def OR_update_delegates_in_dele_badge(self,delegate_no,conf_id,dele_badge_table):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_del_update_badge_from_delegates_table",[delegate_no,conf_id,dele_badge_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
def OR_BOreceipt_no_generate_and_get(self,unique_id,conf_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_del_receipt_no_generate_and_get_payment_details_v1",[unique_id,conf_id])
if cursor.description :
columns = [column[0] for column in cursor.description]
results_1 = []
for row in cursor.fetchall():
results_1.append(dict(zip(columns, row)))
cursor.close()
connection.commit()
return results_1
else:
cursor.close()
connection.commit()
return None
def OR_usp_del_get_delegates_by_delegate_id(self,delegate_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_del_get_delegates_by_delegate_id",[delegate_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()
return results
else :
cursor.close()
connection.commit()
return None
def OR_sessionMapSpotReg(self,conf_id,del_id_int,session_table,del_ses_table,fc_del_sess_tab) :
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_delegate_session_map",[conf_id,del_id_int,session_table,del_ses_table,fc_del_sess_tab])
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 OR_getOTPforConfirmationMail(self,delegate_no,conf_id,del_table_name):
with engine.connect() as conn:
stmt = text("select otp from "+del_table_name+" where delegate_no = "+str(delegate_no)+" and conf_id = "+str(conf_id)+";")
result = conn.execute(stmt)
result = result.one_or_none()
return dict(result._mapping) if result else None
# Purpose : Searching Email,Mobile,Transaction Id already registered or not
def OR_free_search_alerady_registered_delegate_details(self,search_data,conf_id):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_del_search_alerady_registered_delegate_details",[search_data,conf_id])
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
def OR_get_is_admin(self,conf_id):
with engine.connect() as conn:
stmt = text("select c.conf_id,u.full_name,u.is_admin from users u inner join conference c on u.society_id = c.society_id where u.is_admin = 1 and c.conf_id = '"+str(conf_id)+"' and u.email like '%numerotec.com%';")
result = conn.execute(stmt).all()
results = [dict(r._mapping) for r in result] if result else None
return results
# -------------------------------------------------------
# def get_mail_template(self,template_name,conf_id):
# with engine.connect() as conn:
# stmt = text("select * from mail_templates where FIND_IN_SET ('"+str(conf_id)+"',conf_ids) and is_active=1 and template_name = "+(template_name)+" and app_type_id = 2;")
# result = conn.execute(stmt)
# result = result.one_or_none()
# return dict(result._mapping) if result else None
def insert_mandrill_logs(self,data):
with engine_conf_db.connect() as conn:
result = conn.execute(self.mandrill_mail_logs.insert(), data)
conn.commit()
return result.lastrowid
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists