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_size=5000,pool_pre_ping=True,pool_recycle=3600)
engine_conf = create_engine(app.config['DATABASE_URI_CONF'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
class AddonModel():
def __init__(self):
try:
self.meta = MetaData()
self.conference = Table("conference", self.meta, autoload_with=engine)
self.societies = Table("societies", self.meta, autoload_with=engine)
self.addons = Table("addons",self.meta, autoload_with=engine)
self.addon_types = Table("addon_types",self.meta, autoload_with=engine)
self.user_types = Table("user_types",self.meta, autoload_with=engine)
self.m_app_type = Table("m_app_type", self.meta, autoload_with=engine)
self.mail_setting = Table("mail_setting", self.meta, autoload_with=engine)
self.society_applications = Table("society_applications", self.meta, autoload_with=engine)
self.addon_types = Table("addon_types", self.meta, autoload_with=engine)
self.mail_templates = Table("mail_templates",self.meta,autoload_with=engine)
except Exception as e:
print(e)
def get_conf_data(self,conf_id):
with engine.connect() as conn:
stmt = text("select * from conference where is_active=1;")
result = conn.execute(stmt).all()
conn.close()
return [dict(r._mapping) for r in result] if result else None
#-------------- addons form--------------------------
def get_addons(self,conference_id):
with engine.connect() as conn:
stmt = text("select * from addons where conference_id="+str(conference_id)+" order by addon_id desc; ")
result = conn.execute(stmt).all()
conn.close()
return [dict(r._mapping) for r in result] if result else None
def get_addon_type_data(self):
with engine.connect() as conn:
stmt = text("select * from addon_types; ")
result = conn.execute(stmt).all()
conn.close()
return [dict(r._mapping) for r in result] if result else None
def get_order_by_addons(self,conference_id):
with engine.connect() as conn:
stmt = text("select ifnull(MAX(order_by),0) as order_by from addons where conference_id ="+str(conference_id)+";")
result = conn.execute(stmt).one_or_none()
conn.close()
return dict(result._mapping) if result else 0
def insert_addons(self,data,conference_id):
with engine.connect() as conn:
stmt = conn.execute(self.addons.insert(),data)
conn.commit()
conn.close()
get_stmt = text("select * from addons where conference_id="+str(conference_id)+" order by addon_id desc;")
result_2 = conn.execute(get_stmt).all()
conn.close()
return [dict(r._mapping) for r in result_2] if result_2 else None
def get_addon_type(self,conf_id):
with engine.connect() as conn:
stmt = text("select * from addon_types where FIND_IN_SET("+str(conf_id)+",show_conf_ids);")
result = conn.execute(stmt).all()
conn.close()
return [dict(r._mapping) for r in result] if result else None
def addon_edit(self,addon_id):
with engine.connect() as conn:
stmt = text("SELECT * FROM addons where addon_id = "+ str(addon_id) + " ;")
result = conn.execute(stmt).one_or_none()
conn.close()
return dict(result._mapping) if result else 0
def update_addon_and_get_data(self,data,addon_id,conference_id):
with engine.connect() as conn:
stmt = self.addons.update().where(self.addons.c.addon_id.in_([addon_id])).values(data)
restult_1 = conn.execute(stmt)
conn.close()
conn.commit()
stmt_2 = text("select * from addons where conference_id="+str(conference_id)+" order by addon_id desc;")
result_2 = conn.execute(stmt_2).all()
conn.close()
return [dict(r._mapping) for r in result_2] if result_2 else ''
def delete_addon(self,addon_id,conference_id):
with engine.connect() as conn:
stmt = self.addons.delete().where(self.addons.c.addon_id.in_([addon_id]))
restult_1 = conn.execute(stmt)
conn.commit()
conn.close()
get_stmt = text("select * from addons where conference_id ="+str(conference_id)+" order by addon_id desc;")
result_2 = conn.execute(get_stmt).all()
conn.close()
return [dict(r._mapping) for r in result_2] if result_2 else None
#--------------------addons types form--------------------
def insert_addon_type(self,data):
with engine.connect() as conn:
stmt = conn.execute(self.addon_types.insert(),data)
conn.commit()
conn.close()
get_stmt = text("select * from addon_types order by addon_type_id desc;")
result_2 = conn.execute(get_stmt).all()
conn.close()
return [dict(r._mapping) for r in result_2] if result_2 else None
def get_order_by_addon_type(self):
with engine.connect() as conn:
stmt = text("select ifnull(MAX(order_by),0) as order_by from addon_types;")
result = conn.execute(stmt).one_or_none()
conn.close()
return dict(result._mapping) if result else 0
def addon_type_edit(self,addon_type_id):
with engine.connect() as conn:
stmt = text("SELECT * FROM addon_types where addon_type_id = "+ str(addon_type_id) + " ;")
result = conn.execute(stmt).one_or_none()
conn.close()
return dict(result._mapping) if result else 0
def update_addon_type_and_get_data(self,data,addon_type_id,conf_id):
with engine.connect() as conn:
stmt = self.addon_types.update().where(self.addon_types.c.addon_type_id.in_([addon_type_id])).values(data)
restult_1 = conn.execute(stmt)
conn.commit()
conn.close()
stmt_2 = text("select * from addon_types where FIND_IN_SET("+str(conf_id)+",show_conf_ids);")
result_2 = conn.execute(stmt_2)
conn.close()
return [dict(r._mapping) for r in result_2] if result_2 else ''
def remove_conf_id_inaddontypes(self,addon_type_id,conf_id,curr_dt):
with engine.connect() as conn:
stmt = text("select show_conf_ids from addon_types where addon_type_id = "+str(addon_type_id)+" limit 1;")
result = conn.execute(stmt).one_or_none()
conn.close()
results = [dict(result._mapping)] if result else None
if results :
show_conf_ids = results
for index,value in enumerate(show_conf_ids):
if index == 0 :
show_conf_ids = value
break
show_conf_ids = show_conf_ids["show_conf_ids"]
ids_list = show_conf_ids.split(",")
conf_id_str = str(conf_id)
ids_list.remove(conf_id_str)
if ids_list and len(ids_list) > 1 :
new_ids_str = ','.join(ids_list)
else :
new_ids_str = str(ids_list)
new_ids_str = new_ids_str.replace("[" ,"").replace("]" , "")
new_ids_str = new_ids_str.replace("'" , "")
update_stmt = text("update addon_types set show_conf_ids = '"+new_ids_str+"' , updated_at ='"+str(curr_dt)+"' where addon_type_id = " + str(addon_type_id) +" ;")
conn.execute(update_stmt)
conn.commit()
conn.close()
get_stmt = text("select * from addon_types where FIND_IN_SET("+str(conf_id)+",show_conf_ids);")
result_2 = conn.execute(get_stmt).all()
conn.close()
return [dict(r._mapping) for r in result_2] if result_2 else None
#--------------------- user types -----------------------------
def get_user_types(self,conf_id):
with engine.connect() as conn:
stmt = text("select * from user_types order by user_type_id;")
result = conn.execute(stmt).all()
conn.close()
return [dict(r._mapping) for r in result] if result else None
def insert_user_type(self,data):
with engine.connect() as conn:
stmt = conn.execute(self.user_types.insert(),data)
conn.commit()
conn.close()
get_stmt = text("select * from user_types order by user_type_id desc;")
result_2 = conn.execute(get_stmt).all()
conn.close()
return [dict(r._mapping) for r in result_2] if result_2 else None
def user_type_edit(self,user_type_id):
with engine.connect() as conn:
stmt = text("SELECT * FROM user_types where user_type_id = "+ str(user_type_id) + ";")
result = conn.execute(stmt).one_or_none()
conn.close()
return dict(result._mapping) if result else 0
def update_user_type_and_get_data(self,data,user_type_id):
with engine.connect() as conn:
stmt = self.user_types.update().where(self.user_types.c.user_type_id.in_([user_type_id])).values(data)
restult_1 = conn.execute(stmt)
conn.commit()
conn.close()
stmt_2 = text("select * from user_types order by user_type_id;")
result_2 = conn.execute(stmt_2).all()
conn.close()
return [dict(r._mapping) for r in result_2] if result_2 else ''
def delete_user_type(self,user_type_id):
with engine.connect() as conn:
stmt = self.user_types.delete().where(self.user_types.c.user_type_id.in_([user_type_id]))
result_delete = conn.execute(stmt)
conn.commit()
conn.close()
get_stmt = text("select * from user_types order by user_type_id;")
result_2 = conn.execute(get_stmt).all()
conn.close()
return [dict(r._mapping) for r in result_2] if result_2 else None
# Purpose : Adding New Mail Template
# Created At : 2023-10-14 10:46 By Ramya
def get_mail_template_data(self,conf_id):
with engine.connect() as conn:
try:
stmt = text("select * FROM mail_templates where app_type_id = 2 and find_in_set("+str(conf_id)+",conf_ids);")
result_2 = conn.execute(stmt).all()
conn.close()
return [dict(r._mapping) for r in result_2] if result_2 else None
except Exception as e:
return str(e)
def insert_and_get_data(self,conf_id,insert_data):
with engine.connect() as conn:
try:
insert_stmt = conn.execute(self.mail_templates.insert(),insert_data)
conn.commit()
conn.close()
get_stmt = text("select * FROM mail_templates where app_type_id = 2 and find_in_set("+str(conf_id)+",conf_ids);")
result_2 = conn.execute(get_stmt).all()
conn.close()
return [dict(r._mapping) for r in result_2] if result_2 else None
except Exception as e:
return str(e)
def get_mail_template_by_id(self,mail_template_id):
with engine.connect() as conn:
try:
get_stmt = text("select * FROM mail_templates where mail_template_id ="+str(mail_template_id)+";")
result = conn.execute(get_stmt).one_or_none()
conn.close()
return dict(result._mapping) if result else None
except Exception as e:
return str(e)
def update_and_get_data(self,conf_id,update_data,mail_template_id):
with engine.connect() as conn:
try:
stmt = self.mail_templates.update().where(self.mail_templates.c.mail_template_id.in_([mail_template_id])).values(update_data)
restult_1 = conn.execute(stmt)
conn.commit()
conn.close()
get_stmt = text("select * FROM mail_templates where app_type_id = 2 and find_in_set("+str(conf_id)+",conf_ids);")
result_2 = conn.execute(get_stmt).all()
return [dict(r._mapping) for r in result_2] if result_2 else None
except Exception as e:
return str(e)
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists