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 = create_engine(app.config['DATABASE_URI'],pool_size=5000,max_overflow=100,pool_pre_ping=True,pool_recycle=3600)
class ProfileAppModel():
def __init__(self):
try:
self.meta = MetaData()
self.societies = Table("societies", self.meta, autoload_with=engine)
self.society_applications = Table("society_applications", self.meta, autoload_with=engine)
self.mail_setting = Table("mail_setting", self.meta, autoload_with=engine)
self.m_member_type = Table("m_member_type", self.meta, autoload_with=engine)
self.mail_templates = Table("mail_templates", self.meta, autoload_with=engine)
self.society_map_member_type = Table("society_map_member_type", self.meta, autoload_with=engine)
self.society_assets = Table("society_assets", self.meta, autoload_with=engine)
self.m_status = Table("m_status", self.meta, autoload_with=engine)
self.m_steps = Table("m_steps", self.meta, autoload_with=engine)
self.m_attachment_type = Table("m_attachment_type", self.meta,autoload_with=engine)
self.map_membertype_attachment = Table("map_membertype_attachment", self.meta, autoload_with=engine)
self.m_payment_type = Table("m_payment_type", self.meta, autoload_with=engine)
self.ms_setting = Table("ms_setting", self.meta, autoload_with=engine)
self.export_filter_cols = Table("export_filter_cols", self.meta, autoload_with=engine)
self.m_work_type = Table("m_work_type", self.meta, autoload_with=engine)
self.countries = Table("countries", self.meta, autoload_with=engine)
self.m_app_type = Table("m_app_type", self.meta, autoload_with=engine)
self.trigger_daily_reports_mails = Table("trigger_daily_reports_mails", self.meta,autoload_with=engine)
except Exception as e:
print(e)
# def get_profile_applications(self):
# with engine.connect() as conn:
# stmt = text("SELECT sa.*, s.society_name,s.society_title,s.society_logo,s.society_key,s.society_intial FROM society_applications sa "
# +" left join societies s on s.society_id = sa.society_id "
# +" where sa.app_type_id=4 order by s.society_id;")
# result = conn.execute(stmt).all()
# return [dict(r._mapping) for r in result] if result else None
def get_profile_applications(self,user_email):
with engine.connect() as conn:
stmt = text("SELECT sa.*, s.society_name,s.society_title,s.society_logo,s.society_key,s.society_intial,s.e_support_mail,s.e_backup_mails,s.e_secretary_mail_id,case "
+ " when is_active = 1 and profile_member_type is not null then 'active' "
+ " when is_active = 0 and profile_member_type is not null then 'inactive' "
+ " when profile_member_type is null then 'incomplete' "
+ " end as profile_status,u_user_id,u_user_uuid"
+ " FROM society_applications sa "
+ " left join societies s on s.society_id = sa.society_id "
+" LEFT JOIN ("
+" SELECT u1.*,u2.user_id as u_user_id,u2.user_uuid as u_user_uuid"
+" FROM users u1"
+f" LEFT JOIN (SELECT * FROM users WHERE email = '{user_email}' GROUP BY society_id ) u2 ON u1.society_id = u2.society_id GROUP BY u1.society_id"
+" ) u ON sa.society_id = u.society_id"
+" where sa.app_type_id=4 order by s.society_id;")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_profile_application_by_app_id(self,app_id):
with engine.connect() as conn:
stmt = text("SELECT sa.*, s.society_name,s.society_title,s.society_logo,s.society_key,s.society_intial FROM society_applications sa "
+" left join societies s on s.society_id = sa.society_id "
+f" where sa.app_type_id=4 and sa.app_id={app_id};")
result = conn.execute(stmt).first()
return dict(result._mapping) if result else None
def get_all_society(self):
with engine.connect() as conn:
stmt = text("SELECT * from societies;")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_mail_setting_ids(self):
with engine.connect() as conn:
stmt = text("SELECT * from mail_setting;")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_profile_member_type(self):
with engine.connect() as conn:
stmt = text("SELECT * from m_member_type where member_type_id in (1,2);")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_profile_member_type_by_society_id(self,society_id):
with engine.connect() as conn:
stmt = text("SELECT * FROM m_member_type m "
+ " inner join society_map_member_type s on s.member_type_id=m.member_type_id "
+ f" where society_id={society_id}")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def update_profile_app(self,app_id,data):
with engine.connect() as conn:
stmt = self.society_applications.update().where(self.society_applications.c.app_id.in_([app_id])).values(data)
result = conn.execute(stmt)
conn.commit()
return result
def insert_profile_app(self,data):
with engine.connect() as conn:
result = conn.execute(self.society_applications.insert(), data)
conn.commit()
pk_id = result.inserted_primary_key[0] if result.inserted_primary_key[0] else None
return pk_id
def get_app_title_count(self,app_title,app_id):
with engine.connect() as conn:
stmt = text(f"select count(*) as app_title_count from society_applications where app_title = '{app_title}' and app_id != {app_id} and app_type_id = 4")
result = conn.execute(stmt).first()
if result:
results = dict(result._mapping)
return results["app_title_count"]
else:
return 0
def get_society_count(self,society_id,app_id):
with engine.connect() as conn:
stmt = text(f"select count(*) as society_id_count from society_applications where society_id = {society_id} and app_id != {app_id} and app_type_id = 4")
result = conn.execute(stmt).first()
if result:
results = dict(result._mapping)
return results["society_id_count"]
else:
return 0
def get_app_host_count(self,app_host,app_id):
with engine.connect() as conn:
stmt = text(f"select count(*) as app_host_count from society_applications where app_host = '{app_host}' and app_id != {app_id} and app_type_id = 4")
result = conn.execute(stmt).first()
if result:
results = dict(result._mapping)
return results["app_host_count"]
else:
return 0
def get_app_url_count(self,app_url,app_id):
with engine.connect() as conn:
stmt = text(f"select count(*) as app_url_count from society_applications where app_url = '{app_url}' and app_id != {app_id} and app_type_id = 4")
result = conn.execute(stmt).first()
if result:
results = dict(result._mapping)
return results["app_url_count"]
else:
return 0
def get_app_by_app_id(self,app_id):
with engine.connect() as conn:
stmt = text(f"SELECT * from society_applications where app_id={app_id};")
result = conn.execute(stmt).first()
return dict(result._mapping) if result else None
def get_unavailable_society_app(self):
with engine.connect() as conn:
stmt = text("select s.* from societies s where s.society_id not in (select society_id from society_applications sa where sa.app_type_id=4);")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_society_name_by_society_id(self,society_id):
with engine.connect() as conn:
stmt = text(f"SELECT society_name from societies where society_id={society_id};")
result = conn.execute(stmt).first()
return dict(result._mapping) if result else None
def get_profile_app_status(self):
connection = engine.raw_connection()
cursor = connection.cursor()
cursor.callproc("usp_get_profile_app_status_count",[])
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
def get_mail_templates(self,society_id,app_type_id):
with engine.connect() as conn:
stmt = text(f"select * from mail_templates where society_id={society_id} and app_type_id= {app_type_id};")
result = conn.execute(stmt).all()
return [dict(r._mapping) for r in result] if result else None
def get_mail_template_by_mail_id(self,mail_template_id):
with engine.connect() as conn:
stmt = text(f"select * from mail_templates where mail_template_id={mail_template_id};")
result = conn.execute(stmt).first()
return dict(result._mapping) if result else None
def update_mail_template(self,mail_template_id,data_1):
with engine.connect() as conn:
stmt = self.mail_templates.update().where(self.mail_templates.c.mail_template_id.in_([mail_template_id])).values(data_1)
result = conn.execute(stmt)
conn.commit()
if result:
return "success"
else:
return "fail"
def insert_profile_mail_template(self,template_name,society_id,app_type_id,subject_type,mail_type):
with engine.connect() as conn:
stmt = text(f"insert into mail_templates (template_name,society_id,app_type_id,subject_type,mail_type) values('{template_name}',{society_id},{app_type_id},'{subject_type}','{mail_type}');")
print(stmt)
conn = engine.connect()
result = conn.execute(stmt)
conn.commit()
return "success"
def get_society_data(self,society_id):
with engine.connect() as conn:
stmt = text(f"select * from societies where society_id={society_id};")
result = conn.execute(stmt).first()
return dict(result._mapping) if result else None
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists